Skip to content

Commit 511c63e

Browse files
committed
Use layout direction to fix text alignment
1 parent 363a8a2 commit 511c63e

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/accountsecurity/pendingrequests/PendingRequestsScreen.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ import androidx.compose.ui.Alignment
3535
import androidx.compose.ui.Modifier
3636
import androidx.compose.ui.input.nestedscroll.nestedScroll
3737
import androidx.compose.ui.platform.LocalContext
38+
import androidx.compose.ui.platform.LocalLayoutDirection
3839
import androidx.compose.ui.platform.testTag
3940
import androidx.compose.ui.res.stringResource
4041
import androidx.compose.ui.text.style.TextAlign
42+
import androidx.compose.ui.unit.LayoutDirection
4143
import androidx.compose.ui.unit.dp
4244
import androidx.hilt.navigation.compose.hiltViewModel
4345
import androidx.lifecycle.Lifecycle
@@ -320,7 +322,11 @@ private fun PendingRequestItem(
320322
text = timestamp,
321323
style = BitwardenTheme.typography.labelSmall,
322324
color = BitwardenTheme.colorScheme.text.secondary,
323-
textAlign = TextAlign.End,
325+
textAlign = if (LocalLayoutDirection.current == LayoutDirection.Rtl) {
326+
TextAlign.Left
327+
} else {
328+
TextAlign.Right
329+
},
324330
)
325331
}
326332
}

app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/BitwardenTheme.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import androidx.compose.runtime.ReadOnlyComposable
1616
import androidx.compose.runtime.SideEffect
1717
import androidx.compose.runtime.compositionLocalOf
1818
import androidx.compose.ui.platform.LocalContext
19+
import androidx.compose.ui.platform.LocalLayoutDirection
1920
import androidx.compose.ui.platform.LocalView
21+
import androidx.compose.ui.text.style.TextAlign
22+
import androidx.compose.ui.unit.LayoutDirection
2023
import androidx.core.view.WindowCompat
2124
import com.x8bit.bitwarden.ui.platform.components.field.interceptor.IncognitoInput
2225
import com.x8bit.bitwarden.ui.platform.feature.settings.appearance.model.AppTheme
@@ -30,6 +33,7 @@ import com.x8bit.bitwarden.ui.platform.theme.shape.bitwardenShapes
3033
import com.x8bit.bitwarden.ui.platform.theme.type.BitwardenTypography
3134
import com.x8bit.bitwarden.ui.platform.theme.type.bitwardenTypography
3235
import com.x8bit.bitwarden.ui.platform.theme.type.toMaterialTypography
36+
import com.x8bit.bitwarden.ui.platform.theme.type.updateTextAlign
3337

3438
/**
3539
* Static wrapper to make accessing the theme components easier.
@@ -101,6 +105,14 @@ fun BitwardenTheme(
101105
else -> lightBitwardenColorScheme
102106
}
103107

108+
val textAlign =
109+
if (LocalLayoutDirection.current == LayoutDirection.Rtl) {
110+
TextAlign.Right
111+
} else {
112+
TextAlign.Left
113+
}
114+
val bitwardenTypography = bitwardenTypography.updateTextAlign(textAlign)
115+
104116
// Update status bar according to scheme
105117
val view = LocalView.current
106118
if (!view.isInEditMode) {

app/src/main/java/com/x8bit/bitwarden/ui/platform/theme/type/BitwardenTypography.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.platform.theme.type
22

33
import androidx.compose.runtime.Immutable
44
import androidx.compose.ui.text.TextStyle
5+
import androidx.compose.ui.text.style.TextAlign
56

67
/**
78
* Defines all the text-styles for the app.
@@ -28,3 +29,31 @@ data class BitwardenTypography(
2829
val sensitiveInfoMedium: TextStyle,
2930
val eyebrowMedium: TextStyle,
3031
)
32+
33+
/**
34+
* Updates the textAlign property of all text-styles.
35+
* @param newTextAlign The new text alignment to be used.
36+
*/
37+
fun BitwardenTypography.updateTextAlign(newTextAlign: TextAlign): BitwardenTypography {
38+
return this.copy(
39+
displayLarge = displayLarge.copy(textAlign = newTextAlign),
40+
displayMedium = displayMedium.copy(textAlign = newTextAlign),
41+
displaySmall = displaySmall.copy(textAlign = newTextAlign),
42+
headlineLarge = headlineLarge.copy(textAlign = newTextAlign),
43+
headlineMedium = headlineMedium.copy(textAlign = newTextAlign),
44+
headlineSmall = headlineSmall.copy(textAlign = newTextAlign),
45+
titleLarge = titleLarge.copy(textAlign = newTextAlign),
46+
titleMedium = titleMedium.copy(textAlign = newTextAlign),
47+
titleSmall = titleSmall.copy(textAlign = newTextAlign),
48+
bodyLarge = bodyLarge.copy(textAlign = newTextAlign),
49+
bodyMedium = bodyMedium.copy(textAlign = newTextAlign),
50+
bodyMediumEmphasis = bodyMediumEmphasis.copy(textAlign = newTextAlign),
51+
bodySmall = bodySmall.copy(textAlign = newTextAlign),
52+
labelLarge = labelLarge.copy(textAlign = newTextAlign),
53+
labelMedium = labelMedium.copy(textAlign = newTextAlign),
54+
labelSmall = labelSmall.copy(textAlign = newTextAlign),
55+
sensitiveInfoSmall = sensitiveInfoSmall.copy(textAlign = newTextAlign),
56+
sensitiveInfoMedium = sensitiveInfoMedium.copy(textAlign = newTextAlign),
57+
eyebrowMedium = eyebrowMedium.copy(textAlign = newTextAlign),
58+
)
59+
}

0 commit comments

Comments
 (0)