Skip to content

Commit c018c42

Browse files
WoLewickija1ns
authored andcommitted
feat: call onGestureCancel in modal too (software-mansion#2184)
PR adding calling onGestureCancel when trying to dismiss a modal with gestureEnabled set to false.
1 parent 39a2110 commit c018c42

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

apps/test-examples/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import Test2028 from './src/Test2028';
101101
import Test2048 from './src/Test2048';
102102
import Test2069 from './src/Test2069';
103103
import Test2118 from './src/Test2118';
104+
import Test2184 from './src/Test2184';
104105
import TestScreenAnimation from './src/TestScreenAnimation';
105106

106107
enableFreeze(true);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, { useEffect } from 'react';
2+
import { Button } from 'react-native';
3+
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
4+
import {
5+
createNativeStackNavigator,
6+
NativeStackNavigationProp,
7+
} from '@react-navigation/native-stack';
8+
9+
const Stack = createNativeStackNavigator();
10+
11+
export default function App() {
12+
return (
13+
<NavigationContainer>
14+
<Stack.Navigator>
15+
<Stack.Screen name="First" component={First} />
16+
<Stack.Screen
17+
name="Second"
18+
component={Second}
19+
options={{ presentation: 'modal', gestureEnabled: false }}
20+
/>
21+
</Stack.Navigator>
22+
</NavigationContainer>
23+
);
24+
}
25+
26+
type Props = {
27+
navigation: NativeStackNavigationProp<ParamListBase>;
28+
};
29+
30+
const First = ({ navigation }: Props): JSX.Element => {
31+
return (
32+
<Button
33+
title="Tap me for second screen"
34+
onPress={() => navigation.navigate('Second')}
35+
/>
36+
);
37+
};
38+
39+
const Second = ({ navigation }: Props): JSX.Element => {
40+
useEffect(() => {
41+
const unsubscribe = navigation.addListener('gestureCancel', () => {
42+
console.log('gestureCancel');
43+
});
44+
45+
return unsubscribe;
46+
}, [navigation]);
47+
48+
return (
49+
<Button
50+
title="Tap me for first screen"
51+
onPress={() => navigation.goBack()}
52+
/>
53+
);
54+
};

ios/RNSScreen.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,14 @@ - (void)notifyTransitionProgress:(double)progress closing:(BOOL)closing goingFor
521521
#endif
522522
}
523523

524+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
525+
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
526+
- (void)presentationControllerDidAttemptToDismiss:(UIPresentationController *)presentationController
527+
{
528+
[self notifyGestureCancel];
529+
}
530+
#endif
531+
524532
- (void)presentationControllerWillDismiss:(UIPresentationController *)presentationController
525533
{
526534
// We need to call both "cancel" and "reset" here because RN's gesture recognizer

0 commit comments

Comments
 (0)