Skip to content

Commit c719481

Browse files
fix(android): a screen leaving with animation none disappears at once
`none` keeps the leaving screen for a 20ms no-op tween so the transition events still fire, and Android draws a leaving view above the entering one until its tween ends. For a frame or two the old screen covered the new one: on push, the previous screen over the new page, and on pop, the popped screen over the one returning. ScreenStack now draws such screens through an empty clip while a `none` transition is in effect. They are still drawn, so the tween advances and the transition finishes as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3c7c3b1 commit c719481

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎android/src/main/java/com/swmansion/rnscreens/legacy/ScreenStack.kt‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class ScreenStack(
3333
private var childrenDrawingOrderStrategy: ChildrenDrawingOrderStrategy? = null
3434
private var disappearingTransitioningChildren: MutableList<View> = ArrayList()
3535

36+
// Android draws a leaving screen above the entering one until its tween ends. With no animation
37+
// that tween is only a 20ms no-op kept for the transition events, so the screen is clipped out.
38+
private var hidesDisappearingScreens = false
39+
3640
var goingForward = false
3741

3842
/**
@@ -256,6 +260,7 @@ class ScreenStack(
256260
createTransaction().let { transaction ->
257261
if (stackAnimation != null) {
258262
transaction.setTweenAnimations(stackAnimation, shouldUseOpenAnimation)
263+
hidesDisappearingScreens = stackAnimation === Screen.StackAnimation.NONE
259264
}
260265

261266
// Remove all screens that are currently on stack, but should be dismissed, because they're
@@ -420,7 +425,16 @@ class ScreenStack(
420425
private fun performDraw(op: DrawingOp) {
421426
// Canvas parameter can not be null here https://developer.android.com/reference/android/view/ViewGroup#drawChild(android.graphics.Canvas,%20android.view.View,%20long)
422427
// So if we are passing null here, we would crash anyway
423-
super.drawChild(op.canvas!!, op.child, op.drawingTime)
428+
val canvas = op.canvas!!
429+
if (hidesDisappearingScreens && disappearingTransitioningChildren.contains(op.child)) {
430+
// Still drawn, so its tween advances and ends the transition.
431+
canvas.save()
432+
canvas.clipRect(0, 0, 0, 0)
433+
super.drawChild(canvas, op.child, op.drawingTime)
434+
canvas.restore()
435+
return
436+
}
437+
super.drawChild(canvas, op.child, op.drawingTime)
424438
}
425439

426440
// Can't use `drawingOpPool.removeLast` here due to issues with static name resolution in Android SDK 35+.

0 commit comments

Comments
 (0)