Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS can't dismiss Modal! #29319

Open
mrousavy opened this issue Jul 9, 2020 · 19 comments · May be fixed by #47398
Open

iOS can't dismiss Modal! #29319

mrousavy opened this issue Jul 9, 2020 · 19 comments · May be fixed by #47398
Labels
Component: Modal Never gets stale Prevent those issues and PRs from getting stale Platform: iOS iOS applications. Resolution: PR Submitted A pull request with a fix has been provided.

Comments

@mrousavy
Copy link
Contributor

mrousavy commented Jul 9, 2020

Description

On iOS the <Modal> component cannot be dismissed by dragging down. (gesture is a native behaviour on iOS)

The reason for that being is that the onDismiss or onRequestClose function is never called. It is only being called on tvOS.

React Native version:

info Fetching system and libraries information...
(node:10129) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
System:
    OS: macOS 10.15.5
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 2.78 GB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.4.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.5 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 25, 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.0, 30.0.0
      System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: 21.2.6472646
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_252 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.0 => 0.63.0 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Create <Modal> component and set visible and onRequestClose properties
  2. Open Modal by setting visible to true
  3. Try to close Modal by dragging down

Expected Results

Modal should be dragged down and onDismiss or onRequestClose should be called

Snack, code example, screenshot, or link to a repository:

<Modal
  presentationStyle="pageSheet"
  visible={true}
  onRequestClose={() => console.log("will never be called.")} />

Screen Recording 2020-07-09 at 13 40 49 mov

@hsource
Copy link
Contributor

hsource commented Jul 9, 2020

I think you might want to use the react-native-modal package. The React Native team I think has tried to keep the included Modal component fairly basic. The other package expands on that with a lot of functionality.

@alexandersandberg
Copy link

The possibility to swipe to dismiss modals was removed in 0.63 due to problems with it.

It was broken and needed hacks to function properly, but sad that it was removed. 😕

@avbeladiya
Copy link

after updating react native from 0.62 to 0.63 , my modal component closes on onRequestClose method but after that every click/touch on screen fails, seems like modal is still open in background.
even after app reload its doesnt work.
every time requires new build.

i checked with react-native-modal , react-native-translucent-modal , it behaves same.

@aminta
Copy link

aminta commented Jul 27, 2020

after updating react native from 0.62 to 0.63 , my modal component closes on onRequestClose method but after that every click/touch on screen fails, seems like modal is still open in background.
even after app reload its doesnt work.
every time requires new build.

i checked with react-native-modal , react-native-translucent-modal , it behaves same.

Yes, same bug there and no solution so far: react-native-modal/react-native-modal#447

@xavierroma
Copy link

Same issue, pageSheet Modal cannot be dismissed on swipe down

@xhirazi
Copy link

xhirazi commented Sep 24, 2020

+1

@pritamsoni-hsr
Copy link

a workaround for this is in when you are setting visible state to true on press of a button, check if it is false initially and if so, toggle it twice (one with a timeout). There is one pending PR for this. so you can make those changes in native code when compiling with Xcode.

@Benjamaker
Copy link

managed to implement a working solution using react-native-modal with both scrollable contents and swipe-to-dismiss functionality. I recommend looking at the ScrollableModal example in the react-native-modal examples repo: https://github.com/react-native-modal/react-native-modal/blob/master/example/src/modals/ScrollableModal.tsx

@satya164
Copy link
Contributor

Just had an idea to wrap the modal in a navigator which seem to work fine except for pageSheet/formSheet modals because of the issue. If it worked, we'd have a native modal style navigator without any extra libraries.

https://github.com/satya164/react-navigation-native-modal#readme

@alexandersandberg
Copy link

alexandersandberg commented Nov 23, 2020

Not a solution to this issue, but a perfectly working alternative for some:

React Navigation's createNativeStackNavigator with a stackPresentation set to modal, formSheet, or whatever you prefer.

Edit: Some more information on how to implement a modal like this can be found in the React Navigation docs: Opening a full-screen modal.

@r0b0t3d
Copy link

r0b0t3d commented Nov 30, 2020

This patch works for me react-native+0.63.3.patch

@rusliabdulgani
Copy link

Hi all, how about this issue, i still find this issue on RN. 0.63.4

@aakagi
Copy link

aakagi commented Mar 4, 2021

Implemented the solution suggested by @alexandersandberg and it works!

Combine
https://reactnavigation.org/docs/modal
with
https://stackoverflow.com/questions/62283000/is-it-possible-to-present-modals-with-the-uimodalpresentationpagesheet-or-uimoda

Here's my code. You should be able to paste this in and have it work (assuming you have the correct dependencies)

import React from 'react'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'

import {
  View,
  Text,
  Button
} from 'react-native'

import { createNativeStackNavigator } from 'react-native-screens/native-stack'
import { enableScreens } from 'react-native-screens'

enableScreens()

const MainStack = createStackNavigator()
const RootStack = createNativeStackNavigator()

function HomeScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text style={{ fontSize: 30 }}>This is the home screen!</Text>
      <Button
        onPress={() => navigation.navigate('MyModal')}
        title="Open Modal"
      />
    </View>
  )
}

function DetailsScreen() {
  return (
    <View>
      <Text>Details</Text>
    </View>
  )
}

function MainStackScreen() {
  return (
    <MainStack.Navigator>
      <MainStack.Screen name="Home" component={HomeScreen} />
      <MainStack.Screen name="Details" component={DetailsScreen} />
    </MainStack.Navigator>
  )
}

function ModalScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text style={{ fontSize: 30 }}>This is a modal!</Text>
      <Button onPress={() => navigation.goBack()} title="Dismiss" />
    </View>
  )
}

// We use React Navigation's modal to be able to use swipeable native modals
function RootStackScreen() {
  return (
    <RootStack.Navigator
      mode="modal"
      screenOptions={{
        headerShown: false,
        stackPresentation: 'formSheet'
      }}
    >
      <RootStack.Screen
        name="Main"
        component={MainStackScreen}
        options={{ headerShown: false }}
      />
      <RootStack.Screen
        name="MyModal"
        component={ModalScreen}
      />
    </RootStack.Navigator>
  )
}

export default function AppNavigator() {
  return (
    <NavigationContainer>
      <RootStackScreen />
    </NavigationContainer>
  )
}

@ghivert
Copy link

ghivert commented Mar 15, 2021

Hi, is someone able to dismiss the modal with React Native 0.64? I upgraded, and this is not working for me…

I just tried with a brand new project and it’s not working. Here’s my example code:

import React, {useState} from 'react';
import {SafeAreaView, StatusBar, Text, Modal, Button} from 'react-native';

const App = () => {
  const [visible, setVisible] = useState(false);

  return (
    <SafeAreaView>
      <StatusBar barStyle="light-content" />
      <Button title="Open" onPress={() => setVisible(true)} />
      <Modal
        visible={visible}
        presentationStyle="pageSheet"
        animationType="slide"
        onRequestClose={() => {
          console.log('close');
          setVisible(false);
        }}
        onDismiss={() => {
          console.log('dismiss');
          setVisible(false);
        }}>
        <Text>Modal</Text>
      </Modal>
    </SafeAreaView>
  );
};

export default App;

Unfortunately, neither function is firing. Is there anything I missed? Everything is fine in react-native doctor, and I started the new project with react-native globally installed:

yarn global add react-native
react-native init ExampleProject

Then just changed the App.js.

facebook-github-bot pushed a commit that referenced this issue Aug 16, 2021
Summary:
This PR aims to resolve iOS can't dismiss Modal on swipe gesture.
#29319

When modal presentationStyle is pageSheet, iOS allows to dismiss the modal using swipe gesture. This PR adds support for that feature
## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Added] - Support for onRequestClose for iOS Modal component.

Pull Request resolved: #31500

Test Plan:
- If onRequestClose updates the visibility state, modal will be closed.

```
<Modal
    visible={visible}
    animationType="slide"
    presentationStyle="pageSheet"
    onRequestClose={dismiss}>
</Modal>
```

https://user-images.githubusercontent.com/23293248/117590263-36cd7f00-b14c-11eb-940c-86e700c0b8e7.mov

## Notes
- In this PR, only support for partial drag is added. i.e. user can't drag the modal up and down completely. I added full user dragging but reverted in this [commit](bb65b9a) to support controllable onRequestClose. If someone has any suggestion to have full draggable support + controllable onRequestClose, please let me know.

<!--

 the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. -->

Reviewed By: p-sun

Differential Revision: D30041625

Pulled By: sammy-SC

fbshipit-source-id: 9675da760bd5c070c4f0e1d30271c8af5c50b998
@lucis
Copy link

lucis commented Jan 7, 2022

I was having a similar issue (modals would stick in the app and pretty much freeze the application) and was able to fix it with this change. Use yarn patch-package to do so.

@vbylen
Copy link

vbylen commented Jan 28, 2022

@ghivert nope, I can't get onRequestClose to fire.

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label May 29, 2023
@github-actions
Copy link

github-actions bot commented Jun 5, 2023

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as completed Jun 5, 2023
@satya164 satya164 reopened this Jun 5, 2023
@satya164 satya164 removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 5, 2023
@cortinico cortinico added the Never gets stale Prevent those issues and PRs from getting stale label Jun 5, 2023
@ainnotate
Copy link

Any updates on this issue? I'm on 0.72 and I still see the issue.

@mateoguzmana mateoguzmana linked a pull request Nov 5, 2024 that will close this issue
@migueldaipre migueldaipre added Resolution: PR Submitted A pull request with a fix has been provided. and removed Needs: Triage 🔍 labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Modal Never gets stale Prevent those issues and PRs from getting stale Platform: iOS iOS applications. Resolution: PR Submitted A pull request with a fix has been provided.
Projects
None yet
Development

Successfully merging a pull request may close this issue.