-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract use of renderer to its own module
Summary: This diff creates a proxy module to interact with the React Native renderer. The goal of this proxy is to decouple usages of several functions (e.g.: `findNodeHandle`, etc.) from the actual renderer used in an app. This way, we can easily switch between renderers without having to change code depending on it. This will be useful to remove a specific renderer from an app bundle when it's no longer used (e.g.: Paper on the Facebook App). Changelog: [Internal] Reviewed By: javache Differential Revision: D39205975 fbshipit-source-id: 05289c0c3c8cd26d81aa1d2163097c73ec40c6ad
- Loading branch information
1 parent
5efb4f0
commit b06cae3
Showing
6 changed files
with
175 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @flow strict-local | ||
*/ | ||
|
||
import {type RootTag} from './RootTag'; | ||
import type {Element, ElementType, ElementRef} from 'react'; | ||
import type {HostComponent} from '../Renderer/shims/ReactNativeTypes'; | ||
|
||
export function renderElement({ | ||
element, | ||
rootTag, | ||
useFabric, | ||
useConcurrentRoot, | ||
}: { | ||
element: Element<ElementType>, | ||
rootTag: number, | ||
useFabric: boolean, | ||
useConcurrentRoot: boolean, | ||
}): void { | ||
if (useFabric) { | ||
require('../Renderer/shims/ReactFabric').render( | ||
element, | ||
rootTag, | ||
null, | ||
useConcurrentRoot, | ||
); | ||
} else { | ||
require('../Renderer/shims/ReactNative').render(element, rootTag); | ||
} | ||
} | ||
|
||
export function findHostInstance_DEPRECATED<TElementType: ElementType>( | ||
componentOrHandle: ?(ElementRef<TElementType> | number), | ||
): ?ElementRef<HostComponent<mixed>> { | ||
return require('../Renderer/shims/ReactNative').findHostInstance_DEPRECATED( | ||
componentOrHandle, | ||
); | ||
} | ||
|
||
export function findNodeHandle<TElementType: ElementType>( | ||
componentOrHandle: ?(ElementRef<TElementType> | number), | ||
): ?number { | ||
return require('../Renderer/shims/ReactNative').findNodeHandle( | ||
componentOrHandle, | ||
); | ||
} | ||
|
||
export function dispatchCommand( | ||
handle: ElementRef<HostComponent<mixed>>, | ||
command: string, | ||
args: Array<mixed>, | ||
): void { | ||
if (global.RN$Bridgeless === true) { | ||
// Note: this function has the same implementation in the legacy and new renderer. | ||
// However, evaluating the old renderer comes with some side effects. | ||
return require('../Renderer/shims/ReactFabric').dispatchCommand( | ||
handle, | ||
command, | ||
args, | ||
); | ||
} else { | ||
return require('../Renderer/shims/ReactNative').dispatchCommand( | ||
handle, | ||
command, | ||
args, | ||
); | ||
} | ||
} | ||
|
||
export function sendAccessibilityEvent( | ||
handle: ElementRef<HostComponent<mixed>>, | ||
eventType: string, | ||
): void { | ||
return require('../Renderer/shims/ReactNative').sendAccessibilityEvent( | ||
handle, | ||
eventType, | ||
); | ||
} | ||
|
||
/** | ||
* This method is used by AppRegistry to unmount a root when using the old | ||
* React Native renderer (Paper). | ||
*/ | ||
export function unmountComponentAtNodeAndRemoveContainer(rootTag: RootTag) { | ||
// $FlowExpectedError[incompatible-type] rootTag is an opaque type so we can't really cast it as is. | ||
const rootTagAsNumber: number = rootTag; | ||
require('../Renderer/shims/ReactNative').unmountComponentAtNodeAndRemoveContainer( | ||
rootTagAsNumber, | ||
); | ||
} | ||
|
||
export function unstable_batchedUpdates<T>( | ||
fn: T => void, | ||
bookkeeping: T, | ||
): void { | ||
// This doesn't actually do anything when batching updates for a Fabric root. | ||
return require('../Renderer/shims/ReactNative').unstable_batchedUpdates( | ||
fn, | ||
bookkeeping, | ||
); | ||
} | ||
|
||
export function isProfilingRenderer(): boolean { | ||
return Boolean(__DEV__); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @flow strict-local | ||
*/ | ||
|
||
/** | ||
* This module exists to allow apps to select their renderer implementation | ||
* (e.g.: Fabric-only, Paper-only) without having to pull all the renderer | ||
* implementations into their app bundle, which affects app size. | ||
* | ||
* By default, the setup will be: | ||
* -> RendererProxy | ||
* -> RendererImplementation (which uses Fabric or Paper depending on a flag at runtime) | ||
* | ||
* But this will allow a setup like this without duplicating logic: | ||
* -> RendererProxy (fork) | ||
* -> RendererImplementation (which uses Fabric or Paper depending on a flag at runtime) | ||
* or -> OtherImplementation (which uses Fabric only) | ||
*/ | ||
|
||
export * from './RendererImplementation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters