Skip to content

fix(android): fix crash on pager unmount #1001

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

Merged
merged 1 commit into from
May 20, 2025
Merged

Conversation

krozniata
Copy link
Member

Summary

This PR fixes issue with crashing on android when leaving screen using native stack

Root cause of that crash was that component tried to call queued refreshViewChildrenLayout on unmounted views - when leaving screen all of pages were firstly being unmounted and then refreshViewChildrenLayout method was called

Fixes #946 #859

Test Plan

  1. Open example app on android with native stack
  2. Go to any example
  3. Go back to example list
  4. App shouldn't crash

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an Android crash on pager unmount by preventing calls to refreshViewChildrenLayout on unmounted views.

  • Updated the import paths in OnPageScrollExample.tsx to use react-native instead of react-native-gesture-handler.
  • Changed the default mode in App.tsx from 'js' to 'native'.
  • Introduced a debounced refresh mechanism in PagerViewViewManagerImpl.kt to prevent refresh calls on unmounted pagers.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
example/src/OnPageScrollExample.tsx Updated import statements to replace gesture-handler with react-native components
example/src/App.tsx Changed default navigation mode to native to mitigate the crash issue
android/src/main/java/com/reactnativepagerview/PagerViewViewManagerImpl.kt Replaced direct refreshViewChildrenLayout call with a debounced version using Choreographer
Comments suppressed due to low confidence (1)

example/src/OnPageScrollExample.tsx:2

  • Please verify that replacing the react-native-gesture-handler imports with those from react-native maintains the intended behavior for gesture handling in this component.
import { StyleSheet, Text, View, SafeAreaView, Animated, ScrollView, TouchableOpacity } from 'react-native';

Copy link
Collaborator

@MrRefactor MrRefactor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, will include that in next release

@MrRefactor MrRefactor merged commit 5ac4b7e into master May 20, 2025
2 checks passed
@MrRefactor MrRefactor deleted the fix/android-crash branch May 20, 2025 08:55
rivenintech added a commit to rivenintech/WatchVault that referenced this pull request May 30, 2025
Bump react-native-pager-view to resolve the back navigation crash: callstack/react-native-pager-view#1001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] App crashes on navigating out of the screen with Pager
2 participants