fix(Android, FormSheet): Add fallbacks for unblocking sheet transition#4053
Open
t0maboro wants to merge 5 commits into
Open
fix(Android, FormSheet): Add fallbacks for unblocking sheet transition#4053t0maboro wants to merge 5 commits into
t0maboro wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Android FormSheet transition fallbacks so postponed enter transitions are unblocked when layout or WindowInsets callbacks are missed in brownfield/API <=34 setups.
Changes:
- Cancels pending bottom-sheet transition fallback work during
onDestroyView. - Adds an immediate “already laid out” path after attaching the layout listener.
- Adds a delayed insets fallback in
BottomSheetTransitionCoordinator.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
android/src/main/java/com/swmansion/rnscreens/ScreenStackFragment.kt |
Wires lifecycle cancellation and immediate layout readiness notification for FormSheet transitions. |
android/src/main/java/com/swmansion/rnscreens/bottomsheet/BottomSheetTransitionCoordinator.kt |
Adds main-thread timeout fallback for missing insets dispatch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Currently, the FormSheet enter transition relies on two signals to start:
WindowInsetsbeing dispatched to the listener attached in ScreenStackFragment.On devices running API 34 and below in brownfield setups, the bottom sheet transition may hang indefinitely. This happens because the
WindowInsetsare consumed higher up in the view hierarchy and never reach our listener.The difference in behavior comes down to how system window insets are handled by the
PhoneWindowandViewRootImplbefore and after edge-to-edge enforcement.On API 34 and below:
During
Activity.onCreatethePhoneWindow.generateLayoutis called for the native hierarchy setup, the default behavior is to fit the content to system windows (mDecorFitsSystemWindows = true).When
DecorViewis attached to the window,applyDecorFitsSystemWindowsattaches a default insets listener (sDefaultContentInsetsApplier) toViewRootImpl.When
ViewRootImpldispatches insets viacomputeSystemWindowInsets, thesDefaultContentInsetsAppliercalculates the required paddings and consumes the insets. As a result, the LinearLayout below the DecorView doesn't propagate insets down to ourScreenContainer.On API 36:
With enforced edge-to-edge,
PhoneWindow.generateLayoutexplicitly setsmDecorFitsSystemWindows = falseunder the hood.Because of this,
applyDecorFitsSystemWindowspassesnulltoViewRootImplinstead of the default applier.In
computeSystemWindowInsets, since the listener isnull, the insets are not consumed and are simply passed down the view hierarchy, successfully reaching ourScreenContainerand unblocking the transition.Proposed Solution:
WindowInsetswill ever reach our view, I'm introducing a fallback mechanism. If the insets are not received within an arbitrary time, I assume they were consumed upstream, and I should trigger the transition. If insets arrive, the fallback is cancelled.OnLayoutChangeListeneronly catches future layout passes. We now check if (isLaidOut && width > 0 && height > 0) immediately after attaching the listener. If the view is already laid out, we manually trigger the onScreenContainerLayoutChanged callback to prevent the coordinator from hanging from this path.Closes: #4010
Changes
Before & after - visual documentation
before.mov
after.mov
Test plan
sheetShouldOverflowTopInsetprop valueChecklist