Hello! Is there a way to provide 3d party context ...
# compose
a
Hello! Is there a way to provide 3d party context to Composable Preview? Details in the thread.
Copy code
@Composable
fun DGisMapComposable(dGisContext: Context) { .. }

@Preview
@Composable
fun DGisMapComposablePreview() {
    // provide dGisContext somehow
}
z
Never heard of dGisContext before, Google also shows 0 results. What is it and how does it differ from the regular “context: Context”?
a
it’s just a context needed for using a map api https://docs.2gis.com/en/android/sdk/overview (like Google Maps)
z
LocalContext.current?
a
Yeah, I tried that, it doesn’t work in my case
z
What doesn't work
a
when I put
LocalContext.current
in place of
dGisContext
inside preview I’m getting an error
z
What error
a
If you are not making fun of me right now, the error is obviously in a type mismatch. Required: ru.dgis.sdk.Context, but found android.content.Context
dGisContext is an intrinsic context of this 3d party maps library, which is a wrapper of applicationContext with some additional properties
z
It isn't so obvious because this is a Russian library that might not be so popular for most developers. Anyway val androidContext = LocalContext.current val sdkContext = DGis.initialize( androidContext, ApiKeys( directory = "Directory API key", map = "SDK key" ) )
You should probably create a factory method to retrieve that DGis context somewhere to prevent duplicate code
a
Ok, thank you. I’ll give it a try
Well, just to be clear. I had initialised context the way Zun proposed. And I use Hilt to inject it in my fragment, where I call the map compose function. The original question was about any 3d party context in compose preview. If anyone had a case like that, please, ping this thread. Thanks