Put View ViewConfig in JS

Summary: Moving this config to native for android so we skip the native lookup for the config.

Reviewed By: yungsters

Differential Revision: D9415726

fbshipit-source-id: 84cac3f0dfa4f6ea8800de77676f1e2896ee463d
This commit is contained in:
Eli White 2018-08-22 12:49:14 -07:00 committed by Facebook Github Bot
parent 2b6599e9c8
commit d0eb8ff858
2 changed files with 290 additions and 4 deletions

View File

@ -10,16 +10,24 @@
'use strict';
const Platform = require('Platform');
const ReactNative = require('ReactNative');
const requireNativeComponent = require('requireNativeComponent');
const ReactNativeViewConfigRegistry = require('ReactNativeViewConfigRegistry');
import type {ViewProps} from 'ViewPropTypes';
type ViewNativeComponentType = Class<ReactNative.NativeComponent<ViewProps>>;
const ViewNativeComponent = ((requireNativeComponent(
'RCTView',
): any): ViewNativeComponentType);
let NativeViewComponent;
module.exports = ViewNativeComponent;
if (Platform.OS === 'Android') {
NativeViewComponent = ReactNativeViewConfigRegistry.register('RCTView', () =>
require('ViewNativeComponentAndroidConfig'),
);
} else {
NativeViewComponent = requireNativeComponent('RCTView');
}
module.exports = ((NativeViewComponent: any): ViewNativeComponentType);

View File

@ -0,0 +1,278 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
const processColor = require('processColor');
const colorHandler = {diff: null, process: processColor};
const ViewNativeComponentAndroidConfig = {
bubblingEventTypes: {
topChange: {
phasedRegistrationNames: {
captured: 'onChangeCapture',
bubbled: 'onChange',
},
},
topTouchCancel: {
phasedRegistrationNames: {
captured: 'onTouchCancelCapture',
bubbled: 'onTouchCancel',
},
},
topTouchMove: {
phasedRegistrationNames: {
captured: 'onTouchMoveCapture',
bubbled: 'onTouchMove',
},
},
topTouchStart: {
phasedRegistrationNames: {
captured: 'onTouchStartCapture',
bubbled: 'onTouchStart',
},
},
topTouchEnd: {
phasedRegistrationNames: {
captured: 'onTouchEndCapture',
bubbled: 'onTouchEnd',
},
},
topSelect: {
phasedRegistrationNames: {
captured: 'onSelectCapture',
bubbled: 'onSelect',
},
},
},
Commands: {setPressed: 2, hotspotUpdate: 1},
directEventTypes: {
topLoadingError: {registrationName: 'onLoadingError'},
topLayout: {registrationName: 'onLayout'},
topScrollBeginDrag: {registrationName: 'onScrollBeginDrag'},
topContentSizeChange: {registrationName: 'onContentSizeChange'},
topMomentumScrollBegin: {registrationName: 'onMomentumScrollBegin'},
topScrollEndDrag: {registrationName: 'onScrollEndDrag'},
topMomentumScrollEnd: {registrationName: 'onMomentumScrollEnd'},
topLoadingStart: {registrationName: 'onLoadingStart'},
topSelectionChange: {registrationName: 'onSelectionChange'},
topLoadingFinish: {registrationName: 'onLoadingFinish'},
topMessage: {registrationName: 'onMessage'},
topScroll: {registrationName: 'onScroll'},
},
NativeProps: {
accessibilityComponentType: 'String',
accessibilityHint: 'String',
accessibilityLabel: 'String',
accessibilityLiveRegion: 'String',
accessibilityRole: 'String',
accessibilityStates: 'Array',
accessible: 'boolean',
alignContent: 'String',
alignItems: 'String',
alignSelf: 'String',
aspectRatio: 'number',
backgroundColor: 'Color',
borderBottomColor: 'Color',
borderBottomEndRadius: 'number',
borderBottomLeftRadius: 'number',
borderBottomRightRadius: 'number',
borderBottomStartRadius: 'number',
borderBottomWidth: 'number',
borderColor: 'Color',
borderEndColor: 'Color',
borderEndWidth: 'number',
borderLeftColor: 'Color',
borderLeftWidth: 'number',
borderRadius: 'number',
borderRightColor: 'Color',
borderRightWidth: 'number',
borderStartColor: 'Color',
borderStartWidth: 'number',
borderStyle: 'String',
borderTopColor: 'Color',
borderTopEndRadius: 'number',
borderTopLeftRadius: 'number',
borderTopRightRadius: 'number',
borderTopStartRadius: 'number',
borderTopWidth: 'number',
borderWidth: 'number',
bottom: 'Dynamic',
collapsable: 'boolean',
display: 'String',
elevation: 'number',
end: 'Dynamic',
flex: 'number',
flexBasis: 'Dynamic',
flexDirection: 'String',
flexGrow: 'number',
flexShrink: 'number',
flexWrap: 'String',
hasTVPreferredFocus: 'boolean',
height: 'Dynamic',
hitSlop: 'Map',
importantForAccessibility: 'String',
justifyContent: 'String',
left: 'Dynamic',
margin: 'Dynamic',
marginBottom: 'Dynamic',
marginEnd: 'Dynamic',
marginHorizontal: 'Dynamic',
marginLeft: 'Dynamic',
marginRight: 'Dynamic',
marginStart: 'Dynamic',
marginTop: 'Dynamic',
marginVertical: 'Dynamic',
maxHeight: 'Dynamic',
maxWidth: 'Dynamic',
minHeight: 'Dynamic',
minWidth: 'Dynamic',
nativeBackgroundAndroid: 'Map',
nativeForegroundAndroid: 'Map',
nativeID: 'String',
needsOffscreenAlphaCompositing: 'boolean',
onLayout: 'boolean',
opacity: 'number',
overflow: 'String',
padding: 'Dynamic',
paddingBottom: 'Dynamic',
paddingEnd: 'Dynamic',
paddingHorizontal: 'Dynamic',
paddingLeft: 'Dynamic',
paddingRight: 'Dynamic',
paddingStart: 'Dynamic',
paddingTop: 'Dynamic',
paddingVertical: 'Dynamic',
pointerEvents: 'String',
position: 'String',
removeClippedSubviews: 'boolean',
renderToHardwareTextureAndroid: 'boolean',
right: 'Dynamic',
rotation: 'number',
scaleX: 'number',
scaleY: 'number',
start: 'Dynamic',
testID: 'String',
top: 'Dynamic',
transform: 'Array',
translateX: 'number',
translateY: 'number',
width: 'Dynamic',
zIndex: 'number',
},
uiViewClassName: 'RCTView',
validAttributes: {
accessibilityComponentType: true,
accessibilityHint: true,
accessibilityLabel: true,
accessibilityLiveRegion: true,
accessibilityRole: true,
accessibilityStates: true,
accessible: true,
alignContent: true,
alignItems: true,
alignSelf: true,
aspectRatio: true,
backgroundColor: colorHandler,
borderBottomColor: colorHandler,
borderBottomEndRadius: true,
borderBottomLeftRadius: true,
borderBottomRightRadius: true,
borderBottomStartRadius: true,
borderBottomWidth: true,
borderColor: colorHandler,
borderEndColor: colorHandler,
borderEndWidth: true,
borderLeftColor: colorHandler,
borderLeftWidth: true,
borderRadius: true,
borderRightColor: colorHandler,
borderRightWidth: true,
borderStartColor: colorHandler,
borderStartWidth: true,
borderStyle: true,
borderTopColor: colorHandler,
borderTopEndRadius: true,
borderTopLeftRadius: true,
borderTopRightRadius: true,
borderTopStartRadius: true,
borderTopWidth: true,
borderWidth: true,
bottom: true,
collapsable: true,
display: true,
elevation: true,
end: true,
flex: true,
flexBasis: true,
flexDirection: true,
flexGrow: true,
flexShrink: true,
flexWrap: true,
hasTVPreferredFocus: true,
height: true,
hitSlop: true,
importantForAccessibility: true,
justifyContent: true,
left: true,
margin: true,
marginBottom: true,
marginEnd: true,
marginHorizontal: true,
marginLeft: true,
marginRight: true,
marginStart: true,
marginTop: true,
marginVertical: true,
maxHeight: true,
maxWidth: true,
minHeight: true,
minWidth: true,
nativeBackgroundAndroid: true,
nativeForegroundAndroid: true,
nativeID: true,
needsOffscreenAlphaCompositing: true,
onLayout: true,
opacity: true,
overflow: true,
padding: true,
paddingBottom: true,
paddingEnd: true,
paddingHorizontal: true,
paddingLeft: true,
paddingRight: true,
paddingStart: true,
paddingTop: true,
paddingVertical: true,
pointerEvents: true,
position: true,
removeClippedSubviews: true,
renderToHardwareTextureAndroid: true,
right: true,
rotation: true,
scaleX: true,
scaleY: true,
start: true,
testID: true,
top: true,
transform: true,
translateX: true,
translateY: true,
width: true,
zIndex: true,
style: ReactNativeStyleAttributes,
},
};
module.exports = ViewNativeComponentAndroidConfig;