Skip to content

fix(android): preserve pager content during screen exit transitions - #1145

Closed
roitium wants to merge 2 commits into
callstack:mainfrom
roitium:fix/dispose-before-animation-done
Closed

roitium wants to merge 2 commits into
callstack:mainfrom
roitium:fix/dispose-before-animation-done

Conversation

@roitium

@roitium roitium commented Sep 13, 2026 •

Copy link
Copy Markdown

Summary

On Android, navigating back from a native-stack screen containing PagerView can make the pager content disappear before the screen's exit animation finishes. The screen background and views outside the pager remain visible while the pager becomes blank.

React Native removes the pager's children and calls onDropViewInstance while react-native-screens is still retaining the native view hierarchy for the exit transition. Updating the Compose page list and destroying the composition at that point clears the content too early.

This change:

  • Retains the displayed page views during startViewTransition, while keeping React Native's logical child list up to date.
  • Defers composition disposal until endViewTransition, with window detachment as a cleanup fallback.
  • Preserves immediate page removal outside a transition.
  • Stops dispatching pager events after the React Native view has been dropped.

This affects only the Android Compose implementation.

Test Plan

  • The fix was manually verified in my Android app.

Before this fix: https://github.com/user-attachments/assets/3ab80ccc-efda-4c53-a2ee-511e689dd4fe
After this fix: https://github.com/user-attachments/assets/4a8aaa55-cf4d-407f-8621-d6d7c9ab47e9

What's required for testing (prerequisites)?

  • Android with react-native-pager-view after v9.0.3

What are the steps to reproduce (after prerequisites)?

  1. Navigate to a screen containing a PagerView.
  2. Navigate back and observe the screen's exit animation.

Compatibility

OS Implemented
iOS unchanged
Android ✅

Checklist

  • I have tested this on a device and a simulator

@roitium

roitium commented Sep 14, 2026 •

Copy link
Copy Markdown
Author

This fix introduced a new crash: java.lang.IllegalStateException: Cannot remove child at index 8 from parent ViewGroup [5178], only 9 children in parent. Warning: childCount may be incorrect!

I will try to fix it again.

@roitium

roitium commented Sep 14, 2026

Copy link
Copy Markdown
Author

fixed.

@troZee troZee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix only works because a private recursion in react-native-screens (startTransitionRecursive) happens to call startViewTransition on this exact view. Other navigators, or a future screens version, won't do that, and the blank-content bug would come back.

Please think more about a general fix instead of fixing something in one place

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Native transition and Compose lifecycle ordering require final Android device-level review.

0 open findings

What changed in this PR

Preserves Android Compose pager content until native-stack screen exit animations finish.

Changes:

  • Retains displayed pages while updating React Native’s logical children.
  • Defers composition disposal until transition completion, with detachment cleanup.
  • Suppresses pager events after the view is dropped.
File Description
android/​src/​main/​java/​com/​reactnativepagerview/​ComposePagerView.kt Adds transition-aware page retention, deferred disposal, and event guards.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@troZee

troZee commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

@roitium
Could you take a look on this PR #1180 ?

@roitium

roitium commented Oct 15, 2026

Copy link
Copy Markdown
Author

I tested your pr, it works. I will close this pr. Thanks for your work!

@roitium roitium closed this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants