77 * @flow
88 */
99
10- import type { ReactNativeType , HostComponent } from './ReactNativeTypes' ;
10+ import type { HostComponent } from './ReactNativeTypes' ;
1111import type { ReactNodeList } from 'shared/ReactTypes' ;
1212
1313import './ReactNativeInjection' ;
@@ -26,7 +26,7 @@ import {
2626} from 'react-reconciler/inline.native' ;
2727// TODO: direct imports like some-package/src/* are bad. Fix me.
2828import { getStackByFiberInDevAndProd } from 'react-reconciler/src/ReactCurrentFiber' ;
29- import { createPortal } from 'shared/ReactPortal' ;
29+ import { createPortal as createPortalImpl } from 'shared/ReactPortal' ;
3030import {
3131 setBatchingImplementation ,
3232 batchedUpdates ,
@@ -144,6 +144,71 @@ function findNodeHandle(componentOrHandle: any): ?number {
144144 return hostInstance . _nativeTag ;
145145}
146146
147+ function dispatchCommand ( handle : any , command : string , args : Array < any > ) {
148+ if ( handle . _nativeTag == null ) {
149+ if ( __DEV__ ) {
150+ console . error (
151+ "dispatchCommand was called with a ref that isn't a " +
152+ 'native component. Use React.forwardRef to get access to the underlying native component' ,
153+ ) ;
154+ }
155+ return ;
156+ }
157+
158+ if ( handle . _internalInstanceHandle ) {
159+ nativeFabricUIManager . dispatchCommand (
160+ handle . _internalInstanceHandle . stateNode . node ,
161+ command ,
162+ args ,
163+ ) ;
164+ } else {
165+ UIManager . dispatchViewManagerCommand ( handle . _nativeTag , command , args ) ;
166+ }
167+ }
168+
169+ function render (
170+ element : React$Element < any > ,
171+ containerTag : any ,
172+ callback : ?Function ,
173+ ) {
174+ let root = roots . get ( containerTag ) ;
175+
176+ if ( ! root ) {
177+ // TODO (bvaughn): If we decide to keep the wrapper component,
178+ // We could create a wrapper for containerTag as well to reduce special casing.
179+ root = createContainer ( containerTag , LegacyRoot , false , null ) ;
180+ roots . set ( containerTag , root ) ;
181+ }
182+ updateContainer ( element , root , null , callback ) ;
183+
184+ return getPublicRootInstance ( root ) ;
185+ }
186+
187+ function unmountComponentAtNode ( containerTag : number ) {
188+ const root = roots . get ( containerTag ) ;
189+ if ( root ) {
190+ // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
191+ updateContainer ( null , root , null , ( ) => {
192+ roots . delete ( containerTag ) ;
193+ } ) ;
194+ }
195+ }
196+
197+ function unmountComponentAtNodeAndRemoveContainer ( containerTag : number ) {
198+ unmountComponentAtNode ( containerTag ) ;
199+
200+ // Call back into native to remove all of the subviews from this container
201+ UIManager . removeRootView ( containerTag ) ;
202+ }
203+
204+ function createPortal (
205+ children : ReactNodeList ,
206+ containerTag : number ,
207+ key : ?string = null ,
208+ ) {
209+ return createPortalImpl ( children , containerTag , null , key ) ;
210+ }
211+
147212setBatchingImplementation (
148213 batchedUpdatesImpl ,
149214 discreteUpdates ,
@@ -161,78 +226,22 @@ function computeComponentStackForErrorReporting(reactTag: number): string {
161226
162227const roots = new Map ( ) ;
163228
164- const ReactNativeRenderer : ReactNativeType = {
229+ const Internals = {
230+ computeComponentStackForErrorReporting,
231+ } ;
232+
233+ export {
165234 // This is needed for implementation details of TouchableNativeFeedback
166235 // Remove this once TouchableNativeFeedback doesn't use cloneElement
167236 findHostInstance_DEPRECATED ,
168237 findNodeHandle ,
169-
170- dispatchCommand ( handle : any , command : string , args : Array < any > ) {
171- if ( handle . _nativeTag == null ) {
172- if ( __DEV__ ) {
173- console . error (
174- "dispatchCommand was called with a ref that isn't a " +
175- 'native component. Use React.forwardRef to get access to the underlying native component' ,
176- ) ;
177- }
178- return ;
179- }
180-
181- if ( handle . _internalInstanceHandle ) {
182- nativeFabricUIManager . dispatchCommand (
183- handle . _internalInstanceHandle . stateNode . node ,
184- command ,
185- args ,
186- ) ;
187- } else {
188- UIManager . dispatchViewManagerCommand ( handle . _nativeTag, command, args) ;
189- }
190- } ,
191-
192- render ( element : React$Element < any > , containerTag : any , callback : ?Function ) {
193- let root = roots . get ( containerTag ) ;
194-
195- if ( ! root ) {
196- // TODO (bvaughn): If we decide to keep the wrapper component,
197- // We could create a wrapper for containerTag as well to reduce special casing.
198- root = createContainer ( containerTag , LegacyRoot , false , null ) ;
199- roots . set ( containerTag , root ) ;
200- }
201- updateContainer ( element , root , null , callback ) ;
202-
203- return getPublicRootInstance ( root ) ;
204- } ,
205-
206- unmountComponentAtNode ( containerTag : number ) {
207- const root = roots . get ( containerTag ) ;
208- if ( root ) {
209- // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
210- updateContainer ( null , root , null , ( ) => {
211- roots . delete ( containerTag ) ;
212- } ) ;
213- }
214- } ,
215-
216- unmountComponentAtNodeAndRemoveContainer ( containerTag : number ) {
217- ReactNativeRenderer . unmountComponentAtNode ( containerTag ) ;
218-
219- // Call back into native to remove all of the subviews from this container
220- UIManager . removeRootView ( containerTag ) ;
221- } ,
222-
223- createPortal (
224- children : ReactNodeList ,
225- containerTag : number ,
226- key : ?string = null ,
227- ) {
228- return createPortal ( children , containerTag , null , key ) ;
229- } ,
230-
231- unstable_batchedUpdates: batchedUpdates ,
232-
233- __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED : {
234- computeComponentStackForErrorReporting,
235- } ,
238+ dispatchCommand ,
239+ render ,
240+ unmountComponentAtNode ,
241+ unmountComponentAtNodeAndRemoveContainer ,
242+ createPortal ,
243+ batchedUpdates as unstable_batchedUpdates ,
244+ Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ,
236245} ;
237246
238247injectIntoDevTools ( {
@@ -242,5 +251,3 @@ injectIntoDevTools({
242251 version : ReactVersion ,
243252 rendererPackageName : 'react-native-renderer' ,
244253} ) ;
245-
246- export default ReactNativeRenderer ;
0 commit comments