think missing something. AS can't render Compose ...
# compose
a
think missing something. AS can't render Compose preview with CameraX Preview.🧵
"This preview was unable to find a CompositionLocal. You might need to define it so it can render correctly. Show Exception"
java.lang.IllegalStateException: CameraX is not configured properly. The most likely cause is you did not include a default implementation in your build such as 'camera-camera2'. at androidx.camera.core.CameraX.getOrCreateInstance(CameraX.java:360) at androidx.camera.lifecycle.ProcessCameraProvider.getInstance(ProcessCameraProvider.java:154) at com.ylabz.rxtrack.ui.view.CamShotUIKt.SimpleCameraPreview(CamShotUI.kt:36) at com.ylabz.rxtrack.ui.view.CamShotUIKt.ComposablePreview(CamShotUI.kt:202) ...
this works perfect in the App. Just the Android Studio Compose Preview is not working ...
We are not allowed to checkin until all AS Previews work ... but not sure what is missing ... 😢
a
"This preview was unable to find a CompositionLocal. You might need to define it so it can render correctly. Show Exception"
I suspect you're defining your CL high up in your hierarchy. But you're previewing something lower down.
a
So we don't pass in the Nav or ModelView to the composable but not sure how not to pass in the CameraX? the AndroidView needs it ... so not sure how to change the CL hierarchy 🤷🏽? kinda lost ...
The App works perfect ... Just Android Studio Compose Preview is not showing th e CameraX Preview
r
Note that anything that uses a
SurfaceView
or
TextureView
won’t preview properly anyway
👍🏽 2
a
True, forgot 😖 much 🙏🏽 ... So, we are not allowed to submit code until all AS previews are rending properly ... we are going to have think about this ...
r
You’ll have to allow exceptions for at least
Surface/TextureView
👌 2
c
This is how I did it
Copy code
@Composable
fun ComposableUsingSurfaceView(
   ...,
   surfaceViewComposable: @Composable () -> Unit
) {
    ...composables
    
    surfaceViewComposable()
    
    ...composables
}

@Preview
@Composable
fun PreviewComposable() {
   ComposableUsingSurfaceView(...) {
      Box(...modifiers) {
         Text("Surface preview")
      }
}
and in runtime composable you use your surfaceview composable
a
@Carl Benson 🙏🏽 we will try to build a similar solution ...
315 Views