Skip to content

Commit

Permalink
fix(Android): fix sheet transition when there is no dimming applied (#…
Browse files Browse the repository at this point in the history
…2723)

## Description

Shout out to @kligarski for spotting this out!

I've introduced a regression in 4.7.0 when refactoring sheet animation -
basically it always animated to the resolved `maxAlpha`
for given sheet dimming view & did not take into account
`sheetLargestUndimmedDetentIndex` prop, effectively disabling this prop.

This affects both architectures.

## Changes

When configuring enter animation we now take the prop into account.

## Test code and steps to reproduce

`TestFormSheet`

## Checklist

- [x] Included code example that can be used to test this change
- [ ] Ensured that CI passes
  • Loading branch information
kkafar authored Feb 20, 2025
1 parent 8bc0cc2 commit 1540218
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,14 @@ class ScreenStackFragment :
}

val animatorSet = AnimatorSet()
val dimmingDelegate = dimmingDelegate.value

if (enter) {
val alphaAnimator =
ValueAnimator.ofFloat(0f, dimmingDelegate.value.maxAlpha).apply {
ValueAnimator.ofFloat(0f, dimmingDelegate.maxAlpha).apply {
addUpdateListener { anim ->
val animatedValue = anim.animatedValue as? Float
animatedValue?.let { dimmingDelegate.value.dimmingView.alpha = it }
animatedValue?.let { dimmingDelegate.dimmingView.alpha = it }
}
}
val startValueCallback = { initialStartValue: Number? -> screen.height.toFloat() }
Expand All @@ -349,13 +350,21 @@ class ScreenStackFragment :
animatedValue?.let { screen.translationY = it }
}
}
animatorSet.play(alphaAnimator).with(slideAnimator)

animatorSet
.play(slideAnimator)
.takeIf {
dimmingDelegate.willDimForDetentIndex(
screen,
screen.sheetInitialDetentIndex,
)
}?.with(alphaAnimator)
} else {
val alphaAnimator =
ValueAnimator.ofFloat(dimmingDelegate.value.dimmingView.alpha, 0f).apply {
ValueAnimator.ofFloat(dimmingDelegate.dimmingView.alpha, 0f).apply {
addUpdateListener { anim ->
val animatedValue = anim.animatedValue as? Float
animatedValue?.let { dimmingDelegate.value.dimmingView.alpha = it }
animatedValue?.let { dimmingDelegate.dimmingView.alpha = it }
}
}
val slideAnimator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DimmingViewManager(
root: ViewGroup,
) {
root.addView(dimmingView, 0)
if (screen.sheetInitialDetentIndex <= screen.sheetLargestUndimmedDetentIndex) {
if (!willDimForDetentIndex(screen, screen.sheetInitialDetentIndex)) {
dimmingView.alpha = 0.0f
} else {
dimmingView.alpha = maxAlpha
Expand All @@ -45,6 +45,11 @@ class DimmingViewManager(
behavior.addBottomSheetCallback(requireBottomSheetCallback(screen))
}

/**
* Ask the manager whether it will apply non-zero alpha for sheet at given detent index.
*/
fun willDimForDetentIndex(screen: Screen, index: Int) = index > screen.sheetLargestUndimmedDetentIndex

/**
* This bottom sheet callback is responsible for animating alpha of the dimming view.
*/
Expand Down
5 changes: 3 additions & 2 deletions apps/src/tests/TestFormSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ export default function App() {
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="FormSheet" component={FormSheet} options={{
presentation: 'formSheet',
//sheetAllowedDetents: [0.4, 0.75, 1.0],
sheetAllowedDetents: 'fitToContents',
sheetAllowedDetents: [0.4, 0.75, 0.9],
//sheetAllowedDetents: 'fitToContents',
sheetLargestUndimmedDetentIndex: 1,
sheetCornerRadius: 8,
headerShown: false,
contentStyle: {
Expand Down

0 comments on commit 1540218

Please sign in to comment.