-
Notifications
You must be signed in to change notification settings - Fork 24.3k
/
RendererImplementation.js
112 lines (102 loc) · 2.9 KB
/
RendererImplementation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* 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 {HostComponent} from '../Renderer/shims/ReactNativeTypes';
import type {Element, ElementRef, ElementType} from 'react';
import {type RootTag} from './RootTag';
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__);
}