@@ -7,6 +7,7 @@ import androidx.compose.runtime.key
77import androidx.compose.runtime.remember
88import androidx.compose.runtime.saveable.SaveableStateHolder
99import 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