amar_1995
11/07/2019, 10:32 AMcontext
as input parameter while calling from setContent
.
How to use the same function calling from @Preview
function
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MainScreen(applicationContext)
}
}
}
@Composable
fun MainScreen(context: Context) { ...}
@Preview
@Composable
fun testPreview() {
MainScreen( needToGetContextHere )
}
As in preview function we cannot pass any parameter. Is there any other approach to preview this ??
I think of one solution is to make context
global. Is there any other better approach ??aiidziis
11/07/2019, 10:36 AMAndrew Kelly
11/07/2019, 10:42 AMval context = +ambient(ContextAmbient)
, you don’t need to pass any parameters.Andrew Kelly
11/07/2019, 10:44 AMApplicationContext
this may or may not be true now. Meaning that on configuration change you might not see new resources if you load them via the context. There are helper methods though for things like reading Strings, Drawables etc, so maybe use those instead if required.amar_1995
11/07/2019, 10:48 AM