Skip to content

Commit f9a81fa

Browse files
Expose NativeComponentRegistry API toindex.d.ts
1 parent aab0d33 commit f9a81fa

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
import type {HostComponent} from '../../types/public/ReactNativeTypes';
11+
import * as React from 'react';
12+
13+
/**
14+
* Configures a function that is called to determine whether a given component
15+
* should be registered using reflection of the native component at runtime.
16+
*
17+
* The provider should return null if the native component is unavailable in
18+
* the current environment.
19+
*/
20+
export function setRuntimeConfigProvider(
21+
runtimeConfigProvider: (name: string) => {
22+
native: boolean;
23+
verify: boolean;
24+
} | null
25+
): void;
26+
27+
/**
28+
* Gets a `NativeComponent` that can be rendered by React Native.
29+
*
30+
* The supplied `viewConfigProvider` may or may not be invoked and utilized,
31+
* depending on how `setRuntimeConfigProvider` is configured.
32+
*/
33+
export function get<Config extends object>(
34+
name: string,
35+
viewConfigProvider: () => PartialViewConfig,
36+
): HostComponent<Config>;
37+
38+
/**
39+
* Same as `NativeComponentRegistry.get(...)`, except this will check either
40+
* the `setRuntimeConfigProvider` configuration or use native reflection (slow)
41+
* to determine whether this native component is available.
42+
*
43+
* If the native component is not available, a stub component is returned. Note
44+
* that the return value of this is not `HostComponent` because the returned
45+
* component instance is not guaranteed to have native methods.
46+
*/
47+
export function getWithFallback_DEPRECATED<Config extends object>(
48+
name: string,
49+
viewConfigProvider: () => PartialViewConfig,
50+
): React.ComponentType<Config>;
51+
52+
/**
53+
* Unstable API. Do not use!
54+
*
55+
* This method returns if there is a StaticViewConfig registered for the
56+
* component name received as a parameter.
57+
*/
58+
export function unstable_hasStaticViewConfig(name: string): boolean;
59+
60+
type AttributeType<T, V> =
61+
| true
62+
| {
63+
readonly diff?: ((arg1: T, arg2: T) => boolean) | undefined
64+
readonly process?: ((arg1: V) => T) | undefined
65+
}
66+
type AnyAttributeType = AttributeType<any, any>
67+
type AttributeConfiguration = {
68+
readonly [propName: string]: AnyAttributeType | void
69+
readonly style?: {
70+
readonly [propName: string]: AnyAttributeType
71+
} | undefined
72+
}
73+
74+
type PartialViewConfig = Readonly<{
75+
bubblingEventTypes?: {
76+
readonly [eventName: string]: {
77+
readonly phasedRegistrationNames: {
78+
readonly bubbled: string
79+
readonly captured: string
80+
readonly skipBubbling?: boolean | undefined
81+
}
82+
}
83+
} | undefined;
84+
directEventTypes?: {
85+
readonly [eventName: string]: {
86+
readonly registrationName: string
87+
}
88+
} | undefined;
89+
supportsRawText?: boolean | undefined;
90+
uiViewClassName: string;
91+
validAttributes?: AttributeConfiguration | undefined;
92+
}>;

packages/react-native/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export * from '../Libraries/Components/View/ViewAccessibility';
104104
export * from '../Libraries/Components/View/ViewPropTypes';
105105
export * from '../Libraries/Components/Button';
106106
export * from '../Libraries/Core/registerCallableModule';
107+
export * as NativeComponentRegistry from '../Libraries/NativeComponent/NativeComponentRegistry';
107108
export * from '../Libraries/EventEmitter/NativeEventEmitter';
108109
export * from '../Libraries/EventEmitter/RCTDeviceEventEmitter';
109110
export * from '../Libraries/EventEmitter/RCTNativeAppEventEmitter';

0 commit comments

Comments
 (0)