Cleaning up navigation (#234)
* fix: align bottom to top with RTL * fix: clean up the overlapping decor * feat: match theme color with navbar * fix: measure view on return to view
This commit is contained in:
parent
14115ada4c
commit
af1a481bdb
6 changed files with 61 additions and 50 deletions
|
@ -135,7 +135,7 @@ fun logger(e: Any?, print: Boolean = true) {
|
|||
}
|
||||
|
||||
|
||||
fun initActivity(a: Activity) {
|
||||
fun initActivityTheme(a: Activity) {
|
||||
val window = a.window
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
val darkMode = PrefManager.getVal<Int>(PrefName.DarkMode)
|
||||
|
@ -156,7 +156,7 @@ fun initActivity(a: Activity) {
|
|||
navBarHeight = this.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
|
||||
}
|
||||
}
|
||||
a.hideStatusBar()
|
||||
WindowInsetsControllerCompat(window, window.decorView).hide(WindowInsetsCompat.Type.statusBars())
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && statusBarHeight == 0 && a.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
window.decorView.rootWindowInsets?.displayCutout?.apply {
|
||||
if (boundingRects.size > 0) {
|
||||
|
@ -176,40 +176,47 @@ fun initActivity(a: Activity) {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun Activity.hideSystemBars() {
|
||||
window.decorView.systemUiVisibility = (
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
)
|
||||
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
|
||||
controller.systemBarsBehavior =
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
controller.hide(WindowInsetsCompat.Type.systemBars())
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun Activity.hideStatusBar() {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
fun Activity.setNavigationTheme() {
|
||||
val a = TypedValue()
|
||||
theme.resolveAttribute(android.R.attr.colorBackground, a, true)
|
||||
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && a.isColorType)
|
||||
|| (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT)) {
|
||||
window.navigationBarColor = a.data
|
||||
}
|
||||
}
|
||||
|
||||
open class BottomSheetDialogFragment : BottomSheetDialogFragment() {
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
val window = dialog?.window
|
||||
val decorView: View = window?.decorView ?: return
|
||||
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
if (this.resources.configuration.orientation != Configuration.ORIENTATION_PORTRAIT) {
|
||||
val behavior = BottomSheetBehavior.from(requireView().parent as View)
|
||||
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
dialog?.window?.let { window ->
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
val immersiveMode: Boolean = PrefManager.getVal(PrefName.ImmersiveMode)
|
||||
if (immersiveMode) {
|
||||
WindowInsetsControllerCompat(
|
||||
window, window.decorView
|
||||
).hide(WindowInsetsCompat.Type.statusBars())
|
||||
}
|
||||
if (this.resources.configuration.orientation != Configuration.ORIENTATION_PORTRAIT) {
|
||||
val behavior = BottomSheetBehavior.from(requireView().parent as View)
|
||||
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
val typedValue = TypedValue()
|
||||
val theme = requireContext().theme
|
||||
theme.resolveAttribute(
|
||||
com.google.android.material.R.attr.colorSurface,
|
||||
typedValue,
|
||||
true
|
||||
)
|
||||
window.navigationBarColor = typedValue.data
|
||||
}
|
||||
val typedValue = TypedValue()
|
||||
val theme = requireContext().theme
|
||||
theme.resolveAttribute(
|
||||
com.google.android.material.R.attr.colorSurface,
|
||||
typedValue,
|
||||
true
|
||||
)
|
||||
window.navigationBarColor = typedValue.data
|
||||
}
|
||||
|
||||
override fun show(manager: FragmentManager, tag: String?) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue