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

maxgdn

02/18/2022, 12:45 AM
Have any attempts at putting a ComposeView inside an ArrayAdapter been made?
After varied attempts of 1.
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
2. calling
disposeComposition()
I'm stuck with
Copy code
java.lang.IllegalStateException: Cannot locate windowRecomposer; View androidx.compose.ui.platform.ComposeView{...} is not attached to a window
a

Adam Powell

02/18/2022, 1:28 AM
as in for a
ListView
?
m

maxgdn

02/18/2022, 1:33 AM
Specifically an
ArrayAdapter
which extends
BaseAdapter
. It is used in
AutoCompleteTextView
for the dropdown items.
a

Adam Powell

02/18/2022, 1:37 AM
I have to admit you're the first person to ask 😄 got a full stack trace?
m

maxgdn

02/18/2022, 1:45 AM
Let me know if there is anything else I can do! https://gist.github.com/maxgdn/cbbf006bcc9357be207594b8678efef1
a

Adam Powell

02/18/2022, 1:58 AM
the composition needs a parentCompositionContext set on the view to be able to measure, and AutoCompleteTextView tries to measure unattached views to determine the size of the popup window to create
if a parentCompositionContext isn't present, the ComposeView will search the view tree for one. If it's attached to a window then a window-scoped recomposer will be lazily created at that point
you can install one yourself in the window where the AutoCompleteTextView is attached by doing what this internal property does: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/WindowRecomposer.android.kt;l=227?q=WindowRecomposer.
m

maxgdn

02/18/2022, 2:06 AM
I believe I understand and will give this an attempt. Thank you Adam 😄
👍 1
a

Adam Powell

02/18/2022, 2:07 AM
it should make things easier that we recently opened the create function for this as experimental, so you can at least call that to create one instead of having to copy all of that 🙂
that might only be in the recent alphas, I forget if it was experimental in 1.1 or only
internal
👍 1
279 Views