mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
033ad83b29
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. # Context 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
334 lines
7.9 KiB
JavaScript
334 lines
7.9 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
import {
|
|
DynamicallyInjectedByGestureHandler,
|
|
ConditionallyIgnoredEventHandlers,
|
|
} from './ViewConfigIgnore';
|
|
import ReactNativeStyleAttributes from '../Components/View/ReactNativeStyleAttributes';
|
|
import type {PartialViewConfigWithoutName} from './PlatformBaseViewConfig';
|
|
|
|
const bubblingEventTypes = {
|
|
// Generic Events
|
|
topPress: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onPress',
|
|
captured: 'onPressCapture',
|
|
},
|
|
},
|
|
topChange: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onChange',
|
|
captured: 'onChangeCapture',
|
|
},
|
|
},
|
|
topFocus: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onFocus',
|
|
captured: 'onFocusCapture',
|
|
},
|
|
},
|
|
topBlur: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onBlur',
|
|
captured: 'onBlurCapture',
|
|
},
|
|
},
|
|
topSubmitEditing: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onSubmitEditing',
|
|
captured: 'onSubmitEditingCapture',
|
|
},
|
|
},
|
|
topEndEditing: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onEndEditing',
|
|
captured: 'onEndEditingCapture',
|
|
},
|
|
},
|
|
topKeyPress: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onKeyPress',
|
|
captured: 'onKeyPressCapture',
|
|
},
|
|
},
|
|
|
|
// Touch Events
|
|
topTouchStart: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onTouchStart',
|
|
captured: 'onTouchStartCapture',
|
|
},
|
|
},
|
|
topTouchMove: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onTouchMove',
|
|
captured: 'onTouchMoveCapture',
|
|
},
|
|
},
|
|
topTouchCancel: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onTouchCancel',
|
|
captured: 'onTouchCancelCapture',
|
|
},
|
|
},
|
|
topTouchEnd: {
|
|
phasedRegistrationNames: {
|
|
bubbled: 'onTouchEnd',
|
|
captured: 'onTouchEndCapture',
|
|
},
|
|
},
|
|
|
|
// Pointer Events
|
|
topPointerCancel: {
|
|
phasedRegistrationNames: {
|
|
captured: 'onPointerCancelCapture',
|
|
bubbled: 'onPointerCancel',
|
|
},
|
|
},
|
|
topPointerDown: {
|
|
phasedRegistrationNames: {
|
|
captured: 'onPointerDownCapture',
|
|
bubbled: 'onPointerDown',
|
|
},
|
|
},
|
|
topPointerMove2: {
|
|
phasedRegistrationNames: {
|
|
captured: 'onPointerMove2Capture',
|
|
bubbled: 'onPointerMove2',
|
|
},
|
|
},
|
|
topPointerUp: {
|
|
phasedRegistrationNames: {
|
|
captured: 'onPointerUpCapture',
|
|
bubbled: 'onPointerUp',
|
|
},
|
|
},
|
|
topPointerEnter2: {
|
|
phasedRegistrationNames: {
|
|
captured: 'onPointerEnter2Capture',
|
|
bubbled: 'onPointerEnter2',
|
|
skipBubbling: true,
|
|
},
|
|
},
|
|
topPointerLeave2: {
|
|
phasedRegistrationNames: {
|
|
captured: 'onPointerLeave2Capture',
|
|
bubbled: 'onPointerLeave2',
|
|
skipBubbling: true,
|
|
},
|
|
},
|
|
};
|
|
|
|
const directEventTypes = {
|
|
topAccessibilityAction: {
|
|
registrationName: 'onAccessibilityAction',
|
|
},
|
|
topAccessibilityTap: {
|
|
registrationName: 'onAccessibilityTap',
|
|
},
|
|
topMagicTap: {
|
|
registrationName: 'onMagicTap',
|
|
},
|
|
topAccessibilityEscape: {
|
|
registrationName: 'onAccessibilityEscape',
|
|
},
|
|
topLayout: {
|
|
registrationName: 'onLayout',
|
|
},
|
|
onGestureHandlerEvent: DynamicallyInjectedByGestureHandler({
|
|
registrationName: 'onGestureHandlerEvent',
|
|
}),
|
|
onGestureHandlerStateChange: DynamicallyInjectedByGestureHandler({
|
|
registrationName: 'onGestureHandlerStateChange',
|
|
}),
|
|
};
|
|
|
|
const validAttributesForNonEventProps = {
|
|
// View Props
|
|
accessible: true,
|
|
accessibilityActions: true,
|
|
accessibilityLabel: true,
|
|
accessibilityHint: true,
|
|
accessibilityLanguage: true,
|
|
accessibilityValue: true,
|
|
accessibilityViewIsModal: true,
|
|
accessibilityElementsHidden: true,
|
|
accessibilityIgnoresInvertColors: true,
|
|
testID: true,
|
|
backgroundColor: {process: require('../StyleSheet/processColor')},
|
|
backfaceVisibility: true,
|
|
opacity: true,
|
|
shadowColor: {process: require('../StyleSheet/processColor')},
|
|
shadowOffset: {diff: require('../Utilities/differ/sizesDiffer')},
|
|
shadowOpacity: true,
|
|
shadowRadius: true,
|
|
needsOffscreenAlphaCompositing: true,
|
|
overflow: true,
|
|
shouldRasterizeIOS: true,
|
|
transform: {diff: require('../Utilities/differ/matricesDiffer')},
|
|
accessibilityRole: true,
|
|
accessibilityState: true,
|
|
nativeID: true,
|
|
pointerEvents: true,
|
|
removeClippedSubviews: true,
|
|
borderRadius: true,
|
|
borderColor: {process: require('../StyleSheet/processColor')},
|
|
borderWidth: true,
|
|
borderStyle: true,
|
|
hitSlop: {diff: require('../Utilities/differ/insetsDiffer')},
|
|
collapsable: true,
|
|
|
|
borderTopWidth: true,
|
|
borderTopColor: {process: require('../StyleSheet/processColor')},
|
|
borderRightWidth: true,
|
|
borderRightColor: {process: require('../StyleSheet/processColor')},
|
|
borderBottomWidth: true,
|
|
borderBottomColor: {process: require('../StyleSheet/processColor')},
|
|
borderLeftWidth: true,
|
|
borderLeftColor: {process: require('../StyleSheet/processColor')},
|
|
borderStartWidth: true,
|
|
borderStartColor: {process: require('../StyleSheet/processColor')},
|
|
borderEndWidth: true,
|
|
borderEndColor: {process: require('../StyleSheet/processColor')},
|
|
|
|
borderTopLeftRadius: true,
|
|
borderTopRightRadius: true,
|
|
borderTopStartRadius: true,
|
|
borderTopEndRadius: true,
|
|
borderBottomLeftRadius: true,
|
|
borderBottomRightRadius: true,
|
|
borderBottomStartRadius: true,
|
|
borderBottomEndRadius: true,
|
|
display: true,
|
|
zIndex: true,
|
|
|
|
// ShadowView properties
|
|
top: true,
|
|
right: true,
|
|
start: true,
|
|
end: true,
|
|
bottom: true,
|
|
left: true,
|
|
|
|
width: true,
|
|
height: true,
|
|
|
|
minWidth: true,
|
|
maxWidth: true,
|
|
minHeight: true,
|
|
maxHeight: true,
|
|
|
|
// Also declared as ViewProps
|
|
// borderTopWidth: true,
|
|
// borderRightWidth: true,
|
|
// borderBottomWidth: true,
|
|
// borderLeftWidth: true,
|
|
// borderStartWidth: true,
|
|
// borderEndWidth: true,
|
|
// borderWidth: true,
|
|
|
|
marginTop: true,
|
|
marginRight: true,
|
|
marginBottom: true,
|
|
marginLeft: true,
|
|
marginStart: true,
|
|
marginEnd: true,
|
|
marginVertical: true,
|
|
marginHorizontal: true,
|
|
margin: true,
|
|
|
|
paddingTop: true,
|
|
paddingRight: true,
|
|
paddingBottom: true,
|
|
paddingLeft: true,
|
|
paddingStart: true,
|
|
paddingEnd: true,
|
|
paddingVertical: true,
|
|
paddingHorizontal: true,
|
|
padding: true,
|
|
|
|
flex: true,
|
|
flexGrow: true,
|
|
flexShrink: true,
|
|
flexBasis: true,
|
|
flexDirection: true,
|
|
flexWrap: true,
|
|
justifyContent: true,
|
|
alignItems: true,
|
|
alignSelf: true,
|
|
alignContent: true,
|
|
position: true,
|
|
aspectRatio: true,
|
|
|
|
// Also declared as ViewProps
|
|
// overflow: true,
|
|
// display: true,
|
|
|
|
direction: true,
|
|
|
|
style: ReactNativeStyleAttributes,
|
|
};
|
|
|
|
// Props for bubbling and direct events
|
|
const validAttributesForEventProps = ConditionallyIgnoredEventHandlers({
|
|
onLayout: true,
|
|
onMagicTap: true,
|
|
|
|
// Accessibility
|
|
onAccessibilityAction: true,
|
|
onAccessibilityEscape: true,
|
|
onAccessibilityTap: true,
|
|
|
|
// PanResponder handlers
|
|
onMoveShouldSetResponder: true,
|
|
onMoveShouldSetResponderCapture: true,
|
|
onStartShouldSetResponder: true,
|
|
onStartShouldSetResponderCapture: true,
|
|
onResponderGrant: true,
|
|
onResponderReject: true,
|
|
onResponderStart: true,
|
|
onResponderEnd: true,
|
|
onResponderRelease: true,
|
|
onResponderMove: true,
|
|
onResponderTerminate: true,
|
|
onResponderTerminationRequest: true,
|
|
onShouldBlockNativeResponder: true,
|
|
|
|
// Touch events
|
|
onTouchStart: true,
|
|
onTouchMove: true,
|
|
onTouchEnd: true,
|
|
onTouchCancel: true,
|
|
|
|
// Pointer events
|
|
onPointerUp: true,
|
|
onPointerDown: true,
|
|
onPointerCancel: true,
|
|
onPointerEnter2: true,
|
|
onPointerMove2: true,
|
|
onPointerLeave2: true,
|
|
});
|
|
|
|
/**
|
|
* On iOS, view managers define all of a component's props.
|
|
* All view managers extend RCTViewManager, and RCTViewManager declares these props.
|
|
*/
|
|
const PlatformBaseViewConfigIos: PartialViewConfigWithoutName = {
|
|
bubblingEventTypes,
|
|
directEventTypes,
|
|
validAttributes: {
|
|
...validAttributesForNonEventProps,
|
|
...validAttributesForEventProps,
|
|
},
|
|
};
|
|
|
|
export default PlatformBaseViewConfigIos;
|