I'm building an app for a kiosk. Full compose. I'...
# compose
c
I'm building an app for a kiosk. Full compose. I'm trying to add a "debug" dialog that pops up if you click the same "empty" spot on the screen 10 times in 5 seconds. I initially added this on the activity level by overriding my activities
dispatchTouchEvent
method, but now I'm thinking if it'd be possible to have another wrapper composable just inside my Theme declaration that would be able to do the same thing. i.e. Change this
Copy code
MyAppTheme {
 Scaffold { .. }
}
to this
Copy code
MyAppTheme {
 DebugDialogTouchInterceptor {
  Scaffold { .. }
 }
}
Does anyone know if it'd be possible to write something like that in compose?
a
What is the dialog for?
Maybe there's better solutionr
As an example, for debug purposes: https://github.com/alorma/Compose-Debug-Drawer
c
The dialog is to display some debug information, like version of the app. The debug drawer approach was denied by our tech lead.
Came up with something like this if anyone wants to critique it... opinions welcome!
Copy code
@Composable
fun DebugDialogTouchInterceptor(content: @Composable BoxScope.() -> Unit) {
    var touchTimes by remember { mutableStateOf(0) }
    Box(
        modifier =
            Modifier.clickable(
                interactionSource = remember { MutableInteractionSource() },
                indication = null,
                onClick = { touchTimes++ })) {
        val openDialog = remember { derivedStateOf { touchTimes > 3 } }

        if (openDialog.value) {
            Dialog(onDismissRequest = {}) {
                Box(Modifier.fillMaxSize().background(Color.White))
            }
        }
        content()
    }
}
Not perfect as it doesn't have a timer in it, and it doesn't take into account click location, but it's a decent starting point. Will take tips on timer and click location tho. 😅
f
why not offload this to your viewmodel? have a click callback that is triggered when the user taps on your easter egg region and then you can handle timings and triggering the display of the dialog from your viewmodel
👍 1