Skip to content

Commit e99a726

Browse files
fix(android): lay out screens after the mount's changes, not during them
t3.28 applied pending screen changes as soon as a Fabric mount resized the container, so a leaving screen was never resized. That attached the new screen partway through the mount, before the rest of the mount had set up its views. Compose content in it (a top app bar) composed early and was redrawn a frame later, so its title appeared after the page. The container now defers laying out its screens while a resize and a screen change are pending, and lays them out once the change is applied when the mount finishes. The leaving screen still keeps its size, and new screens attach after the whole mount. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cd2a327 commit e99a726

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ open class ScreenContainer(
3434
protected var fragmentManager: FragmentManager? = null
3535
private var isAttached = false
3636
private var needsUpdate = false
37+
private var hasDeferredChildLayout = false
3738
private var isLayoutEnqueued = false
3839
private val layoutCallback: Choreographer.FrameCallback =
3940
object : Choreographer.FrameCallback {
@@ -73,10 +74,18 @@ open class ScreenContainer(
7374
r: Int,
7475
b: Int,
7576
) {
76-
// A Fabric mount resizes the container before its screen changes are applied. Applying them
77-
// first means a screen leaving in that mount is not resized, so its content keeps the size
78-
// it was laid out at and fits at once if it comes back. Never inside a layout pass.
79-
if (changed && !isInLayout) performUpdates()
77+
// A Fabric mount resizes the container before it applies the mount's screen changes, which
78+
// happens when the mount finishes. Laying out the screens waits for them, so a screen leaving
79+
// in that mount is not resized and fits at once if it comes back.
80+
if (changed && needsUpdate && !isInLayout) {
81+
hasDeferredChildLayout = true
82+
return
83+
}
84+
layoutChildren()
85+
}
86+
87+
private fun layoutChildren() {
88+
hasDeferredChildLayout = false
8089
var i = 0
8190
val size = childCount
8291
while (i < size) {
@@ -413,11 +422,13 @@ open class ScreenContainer(
413422

414423
fun performUpdates() {
415424
if (!needsUpdate || !isAttached || fragmentManager == null || fragmentManager?.isDestroyed == true) {
425+
if (hasDeferredChildLayout) layoutChildren()
416426
return
417427
}
418428
needsUpdate = false
419429
onUpdate()
420430
notifyContainerUpdate()
431+
if (hasDeferredChildLayout) layoutChildren()
421432
}
422433

423434
open fun onUpdate() {

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-screens",
3-
"version": "5.0.0-t3.28",
3+
"version": "5.0.0-t3.29",
44
"description": "Native navigation primitives for your React Native app.",
55
"scripts": {
66
"submodules": "git submodule update --init --recursive && (cd react-navigation && yarn && yarn build && cd ../)",

0 commit comments

Comments
 (0)