[Native] Enable and remove targetAsInstance feature flag. (#18182)
Eli White committed
Feb 28, 2020 at 13:45 UTC
26aa1987ce823f54ebc90b2538184fefbc16b99a
17 files changed
+20
-253
packages/react-native-renderer/src/ReactFabricComponentTree.js
+6
-14
@@ -7,25 +7,17 @@
7
8
import invariant from 'shared/invariant';
9
10
-import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags';
11
-
10
function getInstanceFromInstance(instanceHandle) {
11
return instanceHandle;
12
}
13
14
function getTagFromInstance(inst) {
17
- if (enableNativeTargetAsInstance) {
18
- let nativeInstance = inst.stateNode.canonical;
19
- invariant(
20
- nativeInstance._nativeTag,
21
- 'All native instances should have a tag.',
22
- );
23
- return nativeInstance;
24
- } else {
25
- let tag = inst.stateNode.canonical._nativeTag;
26
- invariant(tag, 'All native instances should have a tag.');
27
- return tag;
28
- }
15
+ let nativeInstance = inst.stateNode.canonical;
16
+ invariant(
17
+ nativeInstance._nativeTag,
18
+ 'All native instances should have a tag.',
19
+ );
20
+ return nativeInstance;
21
}
22
23
export {
packages/react-native-renderer/src/ReactFabricEventEmitter.js
+5
-10
@@ -19,7 +19,6 @@ import {registrationNameModules} from 'legacy-events/EventPluginRegistry';
19
import {batchedUpdates} from 'legacy-events/ReactGenericBatching';
20
import accumulateInto from 'legacy-events/accumulateInto';
21
22
-import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags';
22
import {plugins} from 'legacy-events/EventPluginRegistry';
23
import getListener from 'legacy-events/getListener';
24
import {runEventsInBatch} from 'legacy-events/EventBatching';
@@ -85,16 +84,12 @@ export function dispatchEvent(
84
const targetFiber = (target: null | Fiber);
85
86
let eventTarget = null;
88
- if (enableNativeTargetAsInstance) {
89
- if (targetFiber != null) {
90
- const stateNode = targetFiber.stateNode;
91
- // Guard against Fiber being unmounted
92
- if (stateNode != null) {
93
- eventTarget = stateNode.canonical;
94
- }
87
+ if (targetFiber != null) {
88
+ const stateNode = targetFiber.stateNode;
89
+ // Guard against Fiber being unmounted
90
+ if (stateNode != null) {
91
+ eventTarget = stateNode.canonical;
92
}
96
- } else {
97
- eventTarget = nativeEvent.target;
93
}
94
95
batchedUpdates(function() {
packages/react-native-renderer/src/ReactNativeComponentTree.js
+7
-18
@@ -7,8 +7,6 @@
7
8
import invariant from 'shared/invariant';
9
10
-import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags';
11
-
10
const instanceCache = new Map();
11
const instanceProps = new Map();
12
@@ -26,23 +24,14 @@ function getInstanceFromTag(tag) {
24
}
25
26
function getTagFromInstance(inst) {
29
- if (enableNativeTargetAsInstance) {
30
- let nativeInstance = inst.stateNode;
31
- let tag = nativeInstance._nativeTag;
32
- if (tag === undefined) {
33
- nativeInstance = nativeInstance.canonical;
34
- tag = nativeInstance._nativeTag;
35
- }
36
- invariant(tag, 'All native instances should have a tag.');
37
- return nativeInstance;
38
- } else {
39
- let tag = inst.stateNode._nativeTag;
40
- if (tag === undefined) {
41
- tag = inst.stateNode.canonical._nativeTag;
42
- }
43
- invariant(tag, 'All native instances should have a tag.');
44
- return tag;
27
+ let nativeInstance = inst.stateNode;
28
+ let tag = nativeInstance._nativeTag;
29
+ if (tag === undefined) {
30
+ nativeInstance = nativeInstance.canonical;
31
+ tag = nativeInstance._nativeTag;
32
}
33
+ invariant(tag, 'All native instances should have a tag.');
34
+ return nativeInstance;
35
}
36
37
export {
packages/react-native-renderer/src/ReactNativeEventEmitter.js
+2
-7
@@ -18,7 +18,6 @@ import {PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags';
18
import {registrationNameModules} from 'legacy-events/EventPluginRegistry';
19
import {batchedUpdates} from 'legacy-events/ReactGenericBatching';
20
import {runEventsInBatch} from 'legacy-events/EventBatching';
21
-import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags';
21
import {plugins} from 'legacy-events/EventPluginRegistry';
22
import getListener from 'legacy-events/getListener';
23
import accumulateInto from 'legacy-events/accumulateInto';
@@ -104,12 +103,8 @@ function _receiveRootNodeIDEvent(
103
const inst = getInstanceFromNode(rootNodeID);
104
105
let target = null;
107
- if (enableNativeTargetAsInstance) {
108
- if (inst != null) {
109
- target = inst.stateNode;
110
- }
111
- } else {
112
- target = nativeEvent.target;
106
+ if (inst != null) {
107
+ target = inst.stateNode;
108
}
109
110
batchedUpdates(function() {
packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js
-107
@@ -12,7 +12,6 @@
12
13
let React;
14
let ReactFabric;
15
-let ReactFeatureFlags;
15
let createReactNativeComponentClass;
16
let UIManager;
17
let StrictMode;
@@ -38,7 +37,6 @@ describe('ReactFabric', () => {
37
React = require('react');
38
StrictMode = React.StrictMode;
39
ReactFabric = require('react-native-renderer/fabric');
41
- ReactFeatureFlags = require('shared/ReactFeatureFlags');
40
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
41
.UIManager;
42
createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
@@ -649,112 +647,7 @@ describe('ReactFabric', () => {
647
expect(touchStart2).toBeCalled();
648
});
649
652
- it('dispatches event with target as reactTag', () => {
653
- ReactFeatureFlags.enableNativeTargetAsInstance = false;
654
-
655
- const View = createReactNativeComponentClass('RCTView', () => ({
656
- validAttributes: {
657
- id: true,
658
- },
659
- uiViewClassName: 'RCTView',
660
- directEventTypes: {
661
- topTouchStart: {
662
- registrationName: 'onTouchStart',
663
- },
664
- topTouchEnd: {
665
- registrationName: 'onTouchEnd',
666
- },
667
- },
668
- }));
669
-
670
- function getViewById(id) {
671
- const [
672
- reactTag,
673
- ,
674
- ,
675
- ,
676
- instanceHandle,
677
- ] = nativeFabricUIManager.createNode.mock.calls.find(
678
- args => args[3] && args[3].id === id,
679
- );
680
-
681
- return {reactTag, instanceHandle};
682
- }
683
-
684
- const ref1 = React.createRef();
685
- const ref2 = React.createRef();
686
-
687
- ReactFabric.render(
688
- <View id="parent">
689
- <View
690
- ref={ref1}
691
- id="one"
692
- onResponderStart={event => {
693
- expect(ref1.current).not.toBeNull();
694
- expect(ReactFabric.findNodeHandle(ref1.current)).toEqual(
695
- event.target,
696
- );
697
- expect(ReactFabric.findNodeHandle(ref1.current)).toEqual(
698
- event.currentTarget,
699
- );
700
- }}
701
- onStartShouldSetResponder={() => true}
702
- />
703
- <View
704
- ref={ref2}
705
- id="two"
706
- onResponderStart={event => {
707
- expect(ref2.current).not.toBeNull();
708
- expect(ReactFabric.findNodeHandle(ref2.current)).toEqual(
709
- event.target,
710
- );
711
- expect(ReactFabric.findNodeHandle(ref2.current)).toEqual(
712
- event.currentTarget,
713
- );
714
- }}
715
- onStartShouldSetResponder={() => true}
716
- />
717
- </View>,
718
- 1,
719
- );
720
-
721
- let [
722
- dispatchEvent,
723
- ] = nativeFabricUIManager.registerEventHandler.mock.calls[0];
724
-
725
- dispatchEvent(getViewById('one').instanceHandle, 'topTouchStart', {
726
- target: getViewById('one').reactTag,
727
- identifier: 17,
728
- touches: [],
729
- changedTouches: [],
730
- });
731
- dispatchEvent(getViewById('one').instanceHandle, 'topTouchEnd', {
732
- target: getViewById('one').reactTag,
733
- identifier: 17,
734
- touches: [],
735
- changedTouches: [],
736
- });
737
-
738
- dispatchEvent(getViewById('two').instanceHandle, 'topTouchStart', {
739
- target: getViewById('two').reactTag,
740
- identifier: 17,
741
- touches: [],
742
- changedTouches: [],
743
- });
744
-
745
- dispatchEvent(getViewById('two').instanceHandle, 'topTouchEnd', {
746
- target: getViewById('two').reactTag,
747
- identifier: 17,
748
- touches: [],
749
- changedTouches: [],
750
- });
751
-
752
- expect.assertions(6);
753
- });
754
-
650
it('dispatches event with target as instance', () => {
756
- ReactFeatureFlags.enableNativeTargetAsInstance = true;
757
-
651
const View = createReactNativeComponentClass('RCTView', () => ({
652
validAttributes: {
653
id: true,
packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js
-79
@@ -14,7 +14,6 @@ let PropTypes;
14
let RCTEventEmitter;
15
let React;
16
let ReactNative;
17
-let ReactFeatureFlags;
17
let ResponderEventPlugin;
18
let UIManager;
19
let createReactNativeComponentClass;
@@ -69,7 +68,6 @@ beforeEach(() => {
68
.RCTEventEmitter;
69
React = require('react');
70
ReactNative = require('react-native-renderer');
72
- ReactFeatureFlags = require('shared/ReactFeatureFlags');
71
ResponderEventPlugin = require('legacy-events/ResponderEventPlugin').default;
72
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
73
.UIManager;
@@ -459,84 +457,7 @@ it('handles events without target', () => {
457
]);
458
});
459
462
-it('dispatches event with target as reactTag', () => {
463
- ReactFeatureFlags.enableNativeTargetAsInstance = false;
464
- const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
465
-
466
- const View = fakeRequireNativeComponent('View', {id: true});
467
-
468
- function getViewById(id) {
469
- return UIManager.createView.mock.calls.find(
470
- args => args[3] && args[3].id === id,
471
- )[0];
472
- }
473
-
474
- const ref1 = React.createRef();
475
- const ref2 = React.createRef();
476
-
477
- ReactNative.render(
478
- <View id="parent">
479
- <View
480
- ref={ref1}
481
- id="one"
482
- onResponderStart={event => {
483
- expect(ref1.current).not.toBeNull();
484
- expect(ReactNative.findNodeHandle(ref1.current)).toEqual(
485
- event.target,
486
- );
487
- expect(ReactNative.findNodeHandle(ref1.current)).toEqual(
488
- event.currentTarget,
489
- );
490
- }}
491
- onStartShouldSetResponder={() => true}
492
- />
493
- <View
494
- ref={ref2}
495
- id="two"
496
- onResponderStart={event => {
497
- expect(ref2.current).not.toBeNull();
498
- expect(ReactNative.findNodeHandle(ref2.current)).toEqual(
499
- event.target,
500
- );
501
- expect(ReactNative.findNodeHandle(ref2.current)).toEqual(
502
- event.currentTarget,
503
- );
504
- }}
505
- onStartShouldSetResponder={() => true}
506
- />
507
- </View>,
508
- 1,
509
- );
510
-
511
- EventEmitter.receiveTouches(
512
- 'topTouchStart',
513
- [{target: getViewById('one'), identifier: 17}],
514
- [0],
515
- );
516
-
517
- EventEmitter.receiveTouches(
518
- 'topTouchEnd',
519
- [{target: getViewById('one'), identifier: 17}],
520
- [0],
521
- );
522
-
523
- EventEmitter.receiveTouches(
524
- 'topTouchStart',
525
- [{target: getViewById('two'), identifier: 18}],
526
- [0],
527
- );
528
-
529
- EventEmitter.receiveTouches(
530
- 'topTouchEnd',
531
- [{target: getViewById('two'), identifier: 18}],
532
- [0],
533
- );
534
-
535
- expect.assertions(6);
536
-});
537
-
460
it('dispatches event with target as instance', () => {
539
- ReactFeatureFlags.enableNativeTargetAsInstance = true;
461
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
462
463
const View = fakeRequireNativeComponent('View', {id: true});
packages/shared/ReactFeatureFlags.js
-3
@@ -83,9 +83,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
83
84
export const enableTrustedTypesIntegration = false;
85
86
-// Flag to turn event.target and event.currentTarget in ReactNative from a reactTag to a component instance
87
-export const enableNativeTargetAsInstance = false;
88
-
86
// Controls sequence of passive effect destroy and create functions.
87
// If this flag is off, destroy and create functions may be interleaved.
88
// When the flag is on, all destroy functions will be run (for all fibers)
packages/shared/forks/ReactFeatureFlags.native-fb.js
-5
@@ -12,11 +12,6 @@ import invariant from 'shared/invariant';
12
import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
13
import typeof * as ExportsType from './ReactFeatureFlags.native-fb';
14
15
-// Uncomment to re-export dynamic flags from the fbsource version.
16
-export const {
17
- enableNativeTargetAsInstance,
18
-} = require('../shims/ReactFeatureFlags');
19
-
15
// The rest of the flags are static for better dead code elimination.
16
export const enableUserTimingAPI = __DEV__;
17
export const enableProfilerTimer = __PROFILE__;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false;
36
export const disableLegacyContext = false;
37
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
38
export const enableTrustedTypesIntegration = false;
39
-export const enableNativeTargetAsInstance = false;
39
export const disableTextareaChildren = false;
40
export const disableMapsAsChildren = false;
41
export const warnUnstableRenderSubtreeIntoContainer = false;
packages/shared/forks/ReactFeatureFlags.persistent.js
-1
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false;
36
export const disableLegacyContext = false;
37
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
38
export const enableTrustedTypesIntegration = false;
39
-export const enableNativeTargetAsInstance = false;
39
export const disableTextareaChildren = false;
40
export const disableMapsAsChildren = false;
41
export const warnUnstableRenderSubtreeIntoContainer = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false;
36
export const disableLegacyContext = false;
37
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
38
export const enableTrustedTypesIntegration = false;
39
-export const enableNativeTargetAsInstance = false;
39
export const disableTextareaChildren = false;
40
export const disableMapsAsChildren = false;
41
export const warnUnstableRenderSubtreeIntoContainer = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false;
36
export const disableLegacyContext = false;
37
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
38
export const enableTrustedTypesIntegration = false;
39
-export const enableNativeTargetAsInstance = false;
39
export const disableTextareaChildren = false;
40
export const disableMapsAsChildren = false;
41
export const warnUnstableRenderSubtreeIntoContainer = false;
packages/shared/forks/ReactFeatureFlags.testing.js
-1
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false;
36
export const disableLegacyContext = false;
37
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
38
export const enableTrustedTypesIntegration = false;
39
-export const enableNativeTargetAsInstance = false;
39
export const disableTextareaChildren = false;
40
export const disableMapsAsChildren = false;
41
export const warnUnstableRenderSubtreeIntoContainer = false;
packages/shared/forks/ReactFeatureFlags.testing.www.js
-1
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false;
36
export const disableLegacyContext = __EXPERIMENTAL__;
37
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
38
export const enableTrustedTypesIntegration = false;
39
-export const enableNativeTargetAsInstance = false;
39
export const disableTextareaChildren = __EXPERIMENTAL__;
40
export const disableMapsAsChildren = __EXPERIMENTAL__;
41
export const warnUnstableRenderSubtreeIntoContainer = false;
packages/shared/forks/ReactFeatureFlags.www.js
-2
@@ -89,8 +89,6 @@ export const enableSuspenseCallback = true;
89
90
export const flushSuspenseFallbacksInTests = true;
91
92
-export const enableNativeTargetAsInstance = false;
93
-
92
export const disableTextareaChildren = __EXPERIMENTAL__;
93
94
export const disableMapsAsChildren = __EXPERIMENTAL__;
scripts/flow/react-native-host-hooks.js
-1
@@ -187,5 +187,4 @@ declare module 'RTManager' {
187
// shims/ReactFeatureFlags is generated by the packaging script
188
declare module '../shims/ReactFeatureFlags' {
189
declare export var debugRenderPhaseSideEffects: boolean;
190
- declare export var enableNativeTargetAsInstance: boolean;
190
}
scripts/rollup/shims/react-native/ReactFeatureFlags.js
-1
@@ -12,7 +12,6 @@
12
13
const ReactFeatureFlags = {
14
debugRenderPhaseSideEffects: false,
15
- enableNativeTargetAsInstance: false,
15
};
16
17
module.exports = ReactFeatureFlags;