Skip to content

Commit

Permalink
Change fit system windows approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylwester Zielinski committed Apr 4, 2023
1 parent 13e9844 commit 8c95dec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MainActivity : NordicActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

WindowCompat.setDecorFitsSystemWindows(window, false)
setDecorFitsSystemWindows(false)

val menuItems = listOf(
Item("Main", Tabs, Icons.Filled.Verified),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ import android.os.Bundle
import android.view.View
import android.view.WindowInsetsController
import androidx.activity.ComponentActivity
import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat

/**
* Base activity that sets the Nordic theme and the Splash Screen.
Expand All @@ -56,6 +57,8 @@ abstract class NordicActivity : ComponentActivity() {
setTheme(R.style.NordicTheme)
super.onCreate(savedInstanceState)

setDecorFitsSystemWindows(true)

val view = window.decorView
if (!isDarkMode()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Expand Down Expand Up @@ -85,6 +88,15 @@ abstract class NordicActivity : ComponentActivity() {
}
}

fun setDecorFitsSystemWindows(decorFitsSystemWindows: Boolean) {
if (!decorFitsSystemWindows) {
WindowCompat.setDecorFitsSystemWindows(window, false)
window.statusBarColor = ContextCompat.getColor(this, android.R.color.transparent)
} else {
window.statusBarColor = ContextCompat.getColor(this, R.color.statusBarColor)
}
}

fun isDarkMode(): Boolean {
val darkModeFlag = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return darkModeFlag == Configuration.UI_MODE_NIGHT_YES
Expand Down

0 comments on commit 8c95dec

Please sign in to comment.