Skip to content

Commit

Permalink
Fix statusbar content overlap for Android 15
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Jan 15, 2025
1 parent 121daab commit 3c2012c
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
package io.horizontalsystems.bankwallet.core

import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import io.horizontalsystems.core.CoreApp

abstract class BaseActivity : AppCompatActivity() {

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

enableEdgeToEdge()
window.decorView.layoutDirection = if (CoreApp.instance.isLocaleRTL()) View.LAYOUT_DIRECTION_RTL else View.LAYOUT_DIRECTION_LTR
}

override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(CoreApp.instance.localeAwareContext(newBase))
}

protected fun setStatusBarTransparent() {
if (Build.VERSION.SDK_INT in 26..29) {
window.statusBarColor = Color.TRANSPARENT

@Suppress("DEPRECATION")
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE

} else if (Build.VERSION.SDK_INT >= 30) {
window.statusBarColor = Color.TRANSPARENT
// Making status bar overlaps with the activity
WindowCompat.setDecorFitsSystemWindows(window, false)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class IntroActivity : BaseActivity() {
setContent {
IntroScreen(viewModel, nightMode) { finish() }
}
setStatusBarTransparent()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ 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.windowInsetsPadding
import androidx.compose.material.Scaffold
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -26,6 +29,7 @@ import io.horizontalsystems.bankwallet.modules.pin.unlock.PinUnlockViewModel
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.title3_leah

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun PinUnlock(
onSuccess: () -> Unit,
Expand Down Expand Up @@ -70,6 +74,7 @@ fun PinUnlock(
topBar = {
Row(
modifier = Modifier
.windowInsetsPadding(TopAppBarDefaults.windowInsets)
.fillMaxWidth()
.height(64.dp),
verticalAlignment = Alignment.CenterVertically,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class QRScannerActivity : BaseActivity() {
onCameraPermissionSettingsClick = { openCameraPermissionSettings() }
)
}
setStatusBarTransparent()
}

private fun onScan(address: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.ExperimentalMaterialApi
Expand All @@ -31,6 +32,7 @@ import androidx.compose.material.Text
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetState
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
Expand Down Expand Up @@ -380,6 +382,7 @@ fun ButtonPrimaryCustomColor(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TitleCenteredTopBar(
title: String,
Expand All @@ -388,6 +391,7 @@ fun TitleCenteredTopBar(
) {
Box(
modifier = modifier
.windowInsetsPadding(TopAppBarDefaults.windowInsets)
.height(64.dp)
.fillMaxWidth(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package io.horizontalsystems.bankwallet.ui.compose.components
import androidx.annotation.DrawableRes
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -98,16 +102,20 @@ fun AppBar(
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppBar(
title: @Composable () -> Unit,
navigationIcon: @Composable (() -> Unit)? = null,
menuItems: List<IMenuItem> = listOf(),
showSpinner: Boolean = false,
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
backgroundColor: Color = ComposeAppTheme.colors.tyler
) {
TopAppBar(
modifier = Modifier.height(64.dp),
modifier = Modifier
.windowInsetsPadding(windowInsets)
.height(64.dp),
title = title,
backgroundColor = backgroundColor,
navigationIcon = navigationIcon?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material.*
import androidx.compose.material3.NavigationBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -64,6 +65,7 @@ fun HsBottomNavigation(
backgroundColor: Color = MaterialTheme.colors.primarySurface,
contentColor: Color = contentColorFor(backgroundColor),
elevation: Dp = BottomNavigationDefaults.Elevation,
windowInsets: WindowInsets = NavigationBarDefaults.windowInsets,
content: @Composable RowScope.() -> Unit
) {
Surface(
Expand All @@ -75,6 +77,7 @@ fun HsBottomNavigation(
Row(
Modifier
.fillMaxWidth()
.windowInsetsPadding(windowInsets)
.height(BottomNavigationHeight)
.selectableGroup(),
horizontalArrangement = Arrangement.SpaceBetween,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import androidx.compose.animation.fadeOut
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Icon
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.material.TextFieldDefaults
import androidx.compose.material.TopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -33,6 +36,7 @@ import androidx.compose.ui.unit.dp
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme

@OptIn(ExperimentalMaterial3Api::class)
@ExperimentalAnimationApi
@Composable
fun SearchBar(
Expand All @@ -52,7 +56,9 @@ fun SearchBar(
var searchText by remember { mutableStateOf("") }

TopAppBar(
modifier = Modifier.height(64.dp),
modifier = Modifier
.windowInsetsPadding(TopAppBarDefaults.windowInsets)
.height(64.dp),
title = {
title3_leah(
text = if (searchMode) "" else title,
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<style name="Theme.AppTheme.DarkModeAppTheme" parent="Theme.AppTheme">
<item name="colorAccent">@color/yellow_d</item>
<item name="android:windowBackground">@color/dark</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="actionMenuTextAppearance">@style/Headline2</item>
<item name="colorControlNormal">@color/grey</item>
<item name="colorControlActivated">@color/yellow_d</item>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-v31/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
<item name="windowSplashScreenBackground">@color/tyler</item>
<item name="windowSplashScreenAnimationDuration">300</item>
<item name="postSplashScreenTheme">@style/Theme.AppTheme.DayNight</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
3 changes: 0 additions & 3 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<style name="Theme.AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorAccent">@color/yellow_l</item>
<item name="android:windowBackground">@color/light</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:actionMenuTextAppearance">@style/Headline2</item>
<item name="colorControlNormal">@color/grey</item>
<item name="colorControlActivated">@color/yellow_l</item>
Expand Down Expand Up @@ -54,6 +52,5 @@
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_logo</item>
<item name="windowSplashScreenAnimationDuration">300</item>
<item name="postSplashScreenTheme">@style/Theme.AppTheme.DayNight</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>

0 comments on commit 3c2012c

Please sign in to comment.