I’m trying to cache an android view and use it acr...
# compose
r
I’m trying to cache an android view and use it across configuration changes but I keep running into an
IllegalStateException
. The android view is a
TextureView
that i’m using for a webRTC call so I don’t want to restart the whole calling process on config changes. I’m handling configChanges manually as follows
Copy code
android:configChanges="orientation|smallestScreenSize|screenSize|screenLayout"
And reusing the Surface as follows ()
Copy code
val context = LocalContext.current


val surface = remember {
    MyTexture(context)
}

LaunchedEffect(Unit){
    // some legacy webrtc code which initialises call and sends frames to the texture view
    callController.initialise(surface)
}

AndroidView(factory = {surface})
The error message says
Pending composition has not been applied
initialising the view in the factory method prevents this exception from getting thrown, but that will mean re-building a new call whenever the user rotates their device. I have 2 options now, re-architect a legacy app to work properly in this situation by removing the dependency on the
TextureView
during call initialisation or find a way to workaround this problem. I’m currently leaning towards the latter. Posting StackTrace in thread…
🧵 1
Copy code
java.lang.IllegalStateException: pending composition has not been applied
                                                                                                    	at androidx.compose.runtime.CompositionImpl.drainPendingModificationsForCompositionLocked(Composition.kt:444)
                                                                                                    	at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:477)
                                                                                                    	at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:748)
                                                                                                    	at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime_release(Composer.kt:2987)
                                                                                                    	at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:433)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState.subcomposeInto(SubcomposeLayout.kt:269)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState.access$subcomposeInto(SubcomposeLayout.kt:154)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:244)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:241)
                                                                                                    	at androidx.compose.runtime.snapshots.SnapshotStateObserver.withNoObservations(SnapshotStateObserver.kt:142)
                                                                                                    	at androidx.compose.ui.node.OwnerSnapshotObserver.withNoSnapshotReadObservation$ui_release(OwnerSnapshotObserver.kt:55)
                                                                                                    	at androidx.compose.ui.node.LayoutNode.withNoSnapshotReadObservation$ui_release(LayoutNode.kt:1175)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:241)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:235)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose$ui_release(SubcomposeLayout.kt:224)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState$Scope.subcompose(SubcomposeLayout.kt:490)
                                                                                                    	at androidx.compose.material.ScaffoldKt$ScaffoldLayout$1$1$1.invoke(Scaffold.kt:314)
                                                                                                    	at androidx.compose.material.ScaffoldKt$ScaffoldLayout$1$1$1.invoke(Scaffold.kt:241)
                                                                                                    	at androidx.compose.ui.layout.MeasureScope$layout$1.placeChildren(MeasureScope.kt:68)
                                                                                                    	at androidx.compose.ui.layout.SubcomposeLayoutState$createMeasurePolicy$1$measure$1.placeChildren(SubcomposeLayout.kt:367)
                                                                                                    	at androidx.compose.ui.node.LayoutNode$layoutChildren$1.invoke(LayoutNode.kt:993)
                                                                                                    	at androidx.compose.ui.node.LayoutNode$layoutChildren$1.invoke(LayoutNode.kt:978)
                                                                                                    	at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:126)
                                                                                                    	at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:88)
                                                                                                    	at androidx.compose.ui.node.OwnerSnapshotObserver.observeLayoutSnapshotReads$ui_release(OwnerSnapshotObserver.kt:62)
                                                                                                    	at androidx.compose.ui.node.LayoutNode.layoutChildren$ui_release(LayoutNode.kt:978)
                                                                                                    	at androidx.compose.ui.node.LayoutNode.onNodePlaced$ui_release(LayoutNode.kt:964)
                                                                                                    	at androidx.compose.ui.node.InnerPlaceable.placeAt-f8xVGno(InnerPlaceable.kt:129)
                                                                                                    	at androidx.compose.ui.layout.Placeable.access$placeAt-f8xVGno(Placeable.kt:31)
                                                                                                    	at androidx.compose.ui.layout.Placeable$PlacementScope.place-70tqf50(Placeable.kt:370)
                                                                                                    	at androidx.compose.ui.node.OuterMeasurablePlaceable.placeOuterWrapper-f8xVGno(OuterMeasurablePlaceable.kt:170)
                                                                                                    	at androidx.compose.ui.node.OuterMeasurablePlaceable.access$placeOuterWrapper-f8xVGno(OuterMeasurablePlaceable.kt:28)
                                                                                                    	at androidx.compose.ui.node.OuterMeasurablePlaceable$placeAt$1.invoke(OuterMeasurablePlaceable.kt:158)
                                                                                                    	at androidx.compose.ui.node.OuterMeasurablePlaceable$placeAt$1.invoke(OuterMeasurablePlaceable.kt:157)
                                                                                                    	at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:126)
                                                                                                    	at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:88)
                                                                                                    	at androidx.compose.ui.node.OwnerSnapshotObserver.observeLayoutModifierSnapshotReads$ui_release(OwnerSnapshotObserver.kt:69)
                                                                                                    	at androidx.compose.ui.node.OuterMeasurablePlaceable.placeAt-f8xVGno(OuterMeasurablePlaceable.kt:157)
                                                                                                    	at androidx.compose.ui.layout.Placeable.access$placeAt-f8xVGno(Placeable.kt:31)