Skip to content

Commit 26aa198

Browse files
authored
[Native] Enable and remove targetAsInstance feature flag. (#18182)
1 parent 4469700 commit 26aa198

17 files changed

+20
-253
lines changed

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

+6-14
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@
77

88
import invariant from 'shared/invariant';
99

10-
import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags';
11-
1210
function getInstanceFromInstance(instanceHandle) {
1311
return instanceHandle;
1412
}
1513

1614
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;
2921
}
3022

3123
export {

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

+5-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {registrationNameModules} from 'legacy-events/EventPluginRegistry';
1919
import {batchedUpdates} from 'legacy-events/ReactGenericBatching';
2020
import accumulateInto from 'legacy-events/accumulateInto';
2121

22-
import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags';
2322
import {plugins} from 'legacy-events/EventPluginRegistry';
2423
import getListener from 'legacy-events/getListener';
2524
import {runEventsInBatch} from 'legacy-events/EventBatching';
@@ -85,16 +84,12 @@ export function dispatchEvent(
8584
const targetFiber = (target: null | Fiber);
8685

8786
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;
9592
}
96-
} else {
97-
eventTarget = nativeEvent.target;
9893
}
9994

10095
batchedUpdates(function() {

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

+7-18
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import invariant from 'shared/invariant';
99

10-
import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags';
11-
1210
const instanceCache = new Map();
1311
const instanceProps = new Map();
1412

@@ -26,23 +24,14 @@ function getInstanceFromTag(tag) {
2624
}
2725

2826
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;
4532
}
33+
invariant(tag, 'All native instances should have a tag.');
34+
return nativeInstance;
4635
}
4736

4837
export {

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags';
1818
import {registrationNameModules} from 'legacy-events/EventPluginRegistry';
1919
import {batchedUpdates} from 'legacy-events/ReactGenericBatching';
2020
import {runEventsInBatch} from 'legacy-events/EventBatching';
21-
import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags';
2221
import {plugins} from 'legacy-events/EventPluginRegistry';
2322
import getListener from 'legacy-events/getListener';
2423
import accumulateInto from 'legacy-events/accumulateInto';
@@ -104,12 +103,8 @@ function _receiveRootNodeIDEvent(
104103
const inst = getInstanceFromNode(rootNodeID);
105104

106105
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;
113108
}
114109

115110
batchedUpdates(function() {

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

-107
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
let React;
1414
let ReactFabric;
15-
let ReactFeatureFlags;
1615
let createReactNativeComponentClass;
1716
let UIManager;
1817
let StrictMode;
@@ -38,7 +37,6 @@ describe('ReactFabric', () => {
3837
React = require('react');
3938
StrictMode = React.StrictMode;
4039
ReactFabric = require('react-native-renderer/fabric');
41-
ReactFeatureFlags = require('shared/ReactFeatureFlags');
4240
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
4341
.UIManager;
4442
createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
@@ -649,112 +647,7 @@ describe('ReactFabric', () => {
649647
expect(touchStart2).toBeCalled();
650648
});
651649

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-
755650
it('dispatches event with target as instance', () => {
756-
ReactFeatureFlags.enableNativeTargetAsInstance = true;
757-
758651
const View = createReactNativeComponentClass('RCTView', () => ({
759652
validAttributes: {
760653
id: true,

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

-79
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ let PropTypes;
1414
let RCTEventEmitter;
1515
let React;
1616
let ReactNative;
17-
let ReactFeatureFlags;
1817
let ResponderEventPlugin;
1918
let UIManager;
2019
let createReactNativeComponentClass;
@@ -69,7 +68,6 @@ beforeEach(() => {
6968
.RCTEventEmitter;
7069
React = require('react');
7170
ReactNative = require('react-native-renderer');
72-
ReactFeatureFlags = require('shared/ReactFeatureFlags');
7371
ResponderEventPlugin = require('legacy-events/ResponderEventPlugin').default;
7472
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
7573
.UIManager;
@@ -459,84 +457,7 @@ it('handles events without target', () => {
459457
]);
460458
});
461459

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-
538460
it('dispatches event with target as instance', () => {
539-
ReactFeatureFlags.enableNativeTargetAsInstance = true;
540461
const EventEmitter = RCTEventEmitter.register.mock.calls[0][0];
541462

542463
const View = fakeRequireNativeComponent('View', {id: true});

packages/shared/ReactFeatureFlags.js

-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
8383

8484
export const enableTrustedTypesIntegration = false;
8585

86-
// Flag to turn event.target and event.currentTarget in ReactNative from a reactTag to a component instance
87-
export const enableNativeTargetAsInstance = false;
88-
8986
// Controls sequence of passive effect destroy and create functions.
9087
// If this flag is off, destroy and create functions may be interleaved.
9188
// When the flag is on, all destroy functions will be run (for all fibers)

packages/shared/forks/ReactFeatureFlags.native-fb.js

-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import invariant from 'shared/invariant';
1212
import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
1313
import typeof * as ExportsType from './ReactFeatureFlags.native-fb';
1414

15-
// Uncomment to re-export dynamic flags from the fbsource version.
16-
export const {
17-
enableNativeTargetAsInstance,
18-
} = require('../shims/ReactFeatureFlags');
19-
2015
// The rest of the flags are static for better dead code elimination.
2116
export const enableUserTimingAPI = __DEV__;
2217
export const enableProfilerTimer = __PROFILE__;

packages/shared/forks/ReactFeatureFlags.native-oss.js

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false;
3636
export const disableLegacyContext = false;
3737
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
3838
export const enableTrustedTypesIntegration = false;
39-
export const enableNativeTargetAsInstance = false;
4039
export const disableTextareaChildren = false;
4140
export const disableMapsAsChildren = false;
4241
export const warnUnstableRenderSubtreeIntoContainer = false;

packages/shared/forks/ReactFeatureFlags.persistent.js

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false;
3636
export const disableLegacyContext = false;
3737
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
3838
export const enableTrustedTypesIntegration = false;
39-
export const enableNativeTargetAsInstance = false;
4039
export const disableTextareaChildren = false;
4140
export const disableMapsAsChildren = false;
4241
export const warnUnstableRenderSubtreeIntoContainer = false;

0 commit comments

Comments
 (0)