airbnb / Showkase

🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements
https://medium.com/airbnb-engineering/introducing-showkase-a-library-to-organize-discover-and-visualize-your-jetpack-compose-elements-d5c34ef01095
Apache License 2.0
2.11k stars 107 forks source link

Showkase browser doesn't work with empty @Preview BackHandler #247

Closed ReginFell closed 1 year ago

ReginFell commented 2 years ago

If you have BackHandler which does nothing inside @Preview it breaks navigation for Showkase browser

Snippet to reproduce:

@Composable
fun ContentScreen(
    viewModel: ContentViewModel = androidx.lifecycle.viewmodel.compose.viewModel(),
) {
    Content(onBack = viewModel::onBack)
}

@Composable
fun Content(onBack: () -> Unit) {
    BackHandler(onBack = onBack)
}

@Preview
@Composable
fun ContentPreview() {
    Content(
        onBack = {},
    )
}

If you open ContentPreview from Showkase browser, it will not be possible to navigate back

ReginFell commented 2 years ago

One potential fix could be making LocalInspectionMode.current return true for Showkase scope, this way we can either add or not add backpress handler based on LocalInspectionMode

vinaygaba commented 1 year ago

@ReginFell I was able to repro and have a fix pushed for it