-
Notifications
You must be signed in to change notification settings - Fork 1k
Force LTR text direction for passwords and TOTP codes #6309
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.bitwarden.ui.platform.util | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.platform.LocalLayoutDirection | ||
| import androidx.compose.ui.text.TextStyle | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.text.style.TextDirection | ||
| import androidx.compose.ui.unit.LayoutDirection | ||
| import com.bitwarden.annotation.OmitFromCoverage | ||
|
|
||
| /** | ||
| * Returns a [TextStyle] that forces left-to-right text direction while maintaining | ||
| * locale-aware alignment. | ||
| * | ||
| * This extension is designed for sensitive alphanumeric content (passwords, TOTP codes) | ||
| * that must always read left-to-right regardless of system locale, but should align | ||
| * according to the layout direction (right-aligned in RTL locales, left-aligned in LTR). | ||
| * | ||
| * **Implementation:** | ||
| * - Sets `textDirection = TextDirection.Ltr` to force LTR reading order | ||
| * - Sets `textAlign` conditionally: | ||
| * - `TextAlign.End` in RTL layouts (aligns to right side) | ||
| * - `TextAlign.Start` in LTR layouts (aligns to left side) | ||
| * | ||
| * **Use cases:** | ||
| * - Password fields that should read "Pass123!" not "!321ssaP" in RTL locales | ||
| * - TOTP verification codes that should read "123 456" not "654 321" | ||
| * - Any alphanumeric content requiring LTR reading with locale-aware positioning | ||
| * | ||
| * @return A merged [TextStyle] with forced LTR direction and locale-aware alignment. | ||
| */ | ||
| @OmitFromCoverage | ||
| @Composable | ||
| fun TextStyle.withForcedLtr(): TextStyle { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about adding the word
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good |
||
| val layoutDirection = LocalLayoutDirection.current | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we pass this in? fun TextStyle.withForcedLtr(
layoutDirection: LayoutDirection = LocalLayoutDirection.current,
): TextStyle { |
||
| return merge( | ||
| TextStyle( | ||
| textDirection = TextDirection.Ltr, | ||
| textAlign = when (layoutDirection) { | ||
| LayoutDirection.Rtl -> TextAlign.End | ||
| LayoutDirection.Ltr -> TextAlign.Start | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make more sense to explicitly call out
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, that's a little more concise. I'm for it. |
||
| }, | ||
| ), | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great docs!