Skip to content

Commit

Permalink
feat: call onGestureCancel in modal too (#2184)
Browse files Browse the repository at this point in the history
PR adding calling onGestureCancel when trying to dismiss a modal with gestureEnabled set to false.
  • Loading branch information
WoLewicki committed Jun 17, 2024
1 parent cfc046f commit 1a54e22
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/test-examples/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import Test2028 from './src/Test2028';
import Test2048 from './src/Test2048';
import Test2069 from './src/Test2069';
import Test2118 from './src/Test2118';
import Test2184 from './src/Test2184';
import TestScreenAnimation from './src/TestScreenAnimation';

enableFreeze(true);
Expand Down
54 changes: 54 additions & 0 deletions apps/test-examples/src/Test2184.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useEffect } from 'react';
import { Button } from 'react-native';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from '@react-navigation/native-stack';

const Stack = createNativeStackNavigator();

export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="First" component={First} />
<Stack.Screen
name="Second"
component={Second}
options={{ presentation: 'modal', gestureEnabled: false }}
/>
</Stack.Navigator>
</NavigationContainer>
);
}

type Props = {
navigation: NativeStackNavigationProp<ParamListBase>;
};

const First = ({ navigation }: Props): JSX.Element => {
return (
<Button
title="Tap me for second screen"
onPress={() => navigation.navigate('Second')}
/>
);
};

const Second = ({ navigation }: Props): JSX.Element => {
useEffect(() => {
const unsubscribe = navigation.addListener('gestureCancel', () => {
console.log('gestureCancel');
});

return unsubscribe;
}, [navigation]);

return (
<Button
title="Tap me for first screen"
onPress={() => navigation.goBack()}
/>
);
};
8 changes: 8 additions & 0 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ - (void)notifyTransitionProgress:(double)progress closing:(BOOL)closing goingFor
#endif
}

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
- (void)presentationControllerDidAttemptToDismiss:(UIPresentationController *)presentationController
{
[self notifyGestureCancel];
}
#endif

- (void)presentationControllerWillDismiss:(UIPresentationController *)presentationController
{
// We need to call both "cancel" and "reset" here because RN's gesture recognizer
Expand Down

0 comments on commit 1a54e22

Please sign in to comment.