From d32409bd6e68a3d5e32a69eb1b3afbb407741a00 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 7 Jul 2023 19:58:53 -0400 Subject: [PATCH] Fix up icon direction when RTL --- .../kanade/presentation/components/AppBar.kt | 22 ++++++++++++++----- .../manga/components/MangaToolbar.kt | 8 ++----- .../more/settings/PreferenceScaffold.kt | 10 ++------- .../settings/screen/SettingsMainScreen.kt | 8 ++----- .../settings/screen/SettingsSearchScreen.kt | 8 ++----- .../details/SourcePreferencesScreen.kt | 10 ++------- 6 files changed, 26 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt index e2ca263c2..1acd220fc 100644 --- a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt +++ b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt @@ -10,6 +10,7 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.TextFieldDefaults import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ArrowBack +import androidx.compose.material.icons.outlined.ArrowForward import androidx.compose.material.icons.outlined.Close import androidx.compose.material.icons.outlined.MoreVert import androidx.compose.material.icons.outlined.Search @@ -38,12 +39,14 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import eu.kanade.tachiyomi.R @@ -62,7 +65,7 @@ fun AppBar( subtitle: String? = null, // Up button navigateUp: (() -> Unit)? = null, - navigationIcon: ImageVector = Icons.Outlined.ArrowBack, + navigationIcon: ImageVector? = null, // Menu actions: @Composable RowScope.() -> Unit = {}, // Action mode @@ -107,7 +110,7 @@ fun AppBar( titleContent: @Composable () -> Unit, // Up button navigateUp: (() -> Unit)? = null, - navigationIcon: ImageVector = Icons.Outlined.ArrowBack, + navigationIcon: ImageVector? = null, // Menu actions: @Composable RowScope.() -> Unit = {}, // Action mode @@ -131,10 +134,7 @@ fun AppBar( } else { navigateUp?.let { IconButton(onClick = it) { - Icon( - imageVector = navigationIcon, - contentDescription = stringResource(R.string.abc_action_bar_up_description), - ) + UpIcon(navigationIcon) } } } @@ -360,6 +360,16 @@ fun SearchToolbar( ) } +@Composable +fun UpIcon(navigationIcon: ImageVector? = null) { + val icon = navigationIcon + ?: if (LocalLayoutDirection.current == LayoutDirection.Ltr) Icons.Outlined.ArrowBack else Icons.Outlined.ArrowForward + Icon( + imageVector = icon, + contentDescription = stringResource(R.string.abc_action_bar_up_description), + ) +} + sealed interface AppBar { sealed interface AppBarAction diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt index 533a36bb2..b99d58b58 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt @@ -2,13 +2,11 @@ package eu.kanade.presentation.manga.components import androidx.compose.foundation.layout.Column import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ArrowBack import androidx.compose.material.icons.outlined.Close import androidx.compose.material.icons.outlined.Download import androidx.compose.material.icons.outlined.FilterList import androidx.compose.material.icons.outlined.FlipToBack import androidx.compose.material.icons.outlined.SelectAll -import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme @@ -29,6 +27,7 @@ import androidx.compose.ui.unit.dp import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.components.DownloadDropdownMenu +import eu.kanade.presentation.components.UpIcon import eu.kanade.presentation.manga.DownloadAction import eu.kanade.tachiyomi.R import tachiyomi.presentation.core.theme.active @@ -67,10 +66,7 @@ fun MangaToolbar( }, navigationIcon = { IconButton(onClick = onBackClicked) { - Icon( - imageVector = if (isActionMode) Icons.Outlined.Close else Icons.Outlined.ArrowBack, - contentDescription = stringResource(R.string.abc_action_bar_up_description), - ) + UpIcon(Icons.Outlined.Close.takeIf { isActionMode }) } }, actions = { diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceScaffold.kt b/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceScaffold.kt index 012e1f01d..fb9a3de2a 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceScaffold.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceScaffold.kt @@ -2,15 +2,12 @@ package eu.kanade.presentation.more.settings import androidx.annotation.StringRes import androidx.compose.foundation.layout.RowScope -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ArrowBack -import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource -import eu.kanade.tachiyomi.R +import eu.kanade.presentation.components.UpIcon import tachiyomi.presentation.core.components.material.Scaffold @Composable @@ -27,10 +24,7 @@ fun PreferenceScaffold( navigationIcon = { if (onBackPressed != null) { IconButton(onClick = onBackPressed) { - Icon( - imageVector = Icons.Outlined.ArrowBack, - contentDescription = stringResource(R.string.abc_action_bar_up_description), - ) + UpIcon() } } }, diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt index c788640c7..5b094865b 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ArrowBack import androidx.compose.material.icons.outlined.ChromeReaderMode import androidx.compose.material.icons.outlined.Code import androidx.compose.material.icons.outlined.CollectionsBookmark @@ -20,7 +19,6 @@ import androidx.compose.material.icons.outlined.Search import androidx.compose.material.icons.outlined.Security import androidx.compose.material.icons.outlined.SettingsBackupRestore import androidx.compose.material.icons.outlined.Sync -import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme @@ -45,6 +43,7 @@ import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBarActions +import eu.kanade.presentation.components.UpIcon import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget import eu.kanade.presentation.util.LocalBackPress import eu.kanade.presentation.util.Screen @@ -94,10 +93,7 @@ object SettingsMainScreen : Screen() { }, navigationIcon = { IconButton(onClick = backPress::invoke) { - Icon( - imageVector = Icons.Outlined.ArrowBack, - contentDescription = stringResource(R.string.abc_action_bar_up_description), - ) + UpIcon() } }, actions = { diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt index cad51c044..fa8392140 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt @@ -17,7 +17,6 @@ import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ArrowBack import androidx.compose.material.icons.outlined.Close import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -49,6 +48,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.presentation.components.UpIcon import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.R @@ -97,11 +97,7 @@ class SettingsSearchScreen : Screen() { val canPop = remember { navigator.canPop } if (canPop) { IconButton(onClick = navigator::pop) { - Icon( - imageVector = Icons.Outlined.ArrowBack, - contentDescription = stringResource(R.string.abc_action_bar_up_description), - tint = MaterialTheme.colorScheme.onSurfaceVariant, - ) + UpIcon() } } }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt index 3dab9f821..862f810c5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt @@ -7,9 +7,6 @@ import android.view.View import androidx.appcompat.view.ContextThemeWrapper import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ArrowBack -import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar @@ -21,7 +18,6 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.stringResource import androidx.compose.ui.viewinterop.AndroidView import androidx.core.os.bundleOf import androidx.fragment.app.FragmentActivity @@ -38,6 +34,7 @@ import androidx.preference.forEach import androidx.preference.getOnBindEditTextListener import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.presentation.components.UpIcon import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore @@ -62,10 +59,7 @@ class SourcePreferencesScreen(val sourceId: Long) : Screen() { title = { Text(text = Injekt.get().getOrStub(sourceId).toString()) }, navigationIcon = { IconButton(onClick = navigator::pop) { - Icon( - imageVector = Icons.Outlined.ArrowBack, - contentDescription = stringResource(R.string.abc_action_bar_up_description), - ) + UpIcon() } }, scrollBehavior = it,