Skip to content

Commit

Permalink
Merge pull request #712 from alvr/feature/enable_edge_to_edge
Browse files Browse the repository at this point in the history
feat: enable edge to edge
  • Loading branch information
alvr authored Jan 12, 2024
2 parents 0cbdf6a + e9353bc commit e6adf20
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
9 changes: 9 additions & 0 deletions androidApp/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="NightAdjusted.Theme.Katana" parent="android:Theme.Material.NoActionBar" />

<style name="NightAdjusted.Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowLightStatusBar" tools:targetApi="23">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
</style>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package dev.alvr.katana.ui.main
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat

internal class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
enableEdgeToEdge()
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent { KatanaApp() }
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package dev.alvr.katana.ui.main.navigation

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.displayCutoutPadding
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.contentColorFor
Expand Down Expand Up @@ -41,7 +41,11 @@ import dev.alvr.katana.ui.main.viewmodel.MainViewModel
import io.sentry.compose.withSentryObservableEffect

@Composable
@OptIn(ExperimentalAnimationApi::class, ExperimentalMaterialNavigationApi::class)
@OptIn(
ExperimentalAnimationApi::class,
ExperimentalMaterialNavigationApi::class,
ExperimentalLayoutApi::class,
)
internal fun KatanaDestinations(
useNavRail: Boolean,
vm: MainViewModel,
Expand All @@ -66,27 +70,24 @@ internal fun KatanaDestinations(
scrimColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.32f),
) {
Scaffold(
modifier = Modifier.systemBarsPadding(),
bottomBar = {
if (!useNavRail) {
NavigationBar(
modifier = Modifier.fillMaxWidth(),
navController = navController,
type = NavigationBarType.Bottom,
)
} else {
Spacer(
Modifier
.windowInsetsBottomHeight(WindowInsets.navigationBars)
.fillMaxWidth(),
)
}
},
contentWindowInsets = WindowInsets(0, 0, 0, 0),
) { paddingValues ->
Row(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues),
.padding(paddingValues)
.consumeWindowInsets(paddingValues)
.systemBarsPadding()
.displayCutoutPadding(),
) {
if (useNavRail) {
NavigationBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
Expand Down Expand Up @@ -122,13 +116,7 @@ private fun RailNavigationBar(
isItemSelected: (NavigationBarItem) -> Boolean,
onClick: (NavigationBarItem) -> Unit,
) {
NavigationRail(
modifier = Modifier.padding(
WindowInsets.systemBars
.only(WindowInsetsSides.Start + WindowInsetsSides.Vertical)
.asPaddingValues(),
),
) {
NavigationRail {
Spacer(Modifier.weight(1f))
destinations.forEach { destination ->
NavigationRailItem(
Expand Down
2 changes: 2 additions & 0 deletions app/src/androidMain/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<style name="NightAdjusted.Theme.Katana" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:navigationBarColor">@null</item>
<item name="android:statusBarColor">@null</item>
</style>

<style name="NightAdjusted.Theme.Splash" parent="Theme.SplashScreen">
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ dependencyResolutionManagement {
pluginManagement {
includeBuild("build-logic")
repositories {
mavenCentral()
google()
gradlePluginPortal()
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.material.BackdropScaffold
import androidx.compose.material.BackdropScaffoldState
import androidx.compose.material.BackdropValue
Expand Down Expand Up @@ -75,6 +76,7 @@ fun KatanaHomeScaffold(
frontLayerContent = {
Scaffold(
floatingActionButton = { fab?.invoke() },
contentWindowInsets = WindowInsets(0, 0, 0, 0),
content = content,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand Down Expand Up @@ -136,11 +138,14 @@ private fun Login(state: LoginState, onLogin: () -> Unit) {
}
}

Scaffold { padding ->
Scaffold(
contentWindowInsets = WindowInsets(0, 0, 0, 0),
) { padding ->
Surface(
modifier = Modifier
.fillMaxSize()
.padding(padding),
.padding(padding)
.consumeWindowInsets(padding),
) {
if (loading) {
Loading()
Expand All @@ -149,7 +154,9 @@ private fun Login(state: LoginState, onLogin: () -> Unit) {
painter = background.asPainter,
contentDescription = strings.contentDescriptionBackground,
contentScale = ContentScale.Crop,
modifier = Modifier.alpha(BACKGROUND_ALPHA),
modifier = Modifier
.fillMaxSize()
.alpha(BACKGROUND_ALPHA),
)

Box(modifier = Modifier.padding(24.dp)) {
Expand Down Expand Up @@ -226,6 +233,7 @@ internal fun Bottom(modifier: Modifier = Modifier) {
State.GetStarted -> GetStarted { changedState ->
currentState = changedState
}

State.Buttons -> Begin()
}
}
Expand Down

0 comments on commit e6adf20

Please sign in to comment.