@@ -7,6 +7,7 @@ import androidx.compose.runtime.key
7
7
import androidx.compose.runtime.remember
8
8
import androidx.compose.runtime.saveable.SaveableStateHolder
9
9
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
10
+ import androidx.compose.ui.layout.SubcomposeLayout
10
11
11
12
@Composable internal fun <T > rememberSaveableScreenStateHolder (): SaveableScreenStateHolder <T > {
12
13
val stateHolder = rememberSaveableStateHolder()
@@ -62,7 +63,9 @@ internal class SaveableScreenStateHolder<T>(private val holder: SaveableStateHol
62
63
// composed again. We have to use the compose-generated int stateKey, even though this function
63
64
// accepts Any, because it doesn't _actually_ accept Any – it only accepts values that are
64
65
// saveable, and the backstack item may not be saveable.
65
- holder.SaveableStateProvider (stateKey, content)
66
+ holder.SaveableStateProvider (stateKey) {
67
+ WorkaroundComposeStateBug (content)
68
+ }
66
69
}
67
70
68
71
/* *
@@ -82,4 +85,18 @@ internal class SaveableScreenStateHolder<T>(private val holder: SaveableStateHol
82
85
}
83
86
}
84
87
}
88
+
89
+ /* *
90
+ * TODO Remove this when the bug is fixed.
91
+ * See https://issuetracker.google.com/issues/188567661#comment2.
92
+ */
93
+ @Composable private fun WorkaroundComposeStateBug (content : @Composable () -> Unit ) {
94
+ SubcomposeLayout { constraints ->
95
+ val measurable = subcompose(Unit , content).single()
96
+ val placeable = measurable.measure(constraints)
97
+ layout(placeable.width, placeable.height) {
98
+ placeable.placeRelative(0 , 0 )
99
+ }
100
+ }
101
+ }
85
102
}
0 commit comments