Skip to content

Commit 7d6f95a

Browse files
p-sunSaadnajmi
authored andcommitted
Refactor the JS base StaticViewConfig to be easier to understand
Summary: Changelog: [Internal][SVC][JS] Refactor the JS base SVC StaticViewConfig to be easier to understand This diff is a refactor that doesn't change any logic. NativeViewConfigs are generated from RCTViewManager in iOS and ViewManager in Android. StaticViewConfigs are partially generated from JS, and partially handwritten in JS. We've noticed in at least 2 instances that engineers who add new props to NativeViewConfigs sometimes don't put props in the correct place for StaticViewConfigs, and thus they accidentally break the landblocking jest e2e test that validates the StaticViewConfigs matches the NativeViewConfigs. The human error is mostly because PlatformBaseViewConfig.js was too nested to be easily understood. This diff refactors PlatformBaseViewConfig.js and adds clarifying comments. Reviewed By: RSNara Differential Revision: D35623775 fbshipit-source-id: 498a3daa812fa314821a2e7cb7d6f809900dbe3a
1 parent 3074cdd commit 7d6f95a

File tree

5 files changed

+726
-639
lines changed

5 files changed

+726
-639
lines changed
Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow strict-local
9+
*/
10+
11+
import {DynamicallyInjectedByGestureHandler} from './ViewConfigIgnore';
12+
import ReactNativeStyleAttributes from '../Components/View/ReactNativeStyleAttributes';
13+
import type {PartialViewConfigWithoutName} from './PlatformBaseViewConfig';
14+
15+
const bubblingEventTypes = {
16+
// Bubbling events from UIManagerModuleConstants.java
17+
topChange: {
18+
phasedRegistrationNames: {
19+
captured: 'onChangeCapture',
20+
bubbled: 'onChange',
21+
},
22+
},
23+
topSelect: {
24+
phasedRegistrationNames: {
25+
captured: 'onSelectCapture',
26+
bubbled: 'onSelect',
27+
},
28+
},
29+
topTouchEnd: {
30+
phasedRegistrationNames: {
31+
captured: 'onTouchEndCapture',
32+
bubbled: 'onTouchEnd',
33+
},
34+
},
35+
topTouchCancel: {
36+
phasedRegistrationNames: {
37+
captured: 'onTouchCancelCapture',
38+
bubbled: 'onTouchCancel',
39+
},
40+
},
41+
topTouchStart: {
42+
phasedRegistrationNames: {
43+
captured: 'onTouchStartCapture',
44+
bubbled: 'onTouchStart',
45+
},
46+
},
47+
topTouchMove: {
48+
phasedRegistrationNames: {
49+
captured: 'onTouchMoveCapture',
50+
bubbled: 'onTouchMove',
51+
},
52+
},
53+
topPointerCancel: {
54+
phasedRegistrationNames: {
55+
captured: 'onPointerCancelCapture',
56+
bubbled: 'onPointerCancel',
57+
},
58+
},
59+
topPointerDown: {
60+
phasedRegistrationNames: {
61+
captured: 'onPointerDownCapture',
62+
bubbled: 'onPointerDown',
63+
},
64+
},
65+
topPointerEnter2: {
66+
phasedRegistrationNames: {
67+
captured: 'onPointerEnter2Capture',
68+
bubbled: 'onPointerEnter2',
69+
skipBubbling: true,
70+
},
71+
},
72+
topPointerLeave2: {
73+
phasedRegistrationNames: {
74+
captured: 'onPointerLeave2Capture',
75+
bubbled: 'onPointerLeave2',
76+
skipBubbling: true,
77+
},
78+
},
79+
topPointerMove2: {
80+
phasedRegistrationNames: {
81+
captured: 'onPointerMove2Capture',
82+
bubbled: 'onPointerMove2',
83+
},
84+
},
85+
topPointerUp: {
86+
phasedRegistrationNames: {
87+
captured: 'onPointerUpCapture',
88+
bubbled: 'onPointerUp',
89+
},
90+
},
91+
};
92+
93+
const directEventTypes = {
94+
topAccessibilityAction: {
95+
registrationName: 'onAccessibilityAction',
96+
},
97+
topPointerEnter: {
98+
registrationName: 'onPointerEnter',
99+
},
100+
topPointerLeave: {
101+
registrationName: 'onPointerLeave',
102+
},
103+
topPointerMove: {
104+
registrationName: 'onPointerMove',
105+
},
106+
onGestureHandlerEvent: DynamicallyInjectedByGestureHandler({
107+
registrationName: 'onGestureHandlerEvent',
108+
}),
109+
onGestureHandlerStateChange: DynamicallyInjectedByGestureHandler({
110+
registrationName: 'onGestureHandlerStateChange',
111+
}),
112+
113+
// Direct events from UIManagerModuleConstants.java
114+
topContentSizeChange: {
115+
registrationName: 'onContentSizeChange',
116+
},
117+
topScrollBeginDrag: {
118+
registrationName: 'onScrollBeginDrag',
119+
},
120+
topMessage: {
121+
registrationName: 'onMessage',
122+
},
123+
topSelectionChange: {
124+
registrationName: 'onSelectionChange',
125+
},
126+
topLoadingFinish: {
127+
registrationName: 'onLoadingFinish',
128+
},
129+
topMomentumScrollEnd: {
130+
registrationName: 'onMomentumScrollEnd',
131+
},
132+
topClick: {
133+
registrationName: 'onClick',
134+
},
135+
topLoadingStart: {
136+
registrationName: 'onLoadingStart',
137+
},
138+
topLoadingError: {
139+
registrationName: 'onLoadingError',
140+
},
141+
topMomentumScrollBegin: {
142+
registrationName: 'onMomentumScrollBegin',
143+
},
144+
topScrollEndDrag: {
145+
registrationName: 'onScrollEndDrag',
146+
},
147+
topScroll: {
148+
registrationName: 'onScroll',
149+
},
150+
topLayout: {
151+
registrationName: 'onLayout',
152+
},
153+
};
154+
155+
const validAttributesForNonEventProps = {
156+
// @ReactProps from BaseViewManager
157+
backgroundColor: {process: require('../StyleSheet/processColor')},
158+
transform: true,
159+
opacity: true,
160+
elevation: true,
161+
shadowColor: {process: require('../StyleSheet/processColor')},
162+
zIndex: true,
163+
renderToHardwareTextureAndroid: true,
164+
testID: true,
165+
nativeID: true,
166+
accessibilityLabelledBy: true,
167+
accessibilityLabel: true,
168+
accessibilityHint: true,
169+
accessibilityRole: true,
170+
accessibilityState: true,
171+
accessibilityActions: true,
172+
accessibilityValue: true,
173+
importantForAccessibility: true,
174+
rotation: true,
175+
scaleX: true,
176+
scaleY: true,
177+
translateX: true,
178+
translateY: true,
179+
accessibilityLiveRegion: true,
180+
181+
// @ReactProps from LayoutShadowNode
182+
width: true,
183+
minWidth: true,
184+
collapsable: true,
185+
maxWidth: true,
186+
height: true,
187+
minHeight: true,
188+
maxHeight: true,
189+
flex: true,
190+
flexGrow: true,
191+
flexShrink: true,
192+
flexBasis: true,
193+
aspectRatio: true,
194+
flexDirection: true,
195+
flexWrap: true,
196+
alignSelf: true,
197+
alignItems: true,
198+
alignContent: true,
199+
justifyContent: true,
200+
overflow: true,
201+
display: true,
202+
203+
margin: true,
204+
marginVertical: true,
205+
marginHorizontal: true,
206+
marginStart: true,
207+
marginEnd: true,
208+
marginTop: true,
209+
marginBottom: true,
210+
marginLeft: true,
211+
marginRight: true,
212+
213+
padding: true,
214+
paddingVertical: true,
215+
paddingHorizontal: true,
216+
paddingStart: true,
217+
paddingEnd: true,
218+
paddingTop: true,
219+
paddingBottom: true,
220+
paddingLeft: true,
221+
paddingRight: true,
222+
223+
borderWidth: true,
224+
borderStartWidth: true,
225+
borderEndWidth: true,
226+
borderTopWidth: true,
227+
borderBottomWidth: true,
228+
borderLeftWidth: true,
229+
borderRightWidth: true,
230+
231+
start: true,
232+
end: true,
233+
left: true,
234+
right: true,
235+
top: true,
236+
bottom: true,
237+
238+
position: true,
239+
240+
style: ReactNativeStyleAttributes,
241+
};
242+
243+
// Props for bubbling and direct events
244+
const validAttributesForEventProps = {
245+
onLayout: true,
246+
247+
// PanResponder handlers
248+
onMoveShouldSetResponder: true,
249+
onMoveShouldSetResponderCapture: true,
250+
onStartShouldSetResponder: true,
251+
onStartShouldSetResponderCapture: true,
252+
onResponderGrant: true,
253+
onResponderReject: true,
254+
onResponderStart: true,
255+
onResponderEnd: true,
256+
onResponderRelease: true,
257+
onResponderMove: true,
258+
onResponderTerminate: true,
259+
onResponderTerminationRequest: true,
260+
onShouldBlockNativeResponder: true,
261+
262+
// Touch events
263+
onTouchStart: true,
264+
onTouchMove: true,
265+
onTouchEnd: true,
266+
onTouchCancel: true,
267+
268+
// Pointer events
269+
onPointerEnter: true,
270+
onPointerLeave: true,
271+
onPointerMove: true,
272+
};
273+
274+
/**
275+
* On Android, Props are derived from a ViewManager and its ShadowNode.
276+
*
277+
* Where did we find these base platform props from?
278+
* - Nearly all component ViewManagers descend from BaseViewManager,
279+
* - and BaseViewManagers' ShadowNodes descend from LayoutShadowNode.
280+
* - Also, all components inherit ViewConfigs from UIManagerModuleConstants.java.
281+
*
282+
* So, these ViewConfigs are generated from LayoutShadowNode and BaseViewManager.
283+
*/
284+
const PlatformBaseViewConfigAndroid: PartialViewConfigWithoutName = {
285+
directEventTypes,
286+
bubblingEventTypes,
287+
validAttributes: {
288+
...validAttributesForNonEventProps,
289+
...validAttributesForEventProps,
290+
},
291+
};
292+
293+
export default PlatformBaseViewConfigAndroid;

0 commit comments

Comments
 (0)