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

myanmarking

01/21/2022, 3:57 PM
i need the fragment context for some legacy dialogs inside a composable.
Copy code
LocalContext.current
is not returning me the fragment context. Is there a way to get it, without passing the context explicitly?
i think i got it. I was passing wrong context in ComposeView
c

Casey Brooks

01/21/2022, 4:10 PM
Fragments don't extend
Context
like an
Activity
does, so
LocalContext
will never give you a reference to a Fragment.
m

myanmarking

01/21/2022, 4:12 PM
ya. but i’m using a themed context (contextThemeWrapper) in the composeView because i need different context based on the fragment. For some reason, its not using that context
a

Adam Powell

01/21/2022, 8:18 PM
Here's how it assigns
LocalContext
- it comes from the view, so it should be whatever context you've used to construct the view: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]tionLocals.android.kt;l=116?q=ProvideAndroidCompositionLocals
m

myanmarking

01/21/2022, 8:19 PM
thanks @Adam Powell. I managed to find it 😛