Skip to content

Commit

Permalink
fix(AboutScreen): padding + system navbar transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Jan 25, 2024
1 parent f314283 commit 3931771
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/src/main/kotlin/com/aliucord/manager/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.transitions.FadeTransition
import com.aliucord.manager.manager.PreferencesManager
Expand All @@ -28,6 +29,8 @@ class MainActivity : ComponentActivity() {
private val preferences: PreferencesManager by inject()

override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)

installSplashScreen()

super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.aliucord.manager.R
Expand All @@ -36,6 +37,9 @@ fun ManagerTheme(
color = colorScheme.background,
darkIcons = !isDarkTheme
)
systemUiController.setNavigationBarColor(
color = Color.Transparent,
)
}

MaterialTheme(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import cafe.adriel.voyager.koin.getScreenModel
import coil.compose.AsyncImage
import com.aliucord.manager.R
import com.aliucord.manager.ui.components.*
import com.aliucord.manager.ui.util.paddings.PaddingValuesSides
import com.aliucord.manager.ui.util.paddings.exclude

class AboutScreen : Screen {
override val key = "About"
Expand All @@ -45,7 +47,11 @@ class AboutScreen : Screen {
}
) { paddingValues ->
LazyColumn(
modifier = Modifier.padding(paddingValues),
contentPadding = paddingValues
.exclude(PaddingValuesSides.Horizontal + PaddingValuesSides.Top),
modifier = Modifier
.padding(paddingValues.exclude(PaddingValuesSides.Bottom))
.padding(horizontal = 16.dp),
) {
item(key = "PROJECT_HEADER") {
ProjectHeader()
Expand All @@ -62,7 +68,7 @@ class AboutScreen : Screen {
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.primary,
modifier = Modifier
.padding(start = 16.dp, bottom = 16.dp)
.padding(start = 16.dp, top = 12.dp, bottom = 16.dp)
)
}

Expand Down Expand Up @@ -168,6 +174,7 @@ private fun MainContributors(modifier: Modifier = Modifier) {
@Composable
private fun UserEntry(name: String, roles: String, username: String = name) {
val uriHandler = LocalUriHandler.current

Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.aliucord.manager.ui.util.paddings

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Stable
import androidx.compose.ui.unit.LayoutDirection

/**
* Add the values of two [PaddingValues] together.
*/
fun PaddingValues.add(values: PaddingValues): PaddingValues =
CompositePaddingValues(this, values)

@Stable
private class CompositePaddingValues(
private val valuesA: PaddingValues,
private val valuesB: PaddingValues,
) : PaddingValues {
override fun calculateBottomPadding() =
valuesA.calculateBottomPadding() + valuesB.calculateBottomPadding()

override fun calculateLeftPadding(layoutDirection: LayoutDirection) =
valuesA.calculateLeftPadding(layoutDirection) + valuesB.calculateLeftPadding(layoutDirection)

override fun calculateRightPadding(layoutDirection: LayoutDirection) =
valuesA.calculateRightPadding(layoutDirection) + valuesB.calculateRightPadding(layoutDirection)

override fun calculateTopPadding() =
valuesA.calculateTopPadding() + valuesB.calculateTopPadding()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.aliucord.manager.ui.util.paddings

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.runtime.Stable
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection

typealias PaddingValuesSides = WindowInsetsSides

/**
* Remove particular side values from [PaddingValues].
*/
fun PaddingValues.exclude(sides: PaddingValuesSides): PaddingValues =
ExcludePaddingValues(this, sides)

@Stable
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
private class ExcludePaddingValues(
private val values: PaddingValues,
private val excludeSides: PaddingValuesSides,
) : PaddingValues {
override fun calculateBottomPadding(): Dp {
return if (!excludeSides.hasAny(PaddingValuesSides.Bottom)) {
values.calculateBottomPadding()
} else {
Dp.Hairline
}
}

override fun calculateLeftPadding(layoutDirection: LayoutDirection): Dp {
return if (!excludeSides.hasAny(PaddingValuesSides.Left)) {
values.calculateLeftPadding(layoutDirection)
} else {
Dp.Hairline
}
}

override fun calculateRightPadding(layoutDirection: LayoutDirection): Dp {
return if (!excludeSides.hasAny(PaddingValuesSides.Right)) {
values.calculateRightPadding(layoutDirection)
} else {
Dp.Hairline
}
}

override fun calculateTopPadding(): Dp {
return if (!excludeSides.hasAny(PaddingValuesSides.Top)) {
values.calculateTopPadding()
} else {
Dp.Hairline
}
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ coil = "2.5.0"
compose = "1.5.4"
compose-compiler = "1.5.8"
compose-tracing = "1.0.0-beta01"
compose-material3 = "1.2.0-beta02"
compose-material3 = "1.2.0-rc01"
koin = "3.5.3"
kotlin = "1.9.22"
kotlinx-immutable = "0.3.7"
Expand Down

0 comments on commit 3931771

Please sign in to comment.