react-native: Modal make iOS app freeze when visible
Description
I faced this for from react native version 0.65 till now. Open a modal then close it make app freeze on both actual iOS device and simulator. When I install to new simulator or new ios device, it’s fine to oepn modal on first time, but when reopen app, It makes app freeze again.
Version
0.66.1
Output of react-native info
OS: macOS 11.2.3 CPU: (12) x64 Intel® Core™ i5-10400 CPU @ 2.90GHz Memory: 49.63 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.11 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: Not Found IDEs: Android Studio: Not Found Xcode: 12.4/12D4e - /usr/bin/xcodebuild Languages: Java: 11.0.11 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.66.1 => 0.66.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
Open a modal then close it make app freeze on both actual iOS device and simulator, sometime can tap to view inside modal, sometime not, app is freeze. Also when modal was closed, it still make app freeze
Snack, code example, screenshot, or link to a repository
No response
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 14
- Comments: 42 (1 by maintainers)
I am also facing the same issue.
For now, the only work around I see here is, if platform is iOS then set modal’s visibility flag after some finite delay, say 1000ms, using setTimeout else simply set modal’s visibility without any delay.
In my use case, I am using react-navigation 4x, react-native-reanimated v1.x on react-native 0.64.x. I was trying to show modal as soon as my parent component is mounted based on some conditions and it was react-navigation’s transition animations conflicting the Modal animations causing my app to freeze.
Refer to the following code snippet and see if it helps.
PS: I know this is a dirty workaround, if anybody found/finds a solution please quote a reply with it.
1.- downgrading react-native-reanimated to
2.2.32.-cd ios && pod deintegrate3.-pod installthis solved my problem
I have experienced this issue as well with
react-native@0.66.2andreact-native-reanimated@1.9.0. Unfortunately, upgrading toreact-native-reanimated@2.2.3did not resolve the issue for me.From my testing, my particular issue comes from usage of
LayoutAnimationwithin my code. Related to https://github.com/facebook/react-native/issues/16182#issuecomment-333814201 and https://github.com/facebook/react-native/issues/16895, if aLayoutAnimationis not consumed, then it can cause RN modals to remain invisibly open even after closing one: https://github.com/facebook/react-native/issues/32329. I have been able to resolve some of the frozen modals within my app by limiting whenLayoutAnimationis used in the app to avoid multiplesLayoutAnimation.configureNextinvocations occurring at the same time.I am unsure why upgrading RN from 0.64 to 0.66 caused the invisible modal issue to become more prominent for my app.
i faced this issue on expo SDK 47 while using Modal from ‘react-native’ (0.70.2), sadly nothing above has worked for me, i ended up using
presentationStyle="fullScreen". Not the solution i wished to fined 😦I faced this issue today with a component getting a function among its props and containing a Modal, like this:
<Parent> <Modal visible={stateBooleanVar}> <FancyComponent callbackYes={() => doStuffAndCloseModalSettingStateBooleanVarToFalse() callbackNo={() => doLessStuffAndCloseModalSettingStateBooleanVarToFalse()}} /> </Modal> </Parent>On an old iPhone 7 running iOS 15.7.9 the app was freezing. On an iPhone 15 pro running iOS 18.2.1 the app was closing the modal, opening it for an instant and closing it again. I just let here a couple of facts and solutions that worked for me. I did some tries digging in React Native docs https://reactnative.dev/docs/modal#props like settinganimationTypetononeand setting explicitlyonDismissto the same callback I was using to close the modal but it didn’t workWhat worked for me was setting this https://reactnative.dev/docs/modal#presentationstyle-ios to
overFullScreenAlso, I found a post in SO saying that using
onPressOutinstead ofonPressresolves the issue and it does! https://stackoverflow.com/questions/69671852/dismiss-react-native-modal-cause-ui-freeze/79358670#79358670 But I don’t understand why, does anyone know the reason?Just trying to solve this ourselves and see other related issues that aren’t linked here yet for the curious:
Still an issue on “react-native-reanimated”: “2.2.4” and “react-native”: “0.66.3”
Temporarily fix for me was to change Reanimated 2.3.0@beta_1 to Reanimated 2.2.4. Further reading with similar problem (crash instead of freeze): https://githubmemory.com/repo/react-native-modal/react-native-modal/issues/615. I noticed that if i used react natives Modal component it crashed, and when i used the react-native-modal packgage it freezed the screen after close.
My dependencies: “react-native”: “0.66.0”, “react-native-modal”: “^13.0.0”,