Skip to content

Commit

Permalink
Support "edge-to-edge" behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriy-chernysh committed Aug 4, 2023
1 parent 9cbd5b2 commit d75f586
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 26 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:name="com.mobiledevpro.apptemplate.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.AppTemplateCompose">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.getValue
import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.mobiledevpro.apptemplate.ui.MainApp
import com.mobiledevpro.ui.theme.AppTheme
Expand All @@ -13,6 +14,10 @@ class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

//False - allows to drawing the content "edge-to-edge"
WindowCompat.setDecorFitsSystemWindows(window, false)

setContent {
val darkModeState by darkModeState.collectAsStateWithLifecycle()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
*/
package com.mobiledevpro.apptemplate.ui

import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import com.mobiledevpro.navigation.Screen
import com.mobiledevpro.navigation.graph.RootNavGraph
Expand All @@ -31,7 +29,6 @@ fun MainApp() {

RootNavGraph(
navController = navController,
modifier = Modifier.safeContentPadding(),
startDestination = Screen.Home
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
package com.mobiledevpro.navigation

import android.util.Log
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
Expand Down Expand Up @@ -83,7 +81,6 @@ fun NavGraphBuilder.homeNavGraph(onNavigateToRoot: (Screen) -> Unit) {
Log.d("navigation", "homeNavGraph:nestedNavGraph")
HomeNavGraph(
navController = navController,
modifier = Modifier.safeContentPadding(),
onNavigateToRoot = onNavigateToRoot
)
}
Expand All @@ -109,8 +106,7 @@ fun NavGraphBuilder.onBoardingNavGraph(onNavigateToRoot: (Screen) -> Unit) {

val nestedNavGraph: @Composable () -> Unit = {
OnBoardingNavGraph(
navController = navController,
modifier = Modifier.safeContentPadding()
navController = navController
)
}

Expand Down Expand Up @@ -138,8 +134,7 @@ fun NavGraphBuilder.peopleNavGraph() {

val nestedNavGraph: @Composable () -> Unit = {
PeopleNavGraph(
navController = navController,
modifier = Modifier.safeContentPadding()
navController = navController
)
}

Expand Down
8 changes: 2 additions & 6 deletions core/ui/src/main/kotlin/com/mobiledevpro/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -90,19 +91,14 @@ fun AppTheme(
content: @Composable () -> Unit
) {
val colorScheme = when {
/*dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}*/

darkTheme -> DarkColorScheme
else -> LightColorScheme
}
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.background.toArgb()
window.statusBarColor = Color.Transparent.toArgb()
window.navigationBarColor = colorScheme.surfaceColorAtElevation(4.dp).toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
WindowCompat.getInsetsController(window, view).isAppearanceLightNavigationBars = !darkTheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
*/
package com.mobiledevpro.home.view

import android.util.Log
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.mobiledevpro.ui.component.ScreenBackground

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(
nestedNavGraph: @Composable () -> Unit,
bottomBar: @Composable () -> Unit
) {

Log.d("navigation", "HomeScreen")

Scaffold(bottomBar = bottomBar) { paddingValues ->
Scaffold(
bottomBar = bottomBar,
contentWindowInsets = WindowInsets.systemBars
) { paddingValues ->
ScreenBackground(
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ fun OnBoardingFirstScreen() {
Box(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
.background(color = Color(0x80FFCC99))
) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
Expand All @@ -47,7 +49,9 @@ fun SubscriptionScreen(onNavigateBack: () -> Unit) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}

Scaffold { paddingValues ->
Scaffold(
contentWindowInsets = WindowInsets.systemBars
) { paddingValues ->
ScreenBackground(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -111,11 +115,87 @@ fun SubscriptionScreen(onNavigateBack: () -> Unit) {

}
}

/*
Column(
modifier = Modifier
.padding(16.dp)
.verticalScroll(rememberScrollState())
.height(IntrinsicSize.Max)
) {
Header()
//If you remove Items, Footer will be centered at the screen as you could see on attached screenshots
Item(text = "Item 1")
Item(text = "Item 2")
Item(text = "Item 3")
Box(
modifier = Modifier
.fillMaxSize()
//.background(color = Color.Blue)
) {
Footer(modifier = Modifier.align(Alignment.Center))
}
}
*/

}
}


}
/*
@Composable
fun Header() {
Box(
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
.background(color = Color.Yellow)
)
}
@Composable
fun Item(text: String) {
Box(
modifier = Modifier
.padding(vertical = 8.dp)
.fillMaxWidth()
.height(50.dp)
.background(color = Color.White)
) {
Text(
text = text,
modifier = Modifier.align(Alignment.Center),
style = MaterialTheme.typography.bodyLarge
)
}
}
@Composable
fun Footer(modifier: Modifier) {
Box(
modifier = modifier
.padding(vertical = 8.dp)
.fillMaxWidth()
.height(100.dp)
.background(color = Color.Gray)
) {
Text(
text = "Optional block",
modifier = Modifier.align(Alignment.Center),
style = MaterialTheme.typography.bodyLarge
)
}
}
*/

@Composable
fun SubsButton(
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ navigation = "2.5.3"
retrofit = "2.9.0"
room = "2.4.3"
lifecycle = "2.6.0"
compose-bom = "2023.01.00"
compose-bom = "2023.06.01"
compose-compiler = "1.4.0"
coil = "2.2.2"
material3 = "1.1.0-alpha08"
material3 = "1.2.0-alpha04"
koin = "3.4.2"
koin-compose = "3.4.5"

Expand Down

0 comments on commit d75f586

Please sign in to comment.