Repository navigation
fix: prevent scrim opacity dip when detents resize mid-settle - #139
Open
DorianMazur wants to merge 1 commit into
Open
DorianMazur wants to merge 1 commit into
DorianMazur wants to merge 1 commit into
Conversation
DorianMazur
force-pushed
the
fix/prevent-scrim-dip-during-active-settle
branch
from
November 26, 2026 14:15
29129bd to
136179c
Compare
This branch has not been deployed
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.
Summary
Fixes a visual blink where the modal scrim momentarily dips toward transparent and then dims back up when detents resize while a settle spring is active (or when the host height shrinks while settled at an open detent).
Root cause
BottomSheetHostingView+Detents.swift,Detents.kt,controller.ts):wasScrimFullonly setsscrimPinnedFull = trueonce the sheet is within0.5ptoffirstOpenDetentPosition.'content'detent grows while a settle spring is still running—for example, when content expands during theanimateInopen spring or shortly after a drag-release snap-back—the sheet re-anchors at its unchangedvisibleHeightagainst the larger resolved detent height.scrimOpacity(forPosition: visibleHeight)divides that unchangedvisibleHeightby the new larger detent height, causing an immediate opacity drop (e.g.0.67 → 0.20in one frame) before the re-anchored spring climbs back up.wasScrimFull(iOS & Android):BottomSheetHostingView+Detents.swift) and Android (Detents.kt) checkedcurrentSheetHeight + 0.5 >= firstOpenDetentPosition, which subtracts the oldtranslationY(anchored topreviousMaxHeight) from the new container height. When the host shrinks (e.g., keyboard or layout resize),currentSheetHeightunder-reports by the height delta and can falsely evaluatewasScrimFull = false. Web (controller.ts) already usedpreviousHostHeight - currentTranslateY.Changes
ios/HostingView/), Android (android/.../host/), and Web (src/web/):wasScrimFullfrompreviousMaxHeight - currentTranslationYon iOS and Android (matching Web).scrimOpacityFlooracross detent resizes while a modal sheet is not panning and not alreadyscrimPinnedFull, capturing the pre-resize scrim opacity atpreviousVisibleHeight.scrimPinnedFull, takemax(scrimOpacity(position), min(scrimOpacityFloor, targetOpacity))so:targetOpacityensures closing (targetOpacity = 0), lowering to a lighter detent (e.g.1.0 → 0.5), or reducingscrimOpacitiesat runtime is never held above its destination opacity.scrimOpacityFloorin every lifecycle path that clearsscrimPinnedFull: drag start / scroll-handoff start, non-reanchorsnapToIndex, spring completion, settled non-animated detent updates, and view teardown/recycling (resetSheetState/destroy).android/src/test/java/com/swmansion/reactnativebottomsheet/BottomSheetViewScrimDismissTest.ktcovering mid-settle detent growth (including floor clearing on close) and host-height shrinking while settled at an open detent.src/__tests__/scrim.test.tscoveringscrimOpacityFloorpreservation and target-opacity capping.Verification
ios/HostingView/*.swiftfiles against iPhone Simulator SDK and executed a liveBottomSheetHostingViewharness on iPhone 17 simulator covering:100pt → 500pt, opacity held at0.478with zero dip)alpha = 0.0)900pt → 500pt) keepingwasScrimFull/scrimPinnedFulltrue600pt → 300pt,[0, 0.5, 1]) capping floor at0.5and clearing on settleresetSheetStateclearingscrimOpacityFloorsrc/web/*,src/__tests__/scrim.test.ts).bun run lint,bun run typecheck,bun run test, Android unit & instrumented tests) will run on this PR.