Andy Himberger
03/28/2022, 3:46 PMReusableContent(component) {
AndroidView(factory = {
createView(it, component)
}, Modifier.fillMaxSize(), { })
}
I tried some other things like recomposer.invalidate when the component changed, creating different factory function instances that differed slightly, but that didn't change anything... I was really expecting when the args to AndroidView changed, it would create a new view underneath and clean up the old one. Maybe I'm missing somethingannsofi
03/28/2022, 3:50 PMfactory
, I think it's named update
or something along those lines.Adam Powell
03/28/2022, 3:56 PMAndy Himberger
03/28/2022, 4:25 PMPaul Woitaschek
03/28/2022, 4:33 PMAndy Himberger
03/28/2022, 5:10 PMPaul Woitaschek
03/28/2022, 5:15 PMAndy Himberger
03/28/2022, 5:28 PMwhen (component) {
Component.DATE_FORMAT -> AndroidView(factory = factory)
Component.DIALOGS -> AndroidView(factory = factory)
...(20 more)..
}
Paul Woitaschek
03/28/2022, 5:36 PMAndy Himberger
03/28/2022, 6:05 PM@Composable
fun DemoSecondaryPane(
activity: ComponentActivity,
component: Component?,
) {
if (component == null) return
if (component.composeConfig != null) {
component.composeConfig.content.invoke()
} else {
val supportFragmentManager = (activity as AppCompatActivity).supportFragmentManager
val fragment = remember(component) {
component.getFragment(supportFragmentManager.fragmentFactory)
}
val viewId = remember(component) { View.generateViewId() }
AndroidView(factory = {
FragmentContainerView(it).apply {
id = viewId
}
}, Modifier.fillMaxSize(),
{}
)
DisposableEffect(fragment) {
supportFragmentManager.beginTransaction().apply {
disallowAddToBackStack()
replace(viewId, fragment)
commit()
}
onDispose {
if (!supportFragmentManager.isStateSaved) {
supportFragmentManager.beginTransaction().apply {
remove(fragment)
commit()
}
}
}
}
}
}
Adam Powell
03/28/2022, 9:29 PMkey(...) { ... }
composable is likely to be your friend here if there are changes that should really result in completely recreating the viewAndy Himberger
03/29/2022, 12:18 AM