Skip to content

Commit 4f4aa69

Browse files
authored
Adding setNativeProps tests for NativeMethodsMixin (#14901)
1 parent b96b61d commit 4f4aa69

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

packages/react-native-renderer/src/NativeMethodsMixin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ export default function(
142142
return;
143143
}
144144

145+
const nativeTag =
146+
maybeInstance._nativeTag || maybeInstance.canonical._nativeTag;
145147
const viewConfig: ReactNativeBaseComponentViewConfig<> =
146-
maybeInstance.viewConfig;
148+
maybeInstance.viewConfig || maybeInstance.canonical.viewConfig;
147149

148150
if (__DEV__) {
149151
warnForStyleProps(nativeProps, viewConfig.validAttributes);
@@ -156,7 +158,7 @@ export default function(
156158
// view invalidation for certain components (eg RCTTextInput) on iOS.
157159
if (updatePayload != null) {
158160
UIManager.updateView(
159-
maybeInstance._nativeTag,
161+
nativeTag,
160162
viewConfig.uiViewClassName,
161163
updatePayload,
162164
);

packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
let React;
1414
let ReactFabric;
15+
let createReactClass;
1516
let createReactNativeComponentClass;
1617
let UIManager;
1718
let FabricUIManager;
1819
let StrictMode;
20+
let NativeMethodsMixin;
1921

2022
jest.mock('shared/ReactFeatureFlags', () =>
2123
require('shared/forks/ReactFeatureFlags.native-oss'),
@@ -30,8 +32,16 @@ describe('ReactFabric', () => {
3032
ReactFabric = require('react-native-renderer/fabric');
3133
FabricUIManager = require('FabricUIManager');
3234
UIManager = require('UIManager');
35+
createReactClass = require('create-react-class/factory')(
36+
React.Component,
37+
React.isValidElement,
38+
new React.Component().updater,
39+
);
3340
createReactNativeComponentClass = require('ReactNativeViewConfigRegistry')
3441
.register;
42+
NativeMethodsMixin =
43+
ReactFabric.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
44+
.NativeMethodsMixin;
3545
});
3646

3747
it('should be able to create and render a native component', () => {
@@ -169,7 +179,14 @@ describe('ReactFabric', () => {
169179
}
170180
}
171181

172-
[View, Subclass].forEach(Component => {
182+
const CreateClass = createReactClass({
183+
mixins: [NativeMethodsMixin],
184+
render: () => {
185+
return <View />;
186+
},
187+
});
188+
189+
[View, Subclass, CreateClass].forEach(Component => {
173190
UIManager.updateView.mockReset();
174191

175192
let viewRef;

packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
let React;
1414
let StrictMode;
1515
let ReactNative;
16+
let createReactClass;
1617
let createReactNativeComponentClass;
1718
let UIManager;
19+
let NativeMethodsMixin;
1820

1921
describe('ReactNative', () => {
2022
beforeEach(() => {
@@ -24,8 +26,16 @@ describe('ReactNative', () => {
2426
StrictMode = React.StrictMode;
2527
ReactNative = require('react-native-renderer');
2628
UIManager = require('UIManager');
29+
createReactClass = require('create-react-class/factory')(
30+
React.Component,
31+
React.isValidElement,
32+
new React.Component().updater,
33+
);
2734
createReactNativeComponentClass = require('ReactNativeViewConfigRegistry')
2835
.register;
36+
NativeMethodsMixin =
37+
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
38+
.NativeMethodsMixin;
2939
});
3040

3141
it('should be able to create and render a native component', () => {
@@ -100,7 +110,14 @@ describe('ReactNative', () => {
100110
}
101111
}
102112

103-
[View, Subclass].forEach(Component => {
113+
const CreateClass = createReactClass({
114+
mixins: [NativeMethodsMixin],
115+
render: () => {
116+
return <View />;
117+
},
118+
});
119+
120+
[View, Subclass, CreateClass].forEach(Component => {
104121
UIManager.updateView.mockReset();
105122

106123
let viewRef;

0 commit comments

Comments
 (0)