How compose preview works - devrath/urban-octo-jetpack-compose GitHub Wiki

About preview in composable

  • In order to debug the UI of the application, We can have a preview function written in the activity or fragment.
  • Here regular function similar to compose function is annotated with @compose.
  • In addition to that we have @Preview(showBackground = true) annotated.
  • On adding it we rebuild the code, then we can display the preview in the preview section
  • Important thing to note is what function you pass into the setContent(), Same is passed to the DefaultPreview()
  • If you delete the below function in the class, Android studio by default takes away the split or design tabs in its editor
@Preview(showBackground = true)
@Composable
fun DefaultPreview(){
    GreetingScreen("Hello World")
}

Navigating to a specific composable

  • We can click a view in the preview and the IDE will navigate us to that specific composable kid of similar to XML(Jump to source)