Skip to content

Commit 7cc8c76

Browse files
ya-nshmeta-codesync[bot]
authored andcommitted
fix(types): expose Modal native ref prop (facebook#56952)
Summary: - add `modalRef` to the hand-written `Modal` TypeScript declarations - align the hand-written declaration with existing `React.RefObject` ref prop typing patterns - add typetest coverage for passing a Modal ref through `modalRef` This replaces facebook#56889, which GitHub auto-closed after its pull ref got stuck on a bad force-pushed commit. The branch here contains the same scoped fix plus the review feedback from facebook#56889. `Modal` already accepts `modalRef` at runtime and the generated API snapshot already includes it. The hand-written declarations were the odd one out, so TypeScript users could not pass the supported ref prop without a local cast. ## Changelog: [General] [Fixed] - Expose Modal native ref prop in TypeScript declarations Pull Request resolved: facebook#56952 Test Plan: - `npx prettier --check packages/react-native/Libraries/Modal/Modal.d.ts packages/react-native/types/__typetests__/index.tsx` - `npm run test-typescript -- --pretty false` - `npm run build-types` - `npm run test-generated-typescript -- --pretty false` Reviewed By: cipolleschi Differential Revision: D107081018 Pulled By: huntie fbshipit-source-id: 74a4a6db6d295543557106618b39be6007e1049d
1 parent c789880 commit 7cc8c76

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

packages/react-native/Libraries/Modal/Modal.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export interface ModalBaseProps {
5050
* Defaults to `white` if not provided and transparent is `false`. Ignored if `transparent` is `true`.
5151
*/
5252
backdropColor?: ColorValue | undefined;
53+
54+
/**
55+
* A ref to the native Modal component.
56+
*/
57+
modalRef?: React.RefObject<Modal | null> | undefined;
5358
}
5459

5560
export interface ModalPropsIOS {

packages/react-native/types/__typetests__/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
FocusEvent,
4747
GestureResponderEvent,
4848
HostComponent,
49+
HostInstance,
4950
I18nManager,
5051
Image,
5152
ImageBackground,
@@ -1540,6 +1541,10 @@ const KeyboardAvoidingViewTest = () => <KeyboardAvoidingView enabled />;
15401541

15411542
const ModalTest = () => <Modal hardwareAccelerated />;
15421543
const ModalTest2 = () => <Modal hardwareAccelerated testID="modal-test-2" />;
1544+
const ModalRefTest = () => {
1545+
const modalRef = React.useRef<Modal & HostInstance>(null);
1546+
return <Modal modalRef={modalRef} />;
1547+
};
15431548

15441549
// $ExpectType HostComponent<{ nativeProp: string; }>
15451550
const NativeBridgedComponent = requireNativeComponent<{nativeProp: string}>(

0 commit comments

Comments
 (0)