react-native-pager-view: [iOS][5.4.2...5.4.6] Crash when rapidly switching pages
Environment
- Example app on master
System:
OS: macOS 11.5
CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory: 655.26 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 12.16.2 - ~/.nvm/versions/node/v12.16.2/bin/node
Yarn: Not Found
npm: 6.14.4 - ~/.nvm/versions/node/v12.16.2/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK:
API Levels: 29, 31
Build Tools: 29.0.3, 31.0.0
System Images: android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7678000
Xcode: 12.5/12E262 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_292 - /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.4 => 0.63.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Description
Application crashes when rapidly switching pages, with the following error: Unexpected view controller: <UIViewController: 0x7f983a539850>
.
As far as I can tell it dates back to version 5.4.2
. Prior to that, this did not happen. It’s surprisingly easy to trigger on a real device.
https://user-images.githubusercontent.com/2244710/135704139-92179925-dcc2-4918-b0a7-f4f7ba8402b8.mov
Reproducible Demo
- Open the example app.
- Remove the
Alert.alert()
call onOnPageSelectedExample.tsx
so you don’t get artificial pauses. - Run, and rapidly switch pages in the corresponding example.
- 💥
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 54 (9 by maintainers)
Commits related to this issue
- Fix wrong variable usage that causes crash related to #458 Introduced in #455 this should have been `i` instead of `index` all along. — committed to danilobuerger/react-native-viewpager by danilobuerger 2 years ago
- fix(ios): wrong variable usage that causes crash related to #458 (#502) Introduced in #455 this should have been `i` instead of `index` all along. — committed to callstack/react-native-pager-view by danilobuerger 2 years ago
- Fix ios (#1) * Update ReactNativePageView.m * chore: add docs for attaching onPageScroll handler with reanimated (#491) * add docs for attaching handler with reanimated * feat: add reanimate... — committed to chuece/react-native-pager-view by chuece 2 years ago
From what I’ve been reading, it’s a bug in UIPageViewController that’s been there since before iOS 8.
In
scroll
mode, it keeps an internal cache of the pages it is transitioning between. If you switch pages while it’s already animating to another, you can end up selecting a page that is not in its cache, leading to the “Unexpected view controller” crash.In
curl
mode it doesn’t do any precaching, but the animation is ugly.From what I’ve gathered some people:
dataSet = nil
and then back to an acceptable state just before transitioning to another view controller);I’m no iOS dev, but I tried to implement every workaround I could find to no avail. I worked around it by:
For those interested, here’s the patch I am using with patch-package and
react-native-pager-view@5.4.6
:I am facing the same issue when using Material-top-tabs.
I’m trying other solutions by counting the number of animation actions. I haven’t tried in production, but it seems ok on debug mode, it can prevent a crash, but sometimes if the animation does not finish yet, then you navigate to other screens it can be a bug. Maybe it can help and someone can improve it. Thx.
https://github.com/callstack/react-native-pager-view/issues/140
New issue with the update. The new update fixed issue with app crashing when switching screens to fast however the new issue is as follow: I am using React Navigation Top Tabs which depends on this library. If I press (onPress) my tabs to fast then the top tabs stop responding. The indicator gets stuck. I can still swipe left or right to get to other screens from the tabs however the tab bar gets stuck. This only happens when I click on 3 or 4 tabs very quickly.
Is there a PR up for this? Instead of using a patch?
Same problem. Even with the patch.
@RZulfikri Also working fine in Production
@troZee I took a stab at implementing your recommended solution 2, please take a look here: https://github.com/callstack/react-native-pager-view/pull/510
For RTL +
NSInternalInconsistencyException: Unexpected view controller
fixreact-native-pager-view+5.4.9.patch
Patch works!
@troZee any news on this issue ? thanks
https://user-images.githubusercontent.com/64275658/154009118-50cbdaeb-00b4-4d01-8549-6d18c54d4d40.mp4
@elmcapp try to read this https://www.callstack.com/blog/say-goodbye-to-old-fashioned-forks-thanks-to-the-patch-package. But in this case, you can do:
same issue…
I adapted @wbercx patch for
react-native-pager-view@5.4.9
:I’m having this issue as well, including on
5.4.1
and5.4.0
.