Skip to content

Commit

Permalink
Merge pull request #12300 from woocommerce/12058-woo-pos-make-bottom-…
Browse files Browse the repository at this point in the history
…navigation-bar-transparent-when-its-gesture-based-and-keep-it-as-it-is-in-button-based

[Woo POS] Make bottom navigation bar transparent when its gesture based and keep it as it is in button based
  • Loading branch information
AnirudhBhat authored Aug 13, 2024
2 parents a30e004 + 786835e commit ba22646
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.woocommerce.android.ui.woopos.root

import android.R
import android.content.pm.ActivityInfo
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderFacade
import com.woocommerce.android.ui.woopos.common.composeui.WooPosTheme
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -37,20 +35,38 @@ class WooPosActivity : AppCompatActivity() {
SystemBars()

WooPosRootScreen(
modifier = Modifier
.padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())
modifier = Modifier.gesturesOrButtonsNavigationPadding()
)
}
}
}

@Composable
private fun SystemBars() {
val colors = MaterialTheme.colors

SideEffect {
window.statusBarColor = getColor(R.color.transparent)
window.navigationBarColor = colors.background.toArgb()
window.statusBarColor = getColor(android.R.color.transparent)
window.navigationBarColor = getColor(android.R.color.transparent)
}
}
}

@Composable
private fun Modifier.gesturesOrButtonsNavigationPadding(): Modifier {
val view = LocalView.current
val insets = WindowInsetsCompat.toWindowInsetsCompat(view.rootWindowInsets)
val isGestureNavigation = insets.isGestureNavigation()

return if (isGestureNavigation) {
this.padding(bottom = 0.dp)
} else {
this.navigationBarsPadding()
}
}

// That seems to be different on different devices, but 48dp is a common upper value
private const val GESTURE_NAVIGATION_BAR_HEIGHT = 48
private fun WindowInsetsCompat.isGestureNavigation(): Boolean {
val bottomInset = getInsets(WindowInsetsCompat.Type.navigationBars()).bottom

return bottomInset <= GESTURE_NAVIGATION_BAR_HEIGHT
}

0 comments on commit ba22646

Please sign in to comment.