https://kotlinlang.org logo
#compose
Title
# compose
f

fengdai

06/09/2022, 12:30 AM
When move movable content (
movableContentOf
) from/to a
SubcomposeLayout
, the
AndroidView
within it will recreate its view.
Copy code
// When rotate screen, AndroidView recreate its view
val content = remember {
    movableContentOf { isLandscape: Boolean ->
        AndroidView(factory = { context ->
            Log.d("AndroidView", "create view")
            TextView(context).apply {
                layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
            }
        }) {
            it.text = if (isLandscape) "Landscape" else "Portrait"
        }
    }
}
val isLandscape =
    LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
BoxWithConstraints {
    if (!isLandscape) {
        content(false)
    }
}
if (isLandscape) {
    content(true)
}
Is this expected?
a

Andrey Kulikov

06/09/2022, 10:52 AM
please file a bug, we will see what we can do
f

fengdai

06/09/2022, 10:59 AM
5 Views