Ehsan Mehranberg
12/02/2021, 3:26 PMAndroidView
that wraps a ComposeView
and the content of the ComposeView
could be any composable
@Composable
fun SharedElement(
modifier: Modifier = Modifier,
transitionTag: String,
@IdRes viewId: Int,
content: @Composable () -> Unit
) {
AndroidView(
modifier = modifier,
factory = { context ->
ComposeView(context).apply {
transitionName = transitionTag
id = viewId
setContent {
content()
}
}
}
)
}
The problem is when the first fragment gets destroyed, the content of shared element gets decomposed as well and we can’t have a smooth transition between fragments. Ideally, shared composables should decompose when the element transition ends but I couldn’t find a way to do that. Any idea how this shared element transition can be nailed with composables and fragments?Ian Lake
12/02/2021, 4:37 PMViewCompositionStrategy
on your ComposeView? If so, your Composable wouldn't be disposed until the fragment transition completes https://developer.android.com/jetpack/compose/interop/interop-apis#compose-in-fragmentsEhsan Mehranberg
12/03/2021, 10:54 AMDisposeOnViewTreeLifecycleDestroyed
but transition continues after view gets destroyedIan Lake
12/03/2021, 4:45 PMEhsan Mehranberg
12/05/2021, 11:51 PMIan Lake
12/06/2021, 1:26 AMEhsan Mehranberg
12/06/2021, 5:34 PMIan Lake
12/07/2021, 12:15 AMIan Lake
12/07/2021, 12:25 AM3000
and added modifier = Modifier.border(5.dp, Color.Red)
to the Image
within the ComposeView
of your SharedElement
Ian Lake
12/07/2021, 12:30 AMV/FragmentManager: >>>>> Beginning transition <<<<<
V/FragmentManager: >>>>> SharedElementFirstOutViews <<<<<
V/FragmentManager: View: androidx.compose.ui.platform.ComposeView{52fd18e V.E...... ........ 0,0-1050,1050 #7f080170 app:id/shared_element_1} Name: MyTag
V/FragmentManager: View: android.view.View{909adaf V.ED..... ........ 0,0-0,0} Name: null
V/FragmentManager: >>>>> SharedElementLastInViews <<<<<
V/FragmentManager: View: androidx.compose.ui.platform.ComposeView{6475bc V.E...... ........ 0,0-350,350 #7f080171 app:id/shared_element_2} Name: null
Ian Lake
12/07/2021, 12:32 AM0,0
seems rather suspicious - I would have expected your Align.BottomEnd
ComposeView to be positioned, in a View sense, in the lower right, not the upper left corner