1 | import ReanimatedModule from './ReanimatedModule';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | let UI_THREAD_PROPS_WHITELIST = {
|
7 | opacity: true,
|
8 | transform: true,
|
9 |
|
10 | backgroundColor: true,
|
11 | borderRightColor: true,
|
12 | borderBottomColor: true,
|
13 | borderColor: true,
|
14 | borderEndColor: true,
|
15 | borderLeftColor: true,
|
16 | borderStartColor: true,
|
17 | borderTopColor: true,
|
18 |
|
19 | shadowOpacity: true,
|
20 | shadowRadius: true,
|
21 |
|
22 | scaleX: true,
|
23 | scaleY: true,
|
24 | translateX: true,
|
25 | translateY: true,
|
26 | };
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | let NATIVE_THREAD_PROPS_WHITELIST = {
|
32 | borderBottomWidth: true,
|
33 | borderEndWidth: true,
|
34 | borderLeftWidth: true,
|
35 | borderRightWidth: true,
|
36 | borderStartWidth: true,
|
37 | borderTopWidth: true,
|
38 | borderWidth: true,
|
39 | bottom: true,
|
40 | flex: true,
|
41 | flexGrow: true,
|
42 | flexShrink: true,
|
43 | height: true,
|
44 | left: true,
|
45 | margin: true,
|
46 | marginBottom: true,
|
47 | marginEnd: true,
|
48 | marginHorizontal: true,
|
49 | marginLeft: true,
|
50 | marginRight: true,
|
51 | marginStart: true,
|
52 | marginTop: true,
|
53 | marginVertical: true,
|
54 | maxHeight: true,
|
55 | maxWidth: true,
|
56 | minHeight: true,
|
57 | minWidth: true,
|
58 | padding: true,
|
59 | paddingBottom: true,
|
60 | paddingEnd: true,
|
61 | paddingHorizontal: true,
|
62 | paddingLeft: true,
|
63 | paddingRight: true,
|
64 | paddingStart: true,
|
65 | paddingTop: true,
|
66 | paddingVertical: true,
|
67 | right: true,
|
68 | start: true,
|
69 | top: true,
|
70 | width: true,
|
71 | zIndex: true,
|
72 | borderBottomEndRadius: true,
|
73 | borderBottomLeftRadius: true,
|
74 | borderBottomRightRadius: true,
|
75 | borderBottomStartRadius: true,
|
76 | borderRadius: true,
|
77 | borderTopEndRadius: true,
|
78 | borderTopLeftRadius: true,
|
79 | borderTopRightRadius: true,
|
80 | borderTopStartRadius: true,
|
81 | opacity: true,
|
82 | elevation: true,
|
83 | fontSize: true,
|
84 | lineHeight: true,
|
85 | textShadowRadius: true,
|
86 | letterSpacing: true,
|
87 |
|
88 | display: true,
|
89 | backfaceVisibility: true,
|
90 | overflow: true,
|
91 | resizeMode: true,
|
92 | fontStyle: true,
|
93 | fontWeight: true,
|
94 | textAlign: true,
|
95 | textDecorationLine: true,
|
96 | fontFamily: true,
|
97 | textAlignVertical: true,
|
98 | fontVariant: true,
|
99 | textDecorationStyle: true,
|
100 | textTransform: true,
|
101 | writingDirection: true,
|
102 |
|
103 | color: true,
|
104 | tintColor: true,
|
105 | shadowColor: true,
|
106 | };
|
107 |
|
108 | function configureProps() {
|
109 | ReanimatedModule.configureProps(
|
110 | Object.keys(NATIVE_THREAD_PROPS_WHITELIST),
|
111 | Object.keys(UI_THREAD_PROPS_WHITELIST)
|
112 | );
|
113 | }
|
114 |
|
115 | export function addWhitelistedNativeProps(props) {
|
116 | const oldSize = Object.keys(NATIVE_THREAD_PROPS_WHITELIST).length;
|
117 | NATIVE_THREAD_PROPS_WHITELIST = {
|
118 | ...NATIVE_THREAD_PROPS_WHITELIST,
|
119 | ...props,
|
120 | };
|
121 | if (oldSize !== Object.keys(NATIVE_THREAD_PROPS_WHITELIST).length) {
|
122 | configureProps();
|
123 | }
|
124 | }
|
125 |
|
126 | export function addWhitelistedUIProps(props) {
|
127 | const oldSize = Object.keys(UI_THREAD_PROPS_WHITELIST).length;
|
128 | UI_THREAD_PROPS_WHITELIST = { ...UI_THREAD_PROPS_WHITELIST, ...props };
|
129 | if (oldSize !== Object.keys(UI_THREAD_PROPS_WHITELIST).length) {
|
130 | configureProps();
|
131 | }
|
132 | }
|
133 |
|
134 | const PROCESSED_VIEW_NAMES = new Set();
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | export function adaptViewConfig(viewConfig) {
|
140 | const viewName = viewConfig.uiViewClassName;
|
141 | const props = viewConfig.validAttributes;
|
142 |
|
143 |
|
144 | if (!PROCESSED_VIEW_NAMES.has(viewName)) {
|
145 | const propsToAdd = {};
|
146 | Object.keys(props).forEach((key) => {
|
147 |
|
148 |
|
149 | if (
|
150 | !(key in NATIVE_THREAD_PROPS_WHITELIST) &&
|
151 | !(key in UI_THREAD_PROPS_WHITELIST)
|
152 | ) {
|
153 | propsToAdd[key] = true;
|
154 | }
|
155 | });
|
156 | addWhitelistedUIProps(propsToAdd);
|
157 |
|
158 | PROCESSED_VIEW_NAMES.add(viewName);
|
159 | }
|
160 | }
|
161 |
|
162 | configureProps();
|