https://kotlinlang.org logo
Title
f

fengdai

06/07/2022, 1:33 PM
AndroidView
’s
factory
lambda will always be called twice when used in
movableContentOf
. Does anyone know why?
val content = movableContentOf {
    AndroidView(factory = { context ->
        SomeView(context)
    })
}
val content2 = movableContentOf {
    // content2
}
val isLandscape =
    LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
if (!isLandscape) Column {
    content()
    content2()
} else Row {
    content()
    content2()
}
1
z

Zach Klippenstein (he/him) [MOD]

06/07/2022, 3:32 PM
Please file a bug
f

fengdai

06/08/2022, 1:43 AM
I think that’s my fault. I should use
movableContentOf
with
remember
. The correct code is:
val content = remember {
  movableContentOf {
    AndroidView(factory = { context ->
        SomeView(context)
    })
  }
}
val content2 = remember {
  movableContentOf {
    // content2
  }
}
val isLandscape =
    LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
if (!isLandscape) Column {
    content()
    content2()
} else Row {
    content()
    content2()
}
z

Zach Klippenstein (he/him) [MOD]

06/08/2022, 1:52 AM
Wow, I totally missed that. Yep that'll do it. Bug should now be that we're not giving a lint warning like we do for mutable state and derives state
👍🏻 1
f

fengdai

06/08/2022, 1:54 AM
That sounds good!