Skip to content

fix: prevent scrim opacity dip when detents resize mid-settle - #139

Open
DorianMazur wants to merge 1 commit into
software-mansion:mainfrom
DorianMazur:fix/prevent-scrim-dip-during-active-settle
Open

DorianMazur wants to merge 1 commit into
software-mansion:mainfrom
DorianMazur:fix/prevent-scrim-dip-during-active-settle

Conversation

@DorianMazur

Copy link
Copy Markdown

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

  1. Mid-settle detent growth (BottomSheetHostingView+Detents.swift, Detents.kt, controller.ts):
    • wasScrimFull only sets scrimPinnedFull = true once the sheet is within 0.5pt of firstOpenDetentPosition.
    • When an open 'content' detent grows while a settle spring is still running—for example, when content expands during the animateIn open spring or shortly after a drag-release snap-back—the sheet re-anchors at its unchanged visibleHeight against the larger resolved detent height.
    • scrimOpacity(forPosition: visibleHeight) divides that unchanged visibleHeight by the new larger detent height, causing an immediate opacity drop (e.g. 0.67 → 0.20 in one frame) before the re-anchored spring climbs back up.
  2. Host-height shrink in wasScrimFull (iOS & Android):
    • Both iOS (BottomSheetHostingView+Detents.swift) and Android (Detents.kt) checked currentSheetHeight + 0.5 >= firstOpenDetentPosition, which subtracts the old translationY (anchored to previousMaxHeight) from the new container height. When the host shrinks (e.g., keyboard or layout resize), currentSheetHeight under-reports by the height delta and can falsely evaluate wasScrimFull = false. Web (controller.ts) already used previousHostHeight - currentTranslateY.

Changes

  • iOS (ios/HostingView/), Android (android/.../host/), and Web (src/web/):
    • Compute wasScrimFull from previousMaxHeight - currentTranslationY on iOS and Android (matching Web).
    • Track scrimOpacityFloor across detent resizes while a modal sheet is not panning and not already scrimPinnedFull, capturing the pre-resize scrim opacity at previousVisibleHeight.
    • When rendering the scrim without scrimPinnedFull, take max(scrimOpacity(position), min(scrimOpacityFloor, targetOpacity)) so:
      • Opening or expanding toward an open detent never dips below the opacity already on screen.
      • Capping by targetOpacity ensures closing (targetOpacity = 0), lowering to a lighter detent (e.g. 1.0 → 0.5), or reducing scrimOpacities at runtime is never held above its destination opacity.
    • Clear scrimOpacityFloor in every lifecycle path that clears scrimPinnedFull: drag start / scroll-handoff start, non-reanchor snapToIndex, spring completion, settled non-animated detent updates, and view teardown/recycling (resetSheetState / destroy).
  • Tests:
    • Added Robolectric tests in android/src/test/java/com/swmansion/reactnativebottomsheet/BottomSheetViewScrimDismissTest.kt covering mid-settle detent growth (including floor clearing on close) and host-height shrinking while settled at an open detent.
    • Added unit tests in src/__tests__/scrim.test.ts covering scrimOpacityFloor preservation and target-opacity capping.

Verification

  • Compiled all ios/HostingView/*.swift files against iPhone Simulator SDK and executed a live BottomSheetHostingView harness on iPhone 17 simulator covering:
    • mid-open detent growth (100pt → 500pt, opacity held at 0.478 with zero dip)
    • closing snap clearing the floor and hiding scrim (alpha = 0.0)
    • host-height shrink (900pt → 500pt) keeping wasScrimFull / scrimPinnedFull true
    • multi-detent downward snap (600pt → 300pt, [0, 0.5, 1]) capping floor at 0.5 and clearing on settle
    • resetSheetState clearing scrimOpacityFloor
  • Verified Prettier formatting on all changed TypeScript files (src/web/*, src/__tests__/scrim.test.ts).
  • Full CI matrix (bun run lint, bun run typecheck, bun run test, Android unit & instrumented tests) will run on this PR.

@DorianMazur
DorianMazur force-pushed the fix/prevent-scrim-dip-during-active-settle branch from 29129bd to 136179c Compare November 26, 2026 14:15

This branch has not been deployed

No deployments
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.

1 participant