fengdai
06/09/2022, 12:30 AMmovableContentOf
) from/to a SubcomposeLayout
, the AndroidView
within it will recreate its view.
// 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?Andrey Kulikov
06/09/2022, 10:52 AMfengdai
06/09/2022, 10:59 AM