@samitouri / QOS-React-2 / commits / 4be45be5ff

Stop warning about setNativeProps being deprecated (#17045)

* Stop warning about setNativeProps being deprecated * Remove ReactNative.setNativeProps * Remove more Fabric tests

Eli White committed Oct 8, 2019 at 11:21 UTC 4be45be5ff4b26892bab83b5f9022afac1a664fb
17 files changed +3 -310
packages/react-native-renderer/src/NativeMethodsMixin.js
-13
@@ -30,7 +30,6 @@ import {
30 } from './NativeMethodsMixinUtils';
31
32 import warningWithoutStack from 'shared/warningWithoutStack';
33 -import {warnAboutDeprecatedSetNativeProps} from 'shared/ReactFeatureFlags';
33
34 export default function(
35 findNodeHandle: any => ?number,
@@ -251,18 +250,6 @@ export default function(
250 return;
251 }
252
254 - if (__DEV__) {
255 - if (warnAboutDeprecatedSetNativeProps) {
256 - warningWithoutStack(
257 - false,
258 - 'Warning: Calling ref.setNativeProps(nativeProps) ' +
259 - 'is deprecated and will be removed in a future release. ' +
260 - 'Use the setNativeProps export from the react-native package instead.' +
261 - "\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
262 - );
263 - }
264 - }
265 -
253 const nativeTag =
254 maybeInstance._nativeTag || maybeInstance.canonical._nativeTag;
255 const viewConfig: ReactNativeBaseComponentViewConfig<> =
packages/react-native-renderer/src/ReactFabric.js
-9
@@ -109,15 +109,6 @@ const ReactFabric: ReactFabricType = {
109
110 findNodeHandle,
111
112 - setNativeProps(handle: any, nativeProps: Object) {
113 - warningWithoutStack(
114 - false,
115 - 'Warning: setNativeProps is not currently supported in Fabric',
116 - );
117 -
118 - return;
119 - },
120 -
112 dispatchCommand(handle: any, command: string, args: Array<any>) {
113 const invalid =
114 handle._nativeTag == null || handle._internalInstanceHandle == null;
packages/react-native-renderer/src/ReactNativeComponent.js
-13
@@ -27,7 +27,6 @@ import {create} from './ReactNativeAttributePayload';
27 import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
28
29 import warningWithoutStack from 'shared/warningWithoutStack';
30 -import {warnAboutDeprecatedSetNativeProps} from 'shared/ReactFeatureFlags';
30
31 export default function(
32 findNodeHandle: any => ?number,
@@ -262,18 +261,6 @@ export default function(
261 return;
262 }
263
265 - if (__DEV__) {
266 - if (warnAboutDeprecatedSetNativeProps) {
267 - warningWithoutStack(
268 - false,
269 - 'Warning: Calling ref.setNativeProps(nativeProps) ' +
270 - 'is deprecated and will be removed in a future release. ' +
271 - 'Use the setNativeProps export from the react-native package instead.' +
272 - "\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
273 - );
274 - }
275 - }
276 -
264 const nativeTag =
265 maybeInstance._nativeTag || maybeInstance.canonical._nativeTag;
266 const viewConfig: ReactNativeBaseComponentViewConfig<> =
packages/react-native-renderer/src/ReactNativeFiberHostComponent.js
-10
@@ -29,7 +29,6 @@ import {
29 } from './NativeMethodsMixinUtils';
30
31 import warningWithoutStack from 'shared/warningWithoutStack';
32 -import {warnAboutDeprecatedSetNativeProps} from 'shared/ReactFeatureFlags';
32
33 /**
34 * This component defines the same methods as NativeMethodsMixin but without the
@@ -104,15 +103,6 @@ class ReactNativeFiberHostComponent {
103
104 setNativeProps(nativeProps: Object) {
105 if (__DEV__) {
107 - if (warnAboutDeprecatedSetNativeProps) {
108 - warningWithoutStack(
109 - false,
110 - 'Warning: Calling ref.setNativeProps(nativeProps) ' +
111 - 'is deprecated and will be removed in a future release. ' +
112 - 'Use the setNativeProps export from the react-native package instead.' +
113 - "\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
114 - );
115 - }
106 warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
107 }
108
packages/react-native-renderer/src/ReactNativeRenderer.js
-3
@@ -39,7 +39,6 @@ import NativeMethodsMixin from './NativeMethodsMixin';
39 import ReactNativeComponent from './ReactNativeComponent';
40 import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
41 import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
42 -import {setNativeProps} from './ReactNativeRendererSharedExports';
42
43 import {LegacyRoot} from 'shared/ReactRootTags';
44 import ReactSharedInternals from 'shared/ReactSharedInternals';
@@ -133,8 +132,6 @@ const ReactNativeRenderer: ReactNativeType = {
132 UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args);
133 },
134
136 - setNativeProps,
137 -
135 render(element: React$Element<any>, containerTag: any, callback: ?Function) {
136 let root = roots.get(containerTag);
137
packages/react-native-renderer/src/ReactNativeRendererSharedExports.js deleted
-43
@@ -1,43 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import {create} from './ReactNativeAttributePayload';
11 -import {warnForStyleProps} from './NativeMethodsMixinUtils';
12 -
13 -import warningWithoutStack from 'shared/warningWithoutStack';
14 -
15 -// Module provided by RN:
16 -import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
17 -
18 -export function setNativeProps(handle: any, nativeProps: Object): void {
19 - if (handle._nativeTag == null) {
20 - warningWithoutStack(
21 - handle._nativeTag != null,
22 - "setNativeProps was called with a ref that isn't a " +
23 - 'native component. Use React.forwardRef to get access to the underlying native component',
24 - );
25 - return;
26 - }
27 -
28 - if (__DEV__) {
29 - warnForStyleProps(nativeProps, handle.viewConfig.validAttributes);
30 - }
31 -
32 - const updatePayload = create(nativeProps, handle.viewConfig.validAttributes);
33 - // Avoid the overhead of bridge calls if there's no update.
34 - // This is an expensive no-op for Android, and causes an unnecessary
35 - // view invalidation for certain components (eg RCTTextInput) on iOS.
36 - if (updatePayload != null) {
37 - UIManager.updateView(
38 - handle._nativeTag,
39 - handle.viewConfig.uiViewClassName,
40 - updatePayload,
41 - );
42 - }
43 -}
packages/react-native-renderer/src/ReactNativeTypes.js
-2
@@ -143,7 +143,6 @@ export type ReactNativeType = {
143 NativeComponent: typeof ReactNativeComponent,
144 findNodeHandle(componentOrHandle: any): ?number,
145 dispatchCommand(handle: any, command: string, args: Array<any>): void,
146 - setNativeProps(handle: any, nativeProps: Object): void,
146 render(
147 element: React$Element<any>,
148 containerTag: any,
@@ -160,7 +159,6 @@ export type ReactFabricType = {
159 NativeComponent: typeof ReactNativeComponent,
160 findNodeHandle(componentOrHandle: any): ?number,
161 dispatchCommand(handle: any, command: string, args: Array<any>): void,
163 - setNativeProps(handle: any, nativeProps: Object): void,
162 render(
163 element: React$Element<any>,
164 containerTag: any,
packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js
-81
@@ -12,7 +12,6 @@
12
13 let React;
14 let ReactFabric;
15 -let ReactFeatureFlags;
15 let createReactClass;
16 let createReactNativeComponentClass;
17 let UIManager;
@@ -38,8 +37,6 @@ describe('ReactFabric', () => {
37
38 React = require('react');
39 StrictMode = React.StrictMode;
41 - ReactFeatureFlags = require('shared/ReactFeatureFlags');
42 - ReactFeatureFlags.warnAboutDeprecatedSetNativeProps = true;
40 ReactFabric = require('react-native-renderer/fabric');
41 UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
42 .UIManager;
@@ -338,84 +335,6 @@ describe('ReactFabric', () => {
335 });
336 });
337
341 - it('setNativeProps on native refs should no-op', () => {
342 - const View = createReactNativeComponentClass('RCTView', () => ({
343 - validAttributes: {foo: true},
344 - uiViewClassName: 'RCTView',
345 - }));
346 -
347 - UIManager.updateView.mockReset();
348 -
349 - let viewRef;
350 - ReactFabric.render(
351 - <View
352 - foo="bar"
353 - ref={ref => {
354 - viewRef = ref;
355 - }}
356 - />,
357 - 11,
358 - );
359 -
360 - expect(UIManager.updateView).not.toBeCalled();
361 - expect(() => {
362 - ReactFabric.setNativeProps(viewRef, {foo: 'baz'});
363 - }).toWarnDev([SET_NATIVE_PROPS_NOT_SUPPORTED_MESSAGE], {
364 - withoutStack: true,
365 - });
366 - expect(UIManager.updateView).not.toBeCalled();
367 - });
368 -
369 - it('should warn and no-op if calling setNativeProps on non native refs', () => {
370 - const View = createReactNativeComponentClass('RCTView', () => ({
371 - validAttributes: {foo: true},
372 - uiViewClassName: 'RCTView',
373 - }));
374 -
375 - class BasicClass extends React.Component {
376 - render() {
377 - return <React.Fragment />;
378 - }
379 - }
380 -
381 - class Subclass extends ReactFabric.NativeComponent {
382 - render() {
383 - return <View />;
384 - }
385 - }
386 -
387 - const CreateClass = createReactClass({
388 - mixins: [NativeMethodsMixin],
389 - render: () => {
390 - return <View />;
391 - },
392 - });
393 -
394 - [BasicClass, Subclass, CreateClass].forEach(Component => {
395 - UIManager.updateView.mockReset();
396 -
397 - let viewRef;
398 - ReactFabric.render(
399 - <Component
400 - foo="bar"
401 - ref={ref => {
402 - viewRef = ref;
403 - }}
404 - />,
405 - 11,
406 - );
407 -
408 - expect(UIManager.updateView).not.toBeCalled();
409 - expect(() => {
410 - ReactFabric.setNativeProps(viewRef, {foo: 'baz'});
411 - }).toWarnDev([SET_NATIVE_PROPS_NOT_SUPPORTED_MESSAGE], {
412 - withoutStack: true,
413 - });
414 -
415 - expect(UIManager.updateView).not.toBeCalled();
416 - });
417 - });
418 -
338 it('should call FabricUIManager.measure on ref.measure', () => {
339 const View = createReactNativeComponentClass('RCTView', () => ({
340 validAttributes: {foo: true},
packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js
-20
@@ -73,24 +73,4 @@ describe('ReactFabric', () => {
73 [10, 20],
74 );
75 });
76 -
77 - it('sets native props with setNativeProps on Fabric nodes with the RN renderer', () => {
78 - UIManager.updateView.mockReset();
79 - const View = createReactNativeComponentClass('RCTView', () => ({
80 - validAttributes: {title: true},
81 - uiViewClassName: 'RCTView',
82 - }));
83 -
84 - let ref = React.createRef();
85 -
86 - ReactFabric.render(<View title="bar" ref={ref} />, 11);
87 - expect(UIManager.updateView).not.toBeCalled();
88 - ReactNative.setNativeProps(ref.current, {title: 'baz'});
89 - expect(UIManager.updateView).toHaveBeenCalledTimes(1);
90 - expect(UIManager.updateView).toHaveBeenCalledWith(
91 - expect.any(Number),
92 - 'RCTView',
93 - {title: 'baz'},
94 - );
95 - });
76 });
packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js
+3 -106
@@ -11,7 +11,6 @@
11 'use strict';
12
13 let React;
14 -let ReactFeatureFlags;
14 let StrictMode;
15 let ReactNative;
16 let createReactClass;
@@ -23,20 +22,12 @@ const DISPATCH_COMMAND_REQUIRES_HOST_COMPONENT =
22 "Warning: dispatchCommand was called with a ref that isn't a " +
23 'native component. Use React.forwardRef to get access to the underlying native component';
24
26 -const SET_NATIVE_PROPS_DEPRECATION_MESSAGE =
27 - 'Warning: Calling ref.setNativeProps(nativeProps) ' +
28 - 'is deprecated and will be removed in a future release. ' +
29 - 'Use the setNativeProps export from the react-native package instead.' +
30 - "\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n";
31 -
25 describe('ReactNative', () => {
26 beforeEach(() => {
27 jest.resetModules();
28
29 React = require('react');
30 StrictMode = React.StrictMode;
38 - ReactFeatureFlags = require('shared/ReactFeatureFlags');
39 - ReactFeatureFlags.warnAboutDeprecatedSetNativeProps = true;
31 ReactNative = require('react-native-renderer');
32 UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
33 .UIManager;
@@ -223,21 +214,13 @@ describe('ReactNative', () => {
214 />,
215 11,
216 );
226 - expect(UIManager.updateView).not.toBeCalled();
217
228 - expect(() => {
229 - viewRef.setNativeProps({});
230 - }).toWarnDev([SET_NATIVE_PROPS_DEPRECATION_MESSAGE], {
231 - withoutStack: true,
232 - });
218 expect(UIManager.updateView).not.toBeCalled();
219
235 - expect(() => {
236 - viewRef.setNativeProps({foo: 'baz'});
237 - }).toWarnDev([SET_NATIVE_PROPS_DEPRECATION_MESSAGE], {
238 - withoutStack: true,
239 - });
220 + viewRef.setNativeProps({});
221 + expect(UIManager.updateView).not.toBeCalled();
222
223 + viewRef.setNativeProps({foo: 'baz'});
224 expect(UIManager.updateView).toHaveBeenCalledTimes(1);
225 expect(UIManager.updateView).toHaveBeenCalledWith(
226 expect.any(Number),
@@ -247,92 +230,6 @@ describe('ReactNative', () => {
230 });
231 });
232
250 - it('should be able to setNativeProps on native refs', () => {
251 - const View = createReactNativeComponentClass('RCTView', () => ({
252 - validAttributes: {foo: true},
253 - uiViewClassName: 'RCTView',
254 - }));
255 -
256 - UIManager.updateView.mockReset();
257 -
258 - let viewRef;
259 - ReactNative.render(
260 - <View
261 - foo="bar"
262 - ref={ref => {
263 - viewRef = ref;
264 - }}
265 - />,
266 - 11,
267 - );
268 -
269 - ReactNative.setNativeProps(viewRef, {});
270 - expect(UIManager.updateView).not.toBeCalled();
271 -
272 - ReactNative.setNativeProps(viewRef, {foo: 'baz'});
273 - expect(UIManager.updateView).toHaveBeenCalledTimes(1);
274 - expect(UIManager.updateView).toHaveBeenCalledWith(
275 - expect.any(Number),
276 - 'RCTView',
277 - {foo: 'baz'},
278 - );
279 - });
280 -
281 - it('should warn and no-op if calling setNativeProps on non native refs', () => {
282 - const View = createReactNativeComponentClass('RCTView', () => ({
283 - validAttributes: {foo: true},
284 - uiViewClassName: 'RCTView',
285 - }));
286 -
287 - class BasicClass extends React.Component {
288 - render() {
289 - return <React.Fragment />;
290 - }
291 - }
292 -
293 - class Subclass extends ReactNative.NativeComponent {
294 - render() {
295 - return <View />;
296 - }
297 - }
298 -
299 - const CreateClass = createReactClass({
300 - mixins: [NativeMethodsMixin],
301 - render: () => {
302 - return <View />;
303 - },
304 - });
305 -
306 - [BasicClass, Subclass, CreateClass].forEach(Component => {
307 - UIManager.updateView.mockReset();
308 -
309 - let viewRef;
310 - ReactNative.render(
311 - <Component
312 - foo="bar"
313 - ref={ref => {
314 - viewRef = ref;
315 - }}
316 - />,
317 - 11,
318 - );
319 -
320 - expect(UIManager.updateView).not.toBeCalled();
321 - expect(() => {
322 - ReactNative.setNativeProps(viewRef, {foo: 'baz'});
323 - }).toWarnDev(
324 - [
325 - "Warning: setNativeProps was called with a ref that isn't a " +
326 - 'native component. Use React.forwardRef to get access ' +
327 - 'to the underlying native component',
328 - ],
329 - {withoutStack: true},
330 - );
331 -
332 - expect(UIManager.updateView).not.toBeCalled();
333 - });
334 - });
335 -
233 it('should call UIManager.measure on ref.measure', () => {
234 const View = createReactNativeComponentClass('RCTView', () => ({
235 validAttributes: {foo: true},
packages/shared/ReactFeatureFlags.js
-4
@@ -56,10 +56,6 @@ export const enableStableConcurrentModeAPIs = false;
56
57 export const warnAboutShorthandPropertyCollision = false;
58
59 -// See https://github.com/react-native-community/discussions-and-proposals/issues/72 for more information
60 -// This is a flag so we can fix warnings in RN core before turning it on
61 -export const warnAboutDeprecatedSetNativeProps = false;
62 -
59 // Experimental React Flare event system and event components support.
60 export const enableFlareAPI = false;
61
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -31,7 +31,6 @@ export const disableJavaScriptURLs = false;
31 export const disableInputAttributeSyncing = false;
32 export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
33 export const warnAboutDeprecatedLifecycles = true;
34 -export const warnAboutDeprecatedSetNativeProps = true;
34 export const enableFlareAPI = false;
35 export const enableFundamentalAPI = false;
36 export const enableScopeAPI = false;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -26,7 +26,6 @@ export const disableInputAttributeSyncing = false;
26 export const enableStableConcurrentModeAPIs = false;
27 export const warnAboutShorthandPropertyCollision = false;
28 export const enableSchedulerDebugging = false;
29 -export const warnAboutDeprecatedSetNativeProps = false;
29 export const enableFlareAPI = false;
30 export const enableFundamentalAPI = false;
31 export const enableScopeAPI = false;
packages/shared/forks/ReactFeatureFlags.persistent.js
-1
@@ -26,7 +26,6 @@ export const disableInputAttributeSyncing = false;
26 export const enableStableConcurrentModeAPIs = false;
27 export const warnAboutShorthandPropertyCollision = false;
28 export const enableSchedulerDebugging = false;
29 -export const warnAboutDeprecatedSetNativeProps = false;
29 export const enableFlareAPI = false;
30 export const enableFundamentalAPI = false;
31 export const enableScopeAPI = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -26,7 +26,6 @@ export const disableInputAttributeSyncing = false;
26 export const enableStableConcurrentModeAPIs = false;
27 export const warnAboutShorthandPropertyCollision = false;
28 export const enableSchedulerDebugging = false;
29 -export const warnAboutDeprecatedSetNativeProps = false;
29 export const enableFlareAPI = false;
30 export const enableFundamentalAPI = false;
31 export const enableScopeAPI = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -23,7 +23,6 @@ export const enableSuspenseServerRenderer = false;
23 export const enableSelectiveHydration = false;
24 export const enableStableConcurrentModeAPIs = false;
25 export const enableSchedulerDebugging = false;
26 -export const warnAboutDeprecatedSetNativeProps = false;
26 export const disableJavaScriptURLs = false;
27 export const enableFlareAPI = true;
28 export const enableFundamentalAPI = false;
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -34,7 +34,6 @@ export const enableSchedulerDebugging = true;
34 export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
35 export const warnAboutDeprecatedLifecycles = true;
36 export const warnAboutShorthandPropertyCollision = false;
37 -export const warnAboutDeprecatedSetNativeProps = false;
37 export const disableLegacyContext = false;
38 export const warnAboutStringRefs = false;
39 export const warnAboutDefaultPropsOnFunctionComponents = false;