Skip to content

Commit 3f7f9d8

Browse files
gabrieldonadelmeta-codesync[bot]
authored andcommitted
Expose NativeComponentRegistry API to index.d.ts (#54043)
Summary: Follow up of #52999 so that users can import `NativeComponentRegistry` from react-native when using typescript On 0.82 when users try to import `NativeComponentRegistry` without using the Strict TypeScript API they get: ``` Module '"react-native"' has no exported member 'NativeComponentRegistry'.ts(2305) ``` ## Changelog: [GENERAL] [ADDED] - Expose NativeComponentRegistry API to index.d.ts Pull Request resolved: #54043 Test Plan: CI should be green Reviewed By: christophpurrer Differential Revision: D83830024 Pulled By: huntie fbshipit-source-id: e63258b30aed4b33b2881656df0ad88a4a7d670a
1 parent b9baddf commit 3f7f9d8

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
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+
| {
71+
readonly [propName: string]: AnyAttributeType;
72+
}
73+
| undefined;
74+
};
75+
76+
type PartialViewConfig = Readonly<{
77+
bubblingEventTypes?:
78+
| {
79+
readonly [eventName: string]: {
80+
readonly phasedRegistrationNames: {
81+
readonly bubbled: string;
82+
readonly captured: string;
83+
readonly skipBubbling?: boolean | undefined;
84+
};
85+
};
86+
}
87+
| undefined;
88+
directEventTypes?:
89+
| {
90+
readonly [eventName: string]: {
91+
readonly registrationName: string;
92+
};
93+
}
94+
| undefined;
95+
supportsRawText?: boolean | undefined;
96+
uiViewClassName: string;
97+
validAttributes?: AttributeConfiguration | undefined;
98+
}>;

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)