Remove or replace unnecessary BackHandler calls (#4148)

* Remove/replace `BackHandler` calls:

- For `UserProfileView`, remove the redundant `BackHandler` -> `navigateUp()` call.
- For `SetupBiometricView`, remove the `enabled = true` parameter, as this is the default value.
This commit is contained in:
Jorge Martin Espinosa 2025-01-15 10:43:26 +01:00 committed by GitHub
parent f31e648e35
commit a74a62c090
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 5 additions and 21 deletions

View file

@ -31,7 +31,7 @@ fun SetupBiometricView(
state: SetupBiometricState,
modifier: Modifier = Modifier,
) {
BackHandler(true) {
BackHandler {
state.eventSink(SetupBiometricEvents.UsePin)
}
HeaderFooterPage(

View file

@ -45,9 +45,8 @@ fun QrCodeConfirmationView(
onCancel: () -> Unit,
modifier: Modifier = Modifier,
) {
BackHandler {
onCancel()
}
BackHandler(onBack = onCancel)
val icon = when (step) {
is QrCodeConfirmationStep.DisplayCheckCode -> CompoundIcons.Computer()
is QrCodeConfirmationStep.DisplayVerificationCode -> CompoundIcons.LockSolid()

View file

@ -45,16 +45,14 @@ fun QrCodeErrorView(
onRetry: () -> Unit,
modifier: Modifier = Modifier,
) {
BackHandler {
onRetry()
}
BackHandler(onBack = onRetry)
FlowStepPage(
modifier = modifier,
iconStyle = BigIcon.Style.AlertSolid,
title = titleText(errorScreenType, appName),
subTitle = subtitleText(errorScreenType, appName),
content = { Content(errorScreenType) },
buttons = { Buttons(onRetry) }
buttons = { Buttons(onRetry) },
)
}

View file

@ -7,7 +7,6 @@
package io.element.android.features.userprofile.shared
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.consumeWindowInsets
@ -51,7 +50,6 @@ fun UserProfileView(
openAvatarPreview: (username: String, url: String) -> Unit,
modifier: Modifier = Modifier,
) {
BackHandler { goBack() }
Scaffold(
modifier = modifier,
topBar = {

View file

@ -34,7 +34,6 @@ import io.element.android.tests.testutils.ensureCalledOnce
import io.element.android.tests.testutils.ensureCalledOnceWithParam
import io.element.android.tests.testutils.ensureCalledOnceWithTwoParams
import io.element.android.tests.testutils.pressBack
import io.element.android.tests.testutils.pressBackKey
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
@ -46,16 +45,6 @@ import org.robolectric.annotation.Config
class UserProfileViewTest {
@get:Rule val rule = createAndroidComposeRule<ComponentActivity>()
@Test
fun `on back key press - the expected callback is called`() = runTest {
ensureCalledOnce { callback ->
rule.setUserProfileView(
goBack = callback,
)
rule.pressBackKey()
}
}
@Test
fun `on back button click - the expected callback is called`() = runTest {
ensureCalledOnce { callback ->