Skip to content

Commit 7488d94

Browse files
committed
fix(android): fix enter/exit translation value
1 parent 4391058 commit 7488d94

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

android/src/main/java/com/swmansion/rnscreens/ScreenStackFragment.kt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import com.google.android.material.shape.MaterialShapeDrawable
3030
import com.google.android.material.shape.ShapeAppearanceModel
3131
import com.swmansion.rnscreens.bottomsheet.DimmingViewManager
3232
import com.swmansion.rnscreens.bottomsheet.SheetDelegate
33-
import com.swmansion.rnscreens.bottomsheet.isSheetFitToContents
3433
import com.swmansion.rnscreens.bottomsheet.usesFormSheetPresentation
3534
import com.swmansion.rnscreens.events.ScreenAnimationDelegate
3635
import com.swmansion.rnscreens.events.ScreenDismissedEvent
@@ -299,28 +298,29 @@ class ScreenStackFragment :
299298
animatedValue?.let { dimmingDelegate.dimmingView.alpha = it }
300299
}
301300
}
301+
302302
val startValueCallback = { initialStartValue: Number? -> screen.height.toFloat() }
303303
val evaluator = ExternalBoundaryValuesEvaluator(startValueCallback, { 0f })
304304
val slideAnimator =
305305
ValueAnimator.ofObject(evaluator, screen.height.toFloat(), 0f).apply {
306306
addUpdateListener { anim ->
307307
val animatedValue = anim.animatedValue as? Float
308308
animatedValue?.let {
309-
var sheetY = (screen.top + it).toInt()
310-
311-
// Height seems to be different when sheet is not `fitToContents`.
312-
if (!screen.isSheetFitToContents()) {
313-
sheetY = minOf(sheetY, screen.height)
314-
}
315-
316309
screen.translationY = it
317-
screen.onSheetTranslation(sheetY)
318310
}
319311
}
320312
}
321313

314+
val translateAnimator =
315+
ValueAnimator.ofInt(coordinatorLayout.bottom, screen.top).apply {
316+
addUpdateListener { anim ->
317+
screen.onSheetTranslation(anim.animatedValue as Int)
318+
}
319+
}
320+
322321
animatorSet
323322
.play(slideAnimator)
323+
.with(translateAnimator)
324324
.takeIf {
325325
dimmingDelegate.willDimForDetentIndex(
326326
screen,
@@ -335,17 +335,27 @@ class ScreenStackFragment :
335335
animatedValue?.let { dimmingDelegate.dimmingView.alpha = it }
336336
}
337337
}
338+
338339
val slideAnimator =
339340
ValueAnimator.ofFloat(0f, (coordinatorLayout.bottom - screen.top).toFloat()).apply {
340341
addUpdateListener { anim ->
341342
val animatedValue = anim.animatedValue as? Float
342343
animatedValue?.let {
343344
screen.translationY = it
344-
screen.onSheetTranslation(minOf((screen.top + it).toInt(), screen.height))
345345
}
346346
}
347347
}
348-
animatorSet.play(alphaAnimator).with(slideAnimator)
348+
349+
val translateAnimator =
350+
ValueAnimator.ofInt(screen.top, coordinatorLayout.bottom).apply {
351+
addUpdateListener { anim ->
352+
screen.onSheetTranslation(anim.animatedValue as Int)
353+
}
354+
}
355+
animatorSet
356+
.play(alphaAnimator)
357+
.with(slideAnimator)
358+
.with(translateAnimator)
349359
}
350360
animatorSet.addListener(
351361
ScreenAnimationDelegate(

0 commit comments

Comments
 (0)