From 6fef48096d4e33820763fc3f7fa773c18fd8db04 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Mon, 17 Jun 2019 10:46:38 -0700 Subject: [PATCH] Add JS view config for View Summary: This diff adds the generated view config for View (in DEV) Reviewed By: ejanzer Differential Revision: D15780039 fbshipit-source-id: 1ec8ed1b57fd2341552746051980129848cb8e85 --- .../View/ReactNativeViewViewConfigAndroid.js | 73 +++++++++++++++++++ Libraries/Components/View/View.js | 2 +- .../Components/View/ViewNativeComponent.js | 27 ++++++- .../verifyComponentAttributeEquivalence.js | 2 +- 4 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 Libraries/Components/View/ReactNativeViewViewConfigAndroid.js diff --git a/Libraries/Components/View/ReactNativeViewViewConfigAndroid.js b/Libraries/Components/View/ReactNativeViewViewConfigAndroid.js new file mode 100644 index 00000000000..9da87962d48 --- /dev/null +++ b/Libraries/Components/View/ReactNativeViewViewConfigAndroid.js @@ -0,0 +1,73 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +'use strict'; + +const ReactNativeViewConfig = { + uiViewClassName: 'RCTView', + bubblingEventTypes: { + topSelect: { + phasedRegistrationNames: { + bubbled: 'onSelect', + captured: 'onSelectCapture', + }, + }, + }, + directEventTypes: { + topClick: { + registrationName: 'onClick', + }, + topContentSizeChange: { + registrationName: 'onContentSizeChange', + }, + topLoadingError: { + registrationName: 'onLoadingError', + }, + topLoadingFinish: { + registrationName: 'onLoadingFinish', + }, + topLoadingStart: { + registrationName: 'onLoadingStart', + }, + topMessage: { + registrationName: 'onMessage', + }, + topMomentumScrollBegin: { + registrationName: 'onMomentumScrollBegin', + }, + topMomentumScrollEnd: { + registrationName: 'onMomentumScrollEnd', + }, + topScroll: { + registrationName: 'onScroll', + }, + topScrollBeginDrag: { + registrationName: 'onScrollBeginDrag', + }, + topScrollEndDrag: { + registrationName: 'onScrollEndDrag', + }, + topSelectionChange: { + registrationName: 'onSelectionChange', + }, + }, + validAttributes: { + hasTVPreferredFocus: true, + nativeBackgroundAndroid: true, + nativeForegroundAndroid: true, + nextFocusDown: true, + nextFocusForward: true, + nextFocusLeft: true, + nextFocusRight: true, + nextFocusUp: true, + }, +}; + +module.exports = ReactNativeViewConfig; diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index c321d7f87a7..8960b5380c1 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -11,7 +11,7 @@ 'use strict'; const React = require('react'); -const ViewNativeComponent = require('./ViewNativeComponent'); +import ViewNativeComponent from './ViewNativeComponent'; import type {ViewProps} from './ViewPropTypes'; diff --git a/Libraries/Components/View/ViewNativeComponent.js b/Libraries/Components/View/ViewNativeComponent.js index 21e57c8a437..c5cc06bc729 100644 --- a/Libraries/Components/View/ViewNativeComponent.js +++ b/Libraries/Components/View/ViewNativeComponent.js @@ -11,13 +11,34 @@ 'use strict'; const ReactNative = require('../../Renderer/shims/ReactNative'); - +const Platform = require('../../Utilities/Platform'); +const registerGeneratedViewConfig = require('../../Utilities/registerGeneratedViewConfig'); +const ReactNativeViewViewConfigAndroid = require('./ReactNativeViewViewConfigAndroid'); const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); import type {ViewProps} from './ViewPropTypes'; type ViewNativeComponentType = Class>; -const NativeViewComponent = requireNativeComponent('RCTView'); +let NativeViewComponent; +let viewConfig; -module.exports = ((NativeViewComponent: any): ViewNativeComponentType); +// Only use the JS view config in DEV +if (__DEV__) { + // On Android, View extends the base component with additional view-only props + // On iOS, the base component is View + if (Platform.OS === 'android') { + viewConfig = ReactNativeViewViewConfigAndroid; + registerGeneratedViewConfig('RCTView', ReactNativeViewViewConfigAndroid); + } else { + viewConfig = {}; + registerGeneratedViewConfig('RCTView', {uiViewClassName: 'RCTView'}); + } + + NativeViewComponent = 'RCTView'; +} else { + NativeViewComponent = requireNativeComponent('RCTView'); +} + +export const __INTERNAL_VIEW_CONFIG = viewConfig; +export default ((NativeViewComponent: any): ViewNativeComponentType); diff --git a/Libraries/Utilities/verifyComponentAttributeEquivalence.js b/Libraries/Utilities/verifyComponentAttributeEquivalence.js index 560cf9f0ee1..a4db5ef2d25 100644 --- a/Libraries/Utilities/verifyComponentAttributeEquivalence.js +++ b/Libraries/Utilities/verifyComponentAttributeEquivalence.js @@ -15,7 +15,7 @@ const getNativeComponentAttributes = require('../ReactNative/getNativeComponentA import type {ReactNativeBaseComponentViewConfig} from '../Renderer/shims/ReactNativeTypes'; import ReactNativeViewViewConfig from '../Components/View/ReactNativeViewViewConfig'; -const IGNORED_KEYS = ['transform']; +const IGNORED_KEYS = ['transform', 'hitSlop']; /** * The purpose of this function is to validate that the view config that * native exposes for a given view manager is the same as the view config