`AndroidView` ’s `factory` lambda will always be c...
# compose
f
AndroidView
’s
factory
lambda will always be called twice when used in
movableContentOf
. Does anyone know why?
Copy code
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
Please file a bug
f
I think that’s my fault. I should use
movableContentOf
with
remember
. The correct code is:
Copy code
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
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
That sounds good!