Skip to content

Conversation

@lodev09
Copy link
Owner

@lodev09 lodev09 commented Jan 12, 2026

Summary

Replaces RNSLifecycleListenerProtocol with a C++ EventDispatcher-based solution for detecting when a presenting screen unmounts while a sheet is presented.

Context: react-native-screens maintainers want to avoid component-specific integrations. See: software-mansion/react-native-screens#3527 (review)

How it works

  1. Pass the C++ EventDispatcher through state via ComponentDescriptor::adopt()
  2. Create RNScreensEventObserver to listen for topWillDisappear events
  3. At presentation time, capture presenter screen info (_presenterScreenTag, _presenterScreenController)
  4. When topWillDisappear fires, check if the screen is no longer the top view controller (pushed or popped)
  5. Modal dismisses are handled naturally by the modal itself - no special handling needed

Files changed

C++ (iOS-only):

  • TrueSheetViewState - Added eventDispatcher_ member
  • TrueSheetViewShadowNode - Added setEventDispatcher()
  • TrueSheetViewComponentDescriptor - Passes dispatcher in adopt()

iOS:

  • RNScreensEventObserver - New observer class for screen lifecycle events
  • TrueSheetView.mm - Integrates observer, typed delegate for direct window access
  • Removed _parentModalTag tracking - simplified detection using topViewController check

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Test Plan

  • Present sheet from a screen in a navigation stack
  • Navigate back (pop) - sheet should dismiss
  • Push new screen - sheet should dismiss
  • Present sheet from a screen inside a modal
  • Dismiss modal - sheet should be dismissed by modal
  • Navigate back inside modal - sheet should dismiss

Checklist

  • I tested on iOS
  • I tested on Android
  • I tested on Web
  • I updated the documentation (if needed)
  • I added a changelog entry (if needed)

- Pass EventDispatcher from ComponentDescriptor through State to native view
- Listen for topWillDisappear events to detect when presenter screen unmounts
- Capture presenter screen tag and controller at presentation time
- Distinguish navigation pop from modal dismiss by checking nav stack
- Dismiss sheet when its presenter screen is being popped

This replaces RNSLifecycleListenerProtocol per react-native-screens feedback.
See: software-mansion/react-native-screens#3527
@vercel
Copy link

vercel bot commented Jan 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
react-native-true-sheet Ready Ready Preview, Comment Jan 12, 2026 9:33pm

@lodev09 lodev09 marked this pull request as ready for review January 12, 2026 21:29
@lodev09 lodev09 merged commit 8de9a4b into main Jan 12, 2026
5 checks passed
@lodev09 lodev09 deleted the refactor/event-dispatcher-screen-detection branch January 12, 2026 21:40
@lodev09
Copy link
Owner Author

lodev09 commented Jan 14, 2026

🚀 This pull request is included in v3.7.4-beta.0. See Release 3.7.4-beta.0 for release notes.

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.

2 participants