Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 474d6d5

Browse files
tmp fix bug
1 parent 6fc11bd commit 474d6d5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

compose-backstack/src/main/java/com/zachklipp/compose/backstack/SaveableScreenStateHolder.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.compose.runtime.key
77
import androidx.compose.runtime.remember
88
import androidx.compose.runtime.saveable.SaveableStateHolder
99
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
10+
import androidx.compose.ui.layout.SubcomposeLayout
1011

1112
@Composable internal fun <T> rememberSaveableScreenStateHolder(): SaveableScreenStateHolder<T> {
1213
val stateHolder = rememberSaveableStateHolder()
@@ -63,7 +64,9 @@ internal class SaveableScreenStateHolder<T>(private val holder: SaveableStateHol
6364
// composed again. We have to use the compose-generated int stateKey, even though this function
6465
// accepts Any, because it doesn't _actually_ accept Any – it only accepts values that are
6566
// saveable, and the backstack item may not be saveable.
66-
holder.SaveableStateProvider(stateKey, content)
67+
holder.SaveableStateProvider(stateKey) {
68+
WorkaroundComposeStateBug(content)
69+
}
6770
}
6871

6972
/**
@@ -85,4 +88,18 @@ internal class SaveableScreenStateHolder<T>(private val holder: SaveableStateHol
8588
}
8689
}
8790
}
91+
92+
/**
93+
* TODO Remove this when the bug is fixed.
94+
* See https://issuetracker.google.com/issues/188567661#comment2.
95+
*/
96+
@Composable private fun WorkaroundComposeStateBug(content: @Composable () -> Unit) {
97+
SubcomposeLayout { constraints ->
98+
val measurable = subcompose(Unit, content).single()
99+
val placeable = measurable.measure(constraints)
100+
layout(placeable.width, placeable.height) {
101+
placeable.placeRelative(0, 0)
102+
}
103+
}
104+
}
88105
}

0 commit comments

Comments
 (0)