Paulo Martins
09/07/2021, 9:26 AMAndroidView
based on my CustomViewModel
changes.
@Composable
fun FilamentViewer(viewModel: CustomViewModel) {
var modelViewer by remember { mutableStateOf<ModelViewer?>(null) }
launchInComposition {
while (true) {
withFrameNanos { frameTimeNanos ->
modelViewer?.render(frameTimeNanos)
}
}
}
AndroidView({ context ->
LayoutInflater.from(context).inflate(
R.layout.filament_host, FrameLayout(context), false
).apply {
val (engine) = scenes[product.material]!!
modelViewer = ModelViewer(engine, this as SurfaceView).also {
setupModelViewer(it)
}
}
})
}
how can I make it change dynamically? I need to update the modelViewer.scene entityZach Klippenstein (he/him) [MOD]
09/07/2021, 2:33 PMlaunchInComposition
was from over a year agoZach Klippenstein (he/him) [MOD]
09/07/2021, 2:34 PMAndroidView
takes two function parameters: the first one creates the view, and is only called the first time the call is composed, the second one updates the view and is called on every composition (including the first one).Paulo Martins
09/07/2021, 2:35 PMPaulo Martins
09/07/2021, 2:36 PMlaunchInComposition {
while (true) {
withFrameNanos { frameTimeNanos ->
modelViewer?.render(frameTimeNanos)
}
}
}
it won't renderZach Klippenstein (he/him) [MOD]
09/07/2021, 2:39 PMZach Klippenstein (he/him) [MOD]
09/07/2021, 2:39 PMlaunchInComposition
is now called LaunchedEffect
.Paulo Martins
09/07/2021, 2:41 PMАнтон X
09/07/2021, 2:50 PMstate { TextView(...) }
? I've seen some example on codelab where it's used.Paulo Martins
09/07/2021, 3:00 PMLaunchedEffect
. Result is the same. If I delete line
modelViewer?.render(frameTimeNanos)
It won't render nothingZach Klippenstein (he/him) [MOD]
09/07/2021, 3:06 PMAndroidView
looks something like this:
AndroidView(
// This function is only called once.
factory = { context ->
LayoutInflater.from(context)
.inflate(…)
.apply {
// Initialize view.
}
},
// This function is called on every composition.
update = { view ->
// Set view properties that can change based on the
// current composition (e.g. read State values,
// parameters to your composable, etc.)
}
)
Paulo Martins
09/07/2021, 3:08 PMZach Klippenstein (he/him) [MOD]
09/07/2021, 3:23 PM