Hi guys, Interoperability question :slightly_smili...
# compose
j
Hi guys, Interoperability question 🙂 Bit of context: we’re trying to add a compose view to MapBox using their view annotation API and that requires an
inflated view
to work. How can I get one with Compose? For now, I’ve tried something like that:
Copy code
val view = ComposeView(requireContext()).apply {
    setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
    setContent {
        MyComposable(param = myParameter)
    }
}
But MapBox crashes with an error message regarding null
LayoutParams
. Any idea how can I get that inflated view? Thanks! 🙂
hmmmm, I guess that was probably a stupid question and that view is technically already “inflated” and I instead needed to add something like
Copy code
view.layoutParams = FrameLayout.LayoutParams(
    ViewGroup.LayoutParams.WRAP_CONTENT,
    ViewGroup.LayoutParams.WRAP_CONTENT
)
to satisfy MapBox... Still doesn’t work but at least, no longer crashes
y
If you have a very specific set of calls, Is it worth extending AbstractComposeView and putting it all inside there?
e
I think there's a bug with mapbox where wrap content just doesn't work. For now I've been setting a fixed size and "wrapping" the content within compose. Weirdly enough, wrap content does start working again if you minimise/reopen the app
j
!!! 😮 We spent the better part of Friday trying to get it to work, just could not find a solution and ended up doing exactly that with fixed size 😅
e
Sounds like we spent our Fridays doing the exact same thing 😅
j
@Elliot Murray Not sure if you’ve tried but just in case, I updated the SDK to 10.12.2 and WRAP_CONTENT seems to work now 🙂
e
Ah cheers, I'll give it a go 🙌