From dff1c5a15bb6999f7c2f478d9d992b8630c21cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E5=88=BA=E8=9E=88?= Date: Thu, 14 Nov 2024 17:24:45 +0800 Subject: [PATCH] perf: translucent navigation (#774) --- .../kotlin/li/songe/gkd/ui/ActivityLogPage.kt | 3 +- .../kotlin/li/songe/gkd/ui/AppConfigPage.kt | 3 +- .../kotlin/li/songe/gkd/ui/AppItemPage.kt | 9 ++--- .../kotlin/li/songe/gkd/ui/CategoryPage.kt | 4 +-- .../kotlin/li/songe/gkd/ui/ClickLogPage.kt | 3 +- .../li/songe/gkd/ui/GlobalRuleExcludePage.kt | 8 +++-- .../kotlin/li/songe/gkd/ui/GlobalRulePage.kt | 7 ++-- .../kotlin/li/songe/gkd/ui/SlowGroupPage.kt | 34 +++++++++++-------- .../kotlin/li/songe/gkd/ui/SnapshotPage.kt | 3 +- .../main/kotlin/li/songe/gkd/ui/SubsPage.kt | 7 ++-- .../li/songe/gkd/ui/home/AppListPage.kt | 5 +-- .../kotlin/li/songe/gkd/ui/style/Padding.kt | 8 +++++ app/src/main/res/values-night/themes.xml | 4 ++- app/src/main/res/values/themes.xml | 4 ++- 14 files changed, 65 insertions(+), 37 deletions(-) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt index 490e28b..8a8e933 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt @@ -40,6 +40,7 @@ import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.StartEllipsisText import li.songe.gkd.ui.component.waitResult import li.songe.gkd.ui.style.EmptyHeight +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.appInfoCacheFlow @@ -94,7 +95,7 @@ fun ActivityLogPage() { }) }) { contentPadding -> LazyColumn( - modifier = Modifier.padding(contentPadding), + modifier = Modifier.scaffoldPadding(contentPadding), ) { items( count = list.itemCount, diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt index 2ceaa9e..0a7e2cc 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt @@ -67,6 +67,7 @@ import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.ui.style.itemVerticalPadding import li.songe.gkd.ui.style.menuPadding +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.ui.style.titleItemPadding import li.songe.gkd.util.LOCAL_SUBS_ID import li.songe.gkd.util.LocalNavController @@ -178,7 +179,7 @@ fun AppConfigPage(appId: String) { }, ) { contentPadding -> LazyColumn( - modifier = Modifier.padding(contentPadding), + modifier = Modifier.scaffoldPadding(contentPadding), state = listState, ) { itemsIndexed(globalGroups) { i, g -> diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt index 18647cb..fa3ae55 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt @@ -8,10 +8,8 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.lazy.LazyColumn @@ -73,6 +71,7 @@ import li.songe.gkd.ui.component.TowLineText import li.songe.gkd.ui.component.waitResult import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.appInfoCacheFlow @@ -150,9 +149,7 @@ fun AppItemPage( } }) { contentPadding -> LazyColumn( - modifier = Modifier - .fillMaxSize() - .padding(contentPadding) + modifier = Modifier.scaffoldPadding(contentPadding) ) { item { Spacer(modifier = Modifier.height(10.dp)) @@ -285,7 +282,7 @@ fun AppItemPage( }, ) } - if (editable && subsRaw != null && subsItem != null) { + if (editable && subsRaw != null) { DropdownMenuItem( text = { Text(text = "删除", color = MaterialTheme.colorScheme.error) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt index d85c452..10548b8 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt @@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.lazy.LazyColumn @@ -57,6 +56,7 @@ import li.songe.gkd.ui.component.updateDialogOptions import li.songe.gkd.ui.component.waitResult import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.EnableGroupOption import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions @@ -126,7 +126,7 @@ fun CategoryPage(subsItemId: Long) { } }) { contentPadding -> LazyColumn( - modifier = Modifier.padding(contentPadding) + modifier = Modifier.scaffoldPadding(contentPadding) ) { items(categories, { it.key }) { category -> var selectedExpanded by remember { mutableStateOf(false) } diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt index 316c004..fae6b5d 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt @@ -63,6 +63,7 @@ import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.StartEllipsisText import li.songe.gkd.ui.component.waitResult import li.songe.gkd.ui.style.EmptyHeight +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.appInfoCacheFlow @@ -139,7 +140,7 @@ fun ClickLogPage() { }) }, content = { contentPadding -> LazyColumn( - modifier = Modifier.padding(contentPadding), + modifier = Modifier.scaffoldPadding(contentPadding), ) { items( count = clickDataItems.itemCount, diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt index 3bf2588..0b31afa 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt @@ -76,6 +76,7 @@ import li.songe.gkd.ui.component.TowLineText import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.appItemPadding import li.songe.gkd.ui.style.menuPadding +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.SortTypeOption @@ -249,8 +250,11 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) { } } }) - }, content = { paddingValues -> - LazyColumn(modifier = Modifier.padding(paddingValues), state = listState) { + }, content = { contentPadding -> + LazyColumn( + modifier = Modifier.scaffoldPadding(contentPadding), + state = listState + ) { items(showAppInfos, { it.id }) { appInfo -> Row( modifier = Modifier diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt index 16c6d55..75cc6a7 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt @@ -71,6 +71,7 @@ import li.songe.gkd.ui.component.TowLineText import li.songe.gkd.ui.component.waitResult import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.json @@ -137,7 +138,9 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { } }, ) { paddingValues -> - LazyColumn(modifier = Modifier.padding(paddingValues)) { + LazyColumn( + modifier = Modifier.scaffoldPadding(paddingValues) + ) { items(globalGroups, { g -> g.key }) { group -> Row( modifier = Modifier @@ -246,7 +249,7 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { ) } ) - if (editable && rawSubs != null) { + if (editable) { DropdownMenuItem( text = { Text(text = "删除", color = MaterialTheme.colorScheme.error) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt index e69f786..0d6d52b 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons @@ -38,6 +37,7 @@ import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.updateDialogOptions import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.itemPadding +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.appInfoCacheFlow @@ -81,8 +81,10 @@ fun SlowGroupPage() { } ) } - ) { padding -> - LazyColumn(modifier = Modifier.padding(padding)) { + ) { contentPadding -> + LazyColumn( + modifier = Modifier.scaffoldPadding(contentPadding) + ) { items( ruleSummary.slowGlobalGroups, { (_, r) -> "${r.subsItem.id}-${r.group.key}" } @@ -90,12 +92,14 @@ fun SlowGroupPage() { SlowGroupCard( modifier = Modifier .clickable(onClick = throttle { - navController.toDestinationsNavigator().navigate( - GlobalRulePageDestination( - rule.subsItem.id, - group.key + navController + .toDestinationsNavigator() + .navigate( + GlobalRulePageDestination( + rule.subsItem.id, + group.key + ) ) - ) }) .itemPadding(), title = group.name, @@ -109,13 +113,15 @@ fun SlowGroupPage() { SlowGroupCard( modifier = Modifier .clickable(onClick = throttle { - navController.toDestinationsNavigator().navigate( - AppItemPageDestination( - rule.subsItem.id, - rule.app.id, - group.key + navController + .toDestinationsNavigator() + .navigate( + AppItemPageDestination( + rule.subsItem.id, + rule.app.id, + group.key + ) ) - ) }) .itemPadding(), title = group.name, diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt index 9d0e9fd..1a684a5 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt @@ -59,6 +59,7 @@ import li.songe.gkd.ui.component.EmptyText import li.songe.gkd.ui.component.StartEllipsisText import li.songe.gkd.ui.component.waitResult import li.songe.gkd.ui.style.EmptyHeight +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.IMPORT_SHORT_URL import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions @@ -119,7 +120,7 @@ fun SnapshotPage() { }) }, content = { contentPadding -> LazyColumn( - modifier = Modifier.padding(contentPadding), + modifier = Modifier.scaffoldPadding(contentPadding), ) { items(snapshots, { it.id }) { snapshot -> if (snapshot.id != snapshots.firstOrNull()?.id) { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt index c1cc260..e442e1a 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed @@ -64,6 +63,7 @@ import li.songe.gkd.ui.component.TowLineText import li.songe.gkd.ui.component.waitResult import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.menuPadding +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.SortTypeOption @@ -241,9 +241,10 @@ fun SubsPage( } } }, - ) { padding -> + ) { contentPadding -> LazyColumn( - modifier = Modifier.padding(padding), state = listState + modifier = Modifier.scaffoldPadding(contentPadding), + state = listState ) { itemsIndexed(appAndConfigs, { i, a -> i.toString() + a.t0.id }) { _, a -> val (appRaw, subsConfig, enableSize) = a diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt index 9b53062..daa57d4 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt @@ -67,6 +67,7 @@ import li.songe.gkd.ui.component.QueryPkgAuthCard import li.songe.gkd.ui.style.EmptyHeight import li.songe.gkd.ui.style.appItemPadding import li.songe.gkd.ui.style.menuPadding +import li.songe.gkd.ui.style.scaffoldPadding import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.SortTypeOption import li.songe.gkd.util.mapHashCode @@ -259,9 +260,9 @@ fun useAppListPage(): ScaffoldExt { } }) } - ) { padding -> + ) { contentPadding -> LazyColumn( - modifier = Modifier.padding(padding), + modifier = Modifier.scaffoldPadding(contentPadding), state = listState ) { items(orderedAppInfos, { it.id }) { appInfo -> diff --git a/app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt b/app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt index cdcfae6..4fb5332 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt @@ -1,5 +1,6 @@ package li.songe.gkd.ui.style +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding import androidx.compose.material3.MenuDefaults import androidx.compose.ui.Modifier @@ -23,3 +24,10 @@ fun Modifier.appItemPadding() = this.padding(10.dp, 10.dp) fun Modifier.menuPadding() = this .padding(MenuDefaults.DropdownMenuItemContentPadding) .padding(vertical = 8.dp) + +fun Modifier.scaffoldPadding(values: PaddingValues): Modifier { + return this.padding( + top = values.calculateTopPadding(), + // 被 LazyColumn( 使用时, 移除 bottom padding, 否则 底部导航栏 无法实现透明背景 + ) +} diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 523494d..ef2372f 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,6 +1,8 @@ - + +