Skip to content

Commit af34681

Browse files
committed
fix: add missing events
1 parent b45445f commit af34681

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,18 @@ React.useEffect(() => {
9595
}, [navigation]);
9696
```
9797

98+
Only supported on iOS.
99+
98100
#### `orientationChange`
99101

100102
This event is fired when the orientation changes while the modal is being displayed and on initial render. Same as the [`onOrientationChange` prop](https://reactnative.dev/docs/modal#onorientationchange).
101103

104+
It receives an object in the `data` property of the event, which contains the key `orientation` with the value `portrait` or `landscape`:
105+
106+
```js
107+
console.log(e.data) // { orientation: 'portrait' }
108+
```
109+
102110
Example:
103111

104112
```js

src/ModalView.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ export default function ModalView({ state, navigation, descriptors }: Props) {
5353
{...options}
5454
animationType={animationType}
5555
presentationStyle={presentationStyle}
56+
onShow={() =>
57+
navigation.emit({
58+
type: 'show',
59+
target: route.key,
60+
})
61+
}
62+
onDismiss={() =>
63+
navigation.emit({
64+
type: 'dismiss',
65+
target: route.key,
66+
})
67+
}
68+
onOrientationChange={(e) =>
69+
navigation.emit({
70+
type: 'orientationChange',
71+
target: route.key,
72+
data: e.nativeEvent,
73+
})
74+
}
5675
onRequestClose={() => {
5776
navigation.dispatch({
5877
...StackActions.pop(),

src/types.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export type Scene = {
1818

1919
export type ModalNavigationConfig = {};
2020

21-
export type ModalNavigationOptions = React.ComponentProps<typeof Modal>;
21+
export type ModalNavigationOptions = Omit<
22+
React.ComponentProps<typeof Modal>,
23+
'visible' | 'onDismiss' | 'onOrientationChange' | 'onRequestClose' | 'onShow'
24+
>;
2225

2326
export type ModalNavigationEventMap = {
2427
/**
@@ -27,14 +30,16 @@ export type ModalNavigationEventMap = {
2730
show: { data: undefined };
2831
/**
2932
* Event which fires when a modal is dismissed.
33+
* Only supported on iOS.
3034
*/
3135
dismiss: { data: undefined };
3236
/**
3337
* Event which fires when the orientation changes while the modal is being displayed.
3438
* The orientation provided is only 'portrait' or 'landscape'.
3539
* This event also fires on initial render, regardless of the current orientation.
40+
* Only supported on iOS.
3641
*/
37-
orientationChange: { data: undefined };
42+
orientationChange: { data: { orientation: 'portrait' | 'landscape' } };
3843
};
3944

4045
export type ModalNavigationHelpers = NavigationHelpers<

0 commit comments

Comments
 (0)