77 * @flow
88 */
99
10- import type { HostComponent } from './ReactNativeTypes' ;
1110import type { ReactPortal , ReactNodeList } from 'shared/ReactTypes' ;
1211import type { ElementRef , Element , ElementType } from 'react' ;
1312import type { FiberRoot } from 'react-reconciler/src/ReactInternalTypes' ;
1413
1514import './ReactFabricInjection' ;
1615
1716import {
18- findHostInstance ,
19- findHostInstanceWithWarning ,
2017 batchedUpdates as batchedUpdatesImpl ,
2118 discreteUpdates ,
2219 createContainer ,
@@ -29,159 +26,19 @@ import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal
2926import { setBatchingImplementation } from './legacy-events/ReactGenericBatching' ;
3027import ReactVersion from 'shared/ReactVersion' ;
3128
32- // Modules provided by RN:
33- import {
34- UIManager ,
35- legacySendAccessibilityEvent ,
36- } from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' ;
37-
3829import { getClosestInstanceFromNode } from './ReactFabricComponentTree' ;
3930import {
4031 getInspectorDataForViewTag ,
4132 getInspectorDataForViewAtPoint ,
4233 getInspectorDataForInstance ,
4334} from './ReactNativeFiberInspector' ;
4435import { LegacyRoot , ConcurrentRoot } from 'react-reconciler/src/ReactRootTags' ;
45- import ReactSharedInternals from 'shared/ReactSharedInternals' ;
46- import getComponentNameFromType from 'shared/getComponentNameFromType' ;
47-
48- const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
49-
50- function findHostInstance_DEPRECATED < TElementType : ElementType > (
51- componentOrHandle: ?(ElementRef< TElementType > | number),
52- ): ?ElementRef< HostComponent < mixed > > {
53- if ( __DEV__ ) {
54- const owner = ReactCurrentOwner . current ;
55- if ( owner !== null && owner . stateNode !== null ) {
56- if ( ! owner . stateNode . _warnedAboutRefsInRender ) {
57- console . error (
58- '%s is accessing findNodeHandle inside its render(). ' +
59- 'render() should be a pure function of props and state. It should ' +
60- 'never access something that requires stale data from the previous ' +
61- 'render, such as refs. Move this logic to componentDidMount and ' +
62- 'componentDidUpdate instead.' ,
63- getComponentNameFromType ( owner . type ) || 'A component' ,
64- ) ;
65- }
66-
67- owner . stateNode . _warnedAboutRefsInRender = true ;
68- }
69- }
70- if (componentOrHandle == null) {
71- return null ;
72- }
73- // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
74- if (componentOrHandle._nativeTag) {
75- // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
76- return componentOrHandle ;
77- }
78- // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
79- if (componentOrHandle.canonical && componentOrHandle . canonical . _nativeTag ) {
80- // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
81- return componentOrHandle . canonical ;
82- }
83- let hostInstance;
84- if (__DEV__) {
85- hostInstance = findHostInstanceWithWarning (
86- componentOrHandle ,
87- 'findHostInstance_DEPRECATED' ,
88- ) ;
89- } else {
90- hostInstance = findHostInstance ( componentOrHandle ) ;
91- }
92-
93- return hostInstance;
94- }
95-
96- function findNodeHandle ( componentOrHandle : any ) : ?number {
97- if ( __DEV__ ) {
98- const owner = ReactCurrentOwner . current ;
99- if ( owner !== null && owner . stateNode !== null ) {
100- if ( ! owner . stateNode . _warnedAboutRefsInRender ) {
101- console . error (
102- '%s is accessing findNodeHandle inside its render(). ' +
103- 'render() should be a pure function of props and state. It should ' +
104- 'never access something that requires stale data from the previous ' +
105- 'render, such as refs. Move this logic to componentDidMount and ' +
106- 'componentDidUpdate instead.' ,
107- getComponentNameFromType ( owner . type ) || 'A component' ,
108- ) ;
109- }
110-
111- owner . stateNode . _warnedAboutRefsInRender = true ;
112- }
113- }
114- if (componentOrHandle == null) {
115- return null ;
116- }
117- if (typeof componentOrHandle === 'number') {
118- // Already a node handle
119- return componentOrHandle ;
120- }
121- if (componentOrHandle._nativeTag) {
122- return componentOrHandle . _nativeTag ;
123- }
124- if (componentOrHandle.canonical && componentOrHandle . canonical . _nativeTag ) {
125- return componentOrHandle . canonical . _nativeTag ;
126- }
127- let hostInstance;
128- if (__DEV__) {
129- hostInstance = findHostInstanceWithWarning (
130- componentOrHandle ,
131- 'findNodeHandle' ,
132- ) ;
133- } else {
134- hostInstance = findHostInstance ( componentOrHandle ) ;
135- }
136-
137- if (hostInstance == null) {
138- return hostInstance ;
139- }
140-
141- return hostInstance._nativeTag;
142- }
143-
144- function dispatchCommand ( handle : any , command : string , args : Array < any > ) {
145- if ( handle . _nativeTag == null ) {
146- if ( __DEV__ ) {
147- console . error (
148- "dispatchCommand was called with a ref that isn't a " +
149- 'native component. Use React.forwardRef to get access to the underlying native component' ,
150- ) ;
151- }
152- return ;
153- }
154-
155- if ( handle . _internalInstanceHandle != null ) {
156- const { stateNode} = handle . _internalInstanceHandle ;
157- if ( stateNode != null ) {
158- nativeFabricUIManager . dispatchCommand ( stateNode . node , command , args ) ;
159- }
160- } else {
161- UIManager . dispatchViewManagerCommand ( handle . _nativeTag , command , args ) ;
162- }
163- }
164-
165- function sendAccessibilityEvent ( handle : any , eventType : string ) {
166- if ( handle . _nativeTag == null ) {
167- if ( __DEV__ ) {
168- console . error (
169- "sendAccessibilityEvent was called with a ref that isn't a " +
170- 'native component. Use React.forwardRef to get access to the underlying native component' ,
171- ) ;
172- }
173- return ;
174- }
175-
176- if ( handle . _internalInstanceHandle != null ) {
177- const { stateNode} = handle . _internalInstanceHandle ;
178- if ( stateNode != null ) {
179- nativeFabricUIManager . sendAccessibilityEvent ( stateNode . node , eventType ) ;
180- }
181- } else {
182- legacySendAccessibilityEvent ( handle . _nativeTag , eventType ) ;
183- }
184- }
36+ import {
37+ findHostInstance_DEPRECATED ,
38+ findNodeHandle ,
39+ dispatchCommand ,
40+ sendAccessibilityEvent ,
41+ } from './ReactNativePublicCompat' ;
18542
18643// $FlowFixMe[missing-local-annot]
18744function onRecoverableError ( error ) {
0 commit comments