Skip to content

Commit

Permalink
perf: translucent navigation (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Nov 14, 2024
1 parent 84710bf commit dff1c5a
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 37 deletions.
3 changes: 2 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,7 +95,7 @@ fun ActivityLogPage() {
})
}) { contentPadding ->
LazyColumn(
modifier = Modifier.padding(contentPadding),
modifier = Modifier.scaffoldPadding(contentPadding),
) {
items(
count = list.itemCount,
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -178,7 +179,7 @@ fun AppConfigPage(appId: String) {
},
) { contentPadding ->
LazyColumn(
modifier = Modifier.padding(contentPadding),
modifier = Modifier.scaffoldPadding(contentPadding),
state = listState,
) {
itemsIndexed(globalGroups) { i, g ->
Expand Down
9 changes: 3 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -150,9 +149,7 @@ fun AppItemPage(
}
}) { contentPadding ->
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(contentPadding)
modifier = Modifier.scaffoldPadding(contentPadding)
) {
item {
Spacer(modifier = Modifier.height(10.dp))
Expand Down Expand Up @@ -285,7 +282,7 @@ fun AppItemPage(
},
)
}
if (editable && subsRaw != null && subsItem != null) {
if (editable && subsRaw != null) {
DropdownMenuItem(
text = {
Text(text = "删除", color = MaterialTheme.colorScheme.error)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -139,7 +140,7 @@ fun ClickLogPage() {
})
}, content = { contentPadding ->
LazyColumn(
modifier = Modifier.padding(contentPadding),
modifier = Modifier.scaffoldPadding(contentPadding),
) {
items(
count = clickDataItems.itemCount,
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 20 additions & 14 deletions app/src/main/kotlin/li/songe/gkd/ui/SlowGroupPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -81,21 +81,25 @@ fun SlowGroupPage() {
}
)
}
) { padding ->
LazyColumn(modifier = Modifier.padding(padding)) {
) { contentPadding ->
LazyColumn(
modifier = Modifier.scaffoldPadding(contentPadding)
) {
items(
ruleSummary.slowGlobalGroups,
{ (_, r) -> "${r.subsItem.id}-${r.group.key}" }
) { (group, rule) ->
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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/ui/style/Padding.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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, 否则 底部导航栏 无法实现透明背景
)
}
4 changes: 3 additions & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<resources>

<style name="AppTheme" parent="android:Theme.Material.NoActionBar"></style>
<style name="AppTheme" parent="android:Theme.Material.NoActionBar">
<item name="android:windowTranslucentNavigation">true</item>
</style>

<style name="SplashScreenTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<resources>

<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar"></style>
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:windowTranslucentNavigation">true</item>
</style>

<style name="SplashScreenTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">
Expand Down

0 comments on commit dff1c5a

Please sign in to comment.