Ahmet Delibaş
01/20/2021, 1:53 PMvar current by remember { mutableStateOf(0) }
after any change on current value, AndroidView component does not recompose. Does anybody know the answer? How can I update the AndroidView() part?Adam Powell
01/20/2021, 3:07 PMAhmet Delibaş
01/21/2021, 6:10 AM@Composable
fun StoryCaptureScreen(
backAction: () -> Unit,
modifier: Modifier,
) {
var currentCam by remember { mutableStateOf(0) }
val switchAction = { currentCam = switchCamera(currentCam) }
Box(modifier = modifier.fillMaxSize()) {
StoryCamera(currentCam)
StoryCaptureOverlayUI(backAction, modifier, switchAction)
}
}
@Composable
fun StoryCamera(currentCam: Int) {
val lifecycleOwner = AmbientLifecycleOwner.current
val context = AmbientContext.current
val cameraProviderFuture = ProcessCameraProvider.getInstance(context)
AndroidView(
viewBlock = {
PreviewView(context).apply {
cameraProviderFuture.addListener({
val cameraProvider = cameraProviderFuture.get()
bindPreview(
lifecycleOwner,
this,
cameraProvider,
currentCam
)
}, ContextCompat.getMainExecutor(context)
)
scaleType = PreviewView.ScaleType.FILL_CENTER
} },
modifier = Modifier.fillMaxSize(),
)
}
Adam Powell
01/21/2021, 6:17 AMAhmet Delibaş
01/21/2021, 6:28 AMAndroidView({ customView }) { view ->
// View's been inflated - add logic here if necessary
// As selectedItem is read here, AndroidView will recompose
// whenever the state changes
// Example of Compose -> View communication
view.coordinator.selectedItem = selectedItem.value
}
https://developer.android.com/jetpack/compose/interop#views-in-compose