Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash that occurs when the password input field visibility state changes and an accessibility service is enabled running Android 7 (API level 25) and below #8071

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix crash when unmasking password field with TalkBack enabled
  • Loading branch information
muqeeta96 authored and cketti committed Aug 28, 2024
commit 89bacb2f9476ad0ebc20b97c2097854086ff8bb3
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.k9mail.core.ui.compose.designsystem.atom.textfield

import android.os.Build
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -8,6 +9,8 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.password
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
Expand All @@ -34,7 +37,7 @@ fun TextFieldOutlinedPassword(
Material3OutlinedTextField(
value = value,
onValueChange = stripLineBreaks(onValueChange),
modifier = modifier,
modifier = modifier.applyLegacyPasswordSemantics(),
enabled = isEnabled,
label = selectLabel(label, isRequired),
trailingIcon = selectTrailingIcon(
Expand Down Expand Up @@ -69,7 +72,7 @@ fun TextFieldOutlinedPassword(
Material3OutlinedTextField(
value = value,
onValueChange = stripLineBreaks(onValueChange),
modifier = modifier,
modifier = modifier.applyLegacyPasswordSemantics(),
enabled = isEnabled,
label = selectLabel(label, isRequired),
trailingIcon = selectTrailingIcon(
Expand Down Expand Up @@ -129,3 +132,16 @@ private fun selectVisualTransformation(
}

private fun isShowPasswordAllowed(isEnabled: Boolean, isPasswordVisible: Boolean) = isEnabled && isPasswordVisible

private fun Modifier.applyLegacyPasswordSemantics(): Modifier {
/*
* Workaround for a crash that can occur when the password visibility state changes
* while an accessibility service is enabled on devices running Android API level 25 or below.
* This approach mitigates the issue by applying password semantics only on affected versions.
*/
return this.semantics {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) {
password()
}
}
}