1 | 'use strict';
|
2 | import { PropsAllowlists } from './propsAllowlists';
|
3 | import { jsiConfigureProps } from './reanimated2/core';
|
4 | function assertNoOverlapInLists() {
|
5 | for (const key in PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST) {
|
6 | if (key in PropsAllowlists.UI_THREAD_PROPS_WHITELIST) {
|
7 | throw new Error(
|
8 | `[Reanimated] Property \`${key}\` was whitelisted both as UI and native prop. Please remove it from one of the lists.`
|
9 | );
|
10 | }
|
11 | }
|
12 | }
|
13 |
|
14 | export function configureProps(): void {
|
15 | assertNoOverlapInLists();
|
16 | jsiConfigureProps(
|
17 | Object.keys(PropsAllowlists.UI_THREAD_PROPS_WHITELIST),
|
18 | Object.keys(PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST)
|
19 | );
|
20 | }
|
21 |
|
22 | export function addWhitelistedNativeProps(
|
23 | props: Record<string, boolean>
|
24 | ): void {
|
25 | const oldSize = Object.keys(
|
26 | PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST
|
27 | ).length;
|
28 | PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST = {
|
29 | ...PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST,
|
30 | ...props,
|
31 | };
|
32 | if (
|
33 | oldSize !==
|
34 | Object.keys(PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST).length
|
35 | ) {
|
36 | configureProps();
|
37 | }
|
38 | }
|
39 |
|
40 | export function addWhitelistedUIProps(props: Record<string, boolean>): void {
|
41 | const oldSize = Object.keys(PropsAllowlists.UI_THREAD_PROPS_WHITELIST).length;
|
42 | PropsAllowlists.UI_THREAD_PROPS_WHITELIST = {
|
43 | ...PropsAllowlists.UI_THREAD_PROPS_WHITELIST,
|
44 | ...props,
|
45 | };
|
46 | if (
|
47 | oldSize !== Object.keys(PropsAllowlists.UI_THREAD_PROPS_WHITELIST).length
|
48 | ) {
|
49 | configureProps();
|
50 | }
|
51 | }
|
52 |
|
53 | const PROCESSED_VIEW_NAMES = new Set();
|
54 |
|
55 | export interface ViewConfig {
|
56 | uiViewClassName: string;
|
57 | validAttributes: Record<string, unknown>;
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | export function adaptViewConfig(viewConfig: ViewConfig): void {
|
65 | const viewName = viewConfig.uiViewClassName;
|
66 | const props = viewConfig.validAttributes;
|
67 |
|
68 |
|
69 | if (!PROCESSED_VIEW_NAMES.has(viewName)) {
|
70 | const propsToAdd: Record<string, boolean> = {};
|
71 | Object.keys(props).forEach((key) => {
|
72 |
|
73 |
|
74 | if (
|
75 | !(key in PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST) &&
|
76 | !(key in PropsAllowlists.UI_THREAD_PROPS_WHITELIST)
|
77 | ) {
|
78 | propsToAdd[key] = true;
|
79 | }
|
80 | });
|
81 | addWhitelistedUIProps(propsToAdd);
|
82 |
|
83 | PROCESSED_VIEW_NAMES.add(viewName);
|
84 | }
|
85 | }
|
86 |
|
87 | configureProps();
|