Skip to content

Commit 1b94fd2

Browse files
elicwhitebvaughn
authored andcommitted
Make setNativeProps a no-op with Fabric renderer (#15094)
* Make setNativeProps a no-op with Fabric renderer * Remove unnecessary __DEV__ check
1 parent 08055a6 commit 1b94fd2

File tree

5 files changed

+70
-84
lines changed

5 files changed

+70
-84
lines changed

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

+20-11
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,6 @@ export default function(
124124
* Manipulation](docs/direct-manipulation.html)).
125125
*/
126126
setNativeProps: function(nativeProps: Object) {
127-
if (__DEV__) {
128-
if (warnAboutDeprecatedSetNativeProps) {
129-
warningWithoutStack(
130-
false,
131-
'Warning: Calling ref.setNativeProps(nativeProps) ' +
132-
'is deprecated and will be removed in a future release. ' +
133-
'Use the setNativeProps export from the react-native package instead.' +
134-
"\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
135-
);
136-
}
137-
}
138127
// Class components don't have viewConfig -> validateAttributes.
139128
// Nor does it make sense to set native props on a non-native component.
140129
// Instead, find the nearest host component and set props on it.
@@ -156,6 +145,26 @@ export default function(
156145
return;
157146
}
158147

148+
if (maybeInstance.canonical) {
149+
warningWithoutStack(
150+
false,
151+
'Warning: setNativeProps is not currently supported in Fabric',
152+
);
153+
return;
154+
}
155+
156+
if (__DEV__) {
157+
if (warnAboutDeprecatedSetNativeProps) {
158+
warningWithoutStack(
159+
false,
160+
'Warning: Calling ref.setNativeProps(nativeProps) ' +
161+
'is deprecated and will be removed in a future release. ' +
162+
'Use the setNativeProps export from the react-native package instead.' +
163+
"\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
164+
);
165+
}
166+
}
167+
159168
const nativeTag =
160169
maybeInstance._nativeTag || maybeInstance.canonical._nativeTag;
161170
const viewConfig: ReactNativeBaseComponentViewConfig<> =

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import NativeMethodsMixin from './NativeMethodsMixin';
3232
import ReactNativeComponent from './ReactNativeComponent';
3333
import {getClosestInstanceFromNode} from './ReactFabricComponentTree';
3434
import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
35-
import {setNativeProps} from './ReactNativeRendererSharedExports';
3635

3736
import ReactSharedInternals from 'shared/ReactSharedInternals';
3837
import getComponentName from 'shared/getComponentName';
@@ -105,7 +104,14 @@ const ReactFabric: ReactFabricType = {
105104

106105
findNodeHandle,
107106

108-
setNativeProps,
107+
setNativeProps(handle: any, nativeProps: Object) {
108+
warningWithoutStack(
109+
false,
110+
'Warning: setNativeProps is not currently supported in Fabric',
111+
);
112+
113+
return;
114+
},
109115

110116
render(element: React$Element<any>, containerTag: any, callback: ?Function) {
111117
let root = roots.get(containerTag);

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

+6-29
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ import type {
1616
} from './ReactNativeTypes';
1717
import type {ReactEventResponder} from 'shared/ReactTypes';
1818

19-
import {
20-
mountSafeCallback_NOT_REALLY_SAFE,
21-
warnForStyleProps,
22-
} from './NativeMethodsMixinUtils';
19+
import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
2320
import {create, diff} from './ReactNativeAttributePayload';
2421
import {get as getViewConfigForType} from 'ReactNativeViewConfigRegistry';
2522

2623
import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev';
2724
import invariant from 'shared/invariant';
2825
import warningWithoutStack from 'shared/warningWithoutStack';
29-
import {warnAboutDeprecatedSetNativeProps} from 'shared/ReactFeatureFlags';
3026

3127
import {dispatchEvent} from './ReactFabricEventEmitter';
3228

@@ -136,31 +132,12 @@ class ReactFabricHostComponent {
136132
}
137133

138134
setNativeProps(nativeProps: Object) {
139-
if (__DEV__) {
140-
if (warnAboutDeprecatedSetNativeProps) {
141-
warningWithoutStack(
142-
false,
143-
'Warning: Calling ref.setNativeProps(nativeProps) ' +
144-
'is deprecated and will be removed in a future release. ' +
145-
'Use the setNativeProps export from the react-native package instead.' +
146-
"\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
147-
);
148-
}
149-
warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
150-
}
135+
warningWithoutStack(
136+
false,
137+
'Warning: setNativeProps is not currently supported in Fabric',
138+
);
151139

152-
const updatePayload = create(nativeProps, this.viewConfig.validAttributes);
153-
154-
// Avoid the overhead of bridge calls if there's no update.
155-
// This is an expensive no-op for Android, and causes an unnecessary
156-
// view invalidation for certain components (eg RCTTextInput) on iOS.
157-
if (updatePayload != null) {
158-
UIManager.updateView(
159-
this._nativeTag,
160-
this.viewConfig.uiViewClassName,
161-
updatePayload,
162-
);
163-
}
140+
return;
164141
}
165142
}
166143

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

+20-12
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ export default function(
135135
* Manipulation](docs/direct-manipulation.html)).
136136
*/
137137
setNativeProps(nativeProps: Object): void {
138-
if (__DEV__) {
139-
if (warnAboutDeprecatedSetNativeProps) {
140-
warningWithoutStack(
141-
false,
142-
'Warning: Calling ref.setNativeProps(nativeProps) ' +
143-
'is deprecated and will be removed in a future release. ' +
144-
'Use the setNativeProps export from the react-native package instead.' +
145-
"\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
146-
);
147-
}
148-
}
149-
150138
// Class components don't have viewConfig -> validateAttributes.
151139
// Nor does it make sense to set native props on a non-native component.
152140
// Instead, find the nearest host component and set props on it.
@@ -168,6 +156,26 @@ export default function(
168156
return;
169157
}
170158

159+
if (maybeInstance.canonical) {
160+
warningWithoutStack(
161+
false,
162+
'Warning: setNativeProps is not currently supported in Fabric',
163+
);
164+
return;
165+
}
166+
167+
if (__DEV__) {
168+
if (warnAboutDeprecatedSetNativeProps) {
169+
warningWithoutStack(
170+
false,
171+
'Warning: Calling ref.setNativeProps(nativeProps) ' +
172+
'is deprecated and will be removed in a future release. ' +
173+
'Use the setNativeProps export from the react-native package instead.' +
174+
"\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
175+
);
176+
}
177+
}
178+
171179
const nativeTag =
172180
maybeInstance._nativeTag || maybeInstance.canonical._nativeTag;
173181
const viewConfig: ReactNativeBaseComponentViewConfig<> =

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

+16-30
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ let FabricUIManager;
2020
let StrictMode;
2121
let NativeMethodsMixin;
2222

23-
const SET_NATIVE_PROPS_DEPRECATION_MESSAGE =
24-
'Warning: Calling ref.setNativeProps(nativeProps) ' +
25-
'is deprecated and will be removed in a future release. ' +
26-
'Use the setNativeProps export from the react-native package instead.' +
27-
"\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n";
23+
const SET_NATIVE_PROPS_NOT_SUPPORTED_MESSAGE =
24+
'Warning: setNativeProps is not currently supported in Fabric';
2825

2926
jest.mock('shared/ReactFeatureFlags', () =>
3027
require('shared/forks/ReactFeatureFlags.native-oss'),
@@ -176,7 +173,7 @@ describe('ReactFabric', () => {
176173
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
177174
});
178175

179-
it('should not call UIManager.updateView from ref.setNativeProps for properties that have not changed', () => {
176+
it('should not call UIManager.updateView from ref.setNativeProps', () => {
180177
const View = createReactNativeComponentClass('RCTView', () => ({
181178
validAttributes: {foo: true},
182179
uiViewClassName: 'RCTView',
@@ -212,27 +209,22 @@ describe('ReactFabric', () => {
212209

213210
expect(() => {
214211
viewRef.setNativeProps({});
215-
}).toWarnDev([SET_NATIVE_PROPS_DEPRECATION_MESSAGE], {
212+
}).toWarnDev([SET_NATIVE_PROPS_NOT_SUPPORTED_MESSAGE], {
216213
withoutStack: true,
217214
});
218215

219216
expect(UIManager.updateView).not.toBeCalled();
220217

221218
expect(() => {
222219
viewRef.setNativeProps({foo: 'baz'});
223-
}).toWarnDev([SET_NATIVE_PROPS_DEPRECATION_MESSAGE], {
220+
}).toWarnDev([SET_NATIVE_PROPS_NOT_SUPPORTED_MESSAGE], {
224221
withoutStack: true,
225222
});
226-
expect(UIManager.updateView).toHaveBeenCalledTimes(1);
227-
expect(UIManager.updateView).toHaveBeenCalledWith(
228-
expect.any(Number),
229-
'RCTView',
230-
{foo: 'baz'},
231-
);
223+
expect(UIManager.updateView).not.toBeCalled();
232224
});
233225
});
234226

235-
it('should be able to setNativeProps on native refs', () => {
227+
it('setNativeProps on native refs should no-op', () => {
236228
const View = createReactNativeComponentClass('RCTView', () => ({
237229
validAttributes: {foo: true},
238230
uiViewClassName: 'RCTView',
@@ -252,13 +244,12 @@ describe('ReactFabric', () => {
252244
);
253245

254246
expect(UIManager.updateView).not.toBeCalled();
255-
ReactFabric.setNativeProps(viewRef, {foo: 'baz'});
256-
expect(UIManager.updateView).toHaveBeenCalledTimes(1);
257-
expect(UIManager.updateView).toHaveBeenCalledWith(
258-
expect.any(Number),
259-
'RCTView',
260-
{foo: 'baz'},
261-
);
247+
expect(() => {
248+
ReactFabric.setNativeProps(viewRef, {foo: 'baz'});
249+
}).toWarnDev([SET_NATIVE_PROPS_NOT_SUPPORTED_MESSAGE], {
250+
withoutStack: true,
251+
});
252+
expect(UIManager.updateView).not.toBeCalled();
262253
});
263254

264255
it('should warn and no-op if calling setNativeProps on non native refs', () => {
@@ -303,14 +294,9 @@ describe('ReactFabric', () => {
303294
expect(UIManager.updateView).not.toBeCalled();
304295
expect(() => {
305296
ReactFabric.setNativeProps(viewRef, {foo: 'baz'});
306-
}).toWarnDev(
307-
[
308-
"Warning: setNativeProps was called with a ref that isn't a " +
309-
'native component. Use React.forwardRef to get access ' +
310-
'to the underlying native component',
311-
],
312-
{withoutStack: true},
313-
);
297+
}).toWarnDev([SET_NATIVE_PROPS_NOT_SUPPORTED_MESSAGE], {
298+
withoutStack: true,
299+
});
314300

315301
expect(UIManager.updateView).not.toBeCalled();
316302
});

0 commit comments

Comments
 (0)