From 4f4aa69f1b2bdc1ddb00e476f49450e251475e0c Mon Sep 17 00:00:00 2001 From: Eli White Date: Wed, 20 Feb 2019 13:16:35 -0800 Subject: [PATCH] Adding setNativeProps tests for NativeMethodsMixin (#14901) --- .../src/NativeMethodsMixin.js | 6 ++++-- .../__tests__/ReactFabric-test.internal.js | 19 ++++++++++++++++++- .../ReactNativeMount-test.internal.js | 19 ++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/react-native-renderer/src/NativeMethodsMixin.js b/packages/react-native-renderer/src/NativeMethodsMixin.js index 77fd666b3b618..62791c7e62441 100644 --- a/packages/react-native-renderer/src/NativeMethodsMixin.js +++ b/packages/react-native-renderer/src/NativeMethodsMixin.js @@ -142,8 +142,10 @@ export default function( return; } + const nativeTag = + maybeInstance._nativeTag || maybeInstance.canonical._nativeTag; const viewConfig: ReactNativeBaseComponentViewConfig<> = - maybeInstance.viewConfig; + maybeInstance.viewConfig || maybeInstance.canonical.viewConfig; if (__DEV__) { warnForStyleProps(nativeProps, viewConfig.validAttributes); @@ -156,7 +158,7 @@ export default function( // view invalidation for certain components (eg RCTTextInput) on iOS. if (updatePayload != null) { UIManager.updateView( - maybeInstance._nativeTag, + nativeTag, viewConfig.uiViewClassName, updatePayload, ); diff --git a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js index e363a9fed5580..a045729e972d3 100644 --- a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js @@ -12,10 +12,12 @@ let React; let ReactFabric; +let createReactClass; let createReactNativeComponentClass; let UIManager; let FabricUIManager; let StrictMode; +let NativeMethodsMixin; jest.mock('shared/ReactFeatureFlags', () => require('shared/forks/ReactFeatureFlags.native-oss'), @@ -30,8 +32,16 @@ describe('ReactFabric', () => { ReactFabric = require('react-native-renderer/fabric'); FabricUIManager = require('FabricUIManager'); UIManager = require('UIManager'); + createReactClass = require('create-react-class/factory')( + React.Component, + React.isValidElement, + new React.Component().updater, + ); createReactNativeComponentClass = require('ReactNativeViewConfigRegistry') .register; + NativeMethodsMixin = + ReactFabric.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED + .NativeMethodsMixin; }); it('should be able to create and render a native component', () => { @@ -169,7 +179,14 @@ describe('ReactFabric', () => { } } - [View, Subclass].forEach(Component => { + const CreateClass = createReactClass({ + mixins: [NativeMethodsMixin], + render: () => { + return ; + }, + }); + + [View, Subclass, CreateClass].forEach(Component => { UIManager.updateView.mockReset(); let viewRef; diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js index 42c999f77f501..8089088f8faea 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js @@ -13,8 +13,10 @@ let React; let StrictMode; let ReactNative; +let createReactClass; let createReactNativeComponentClass; let UIManager; +let NativeMethodsMixin; describe('ReactNative', () => { beforeEach(() => { @@ -24,8 +26,16 @@ describe('ReactNative', () => { StrictMode = React.StrictMode; ReactNative = require('react-native-renderer'); UIManager = require('UIManager'); + createReactClass = require('create-react-class/factory')( + React.Component, + React.isValidElement, + new React.Component().updater, + ); createReactNativeComponentClass = require('ReactNativeViewConfigRegistry') .register; + NativeMethodsMixin = + ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED + .NativeMethodsMixin; }); it('should be able to create and render a native component', () => { @@ -100,7 +110,14 @@ describe('ReactNative', () => { } } - [View, Subclass].forEach(Component => { + const CreateClass = createReactClass({ + mixins: [NativeMethodsMixin], + render: () => { + return ; + }, + }); + + [View, Subclass, CreateClass].forEach(Component => { UIManager.updateView.mockReset(); let viewRef;