Hello, everyone! :wave: I’m having some issues wit...
# compose
e
Hello, everyone! 👋 I’m having some issues with Instrumented Tests. Could you help me please? Basically my MainActivity contains a
LocalBackPressedDispatcher
to handle back presses. The code is similar to:
Copy code
setContent {
    AlkaaTheme {
        CompositionLocalProvider(LocalBackPressedDispatcher provides onBackPressedDispatcher) {
            NavGraph()
        }
    }
}
But now my tests are failing with
No Back Dispatcher provided
but I’m not finding a way to provide it.
Copy code
composeTestRule.setContent {
    AlkaaTheme {
        CompositionLocalProvider(
            LocalBackPressedDispatcher provides onBackPressedDispatcher //unresolved reference
        ) {
            NavGraph()
        }
    }
}
I tried with both
createComposeRule()
and
createEmptyComposeRule()
. Thanks a lot!
i
What is a "LocalBackPressedDispatcher" and why aren't you using the androidx.activity APIs specifically for handling the system back button? https://developer.android.com/reference/kotlin/androidx/activity/compose/package-summary#backhandler
e
Well, I was just following official samples. 🙂 Jetchat heavily relies on it. https://github.com/android/compose-samples/blob/ef5b972bdeffa711ef4188a3452aea54a3[…]at/app/src/main/java/com/example/compose/jetchat/NavActivity.kt I didn’t know that there was a simpler solution. Thanks Ian! I will take a look on it. 😊
👍 1