From 42cf8a92416a49584e8eedda798c371eb83ec932 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Mon, 22 Jul 2019 09:21:01 -0700 Subject: [PATCH] Retry add JS view config for View Summary: Adds the JavaScript view config for View Reviewed By: TheSavior Differential Revision: D15862368 fbshipit-source-id: 8a6a77cf57e84744044a2d6034aff2be6e600f5f --- .../View/ReactNativeViewViewConfigAndroid.js | 1 + .../Components/View/ViewNativeComponent.js | 29 ++++++++++++++++--- .../verifyComponentAttributeEquivalence.js | 2 +- jest/setup.js | 17 ++++++++++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Libraries/Components/View/ReactNativeViewViewConfigAndroid.js b/Libraries/Components/View/ReactNativeViewViewConfigAndroid.js index 9396eb842c5..250b0634bae 100644 --- a/Libraries/Components/View/ReactNativeViewViewConfigAndroid.js +++ b/Libraries/Components/View/ReactNativeViewViewConfigAndroid.js @@ -60,6 +60,7 @@ const ReactNativeViewViewConfigAndroid = { }, validAttributes: { hasTVPreferredFocus: true, + focusable: true, nativeBackgroundAndroid: true, nativeForegroundAndroid: true, nextFocusDown: true, diff --git a/Libraries/Components/View/ViewNativeComponent.js b/Libraries/Components/View/ViewNativeComponent.js index 36a71deed99..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>; -export default ((requireNativeComponent( - 'RCTView', -): any): ViewNativeComponentType); +let NativeViewComponent; +let viewConfig; + +// 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 diff --git a/jest/setup.js b/jest/setup.js index a6faf2a996e..b26efd77ba8 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -348,4 +348,19 @@ jest .mock( '../Libraries/Utilities/verifyComponentAttributeEquivalence', () => function() {}, - ); + ) + .mock('../Libraries/Components/View/ViewNativeComponent', () => { + const React = require('react'); + const Component = class extends React.Component { + render() { + return React.createElement('View', this.props, this.props.children); + } + }; + + Component.displayName = 'View'; + + return { + __esModule: true, + default: Component, + }; + });