Apply elevation overlay to colored navbar (#6308)

This commit is contained in:
Ivan Iskandar 2021-12-04 21:57:02 +07:00 committed by GitHub
parent 32f3a50def
commit 458a0e608a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 4 deletions

View file

@ -0,0 +1,10 @@
package com.google.android.material.bottomsheet
import android.view.View
/**
* Returns package-private elevation value
*/
fun <T : View> BottomSheetBehavior<T>.getElevation(): Float {
return elevation.takeIf { it >= 0F } ?: 0F
}

View file

@ -279,7 +279,8 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
// Make sure navigation bar is on bottom before we modify it
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets ->
if (insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom > 0) {
window.setNavigationBarTransparentCompat(this@MainActivity)
val elevation = binding.bottomNav?.elevation ?: 0F
window.setNavigationBarTransparentCompat(this@MainActivity, elevation)
}
insets
}

View file

@ -5,6 +5,7 @@ import android.graphics.Color
import android.os.Build
import android.view.Window
import android.view.WindowManager
import com.google.android.material.elevation.ElevationOverlayProvider
import eu.kanade.tachiyomi.util.system.InternalResourceHelper
import eu.kanade.tachiyomi.util.system.getResourceColor
@ -12,14 +13,17 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
* Sets navigation bar color to transparent if system's config_navBarNeedsScrim is false,
* otherwise it will use the theme navigationBarColor with 70% opacity.
*/
fun Window.setNavigationBarTransparentCompat(context: Context) {
fun Window.setNavigationBarTransparentCompat(context: Context, elevation: Float = 0F) {
navigationBarColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
!InternalResourceHelper.getBoolean(context, "config_navBarNeedsScrim", true)
) {
Color.TRANSPARENT
} else {
// Set navbar scrim 70% of navigationBarColor
context.getResourceColor(android.R.attr.navigationBarColor, 0.7F)
ElevationOverlayProvider(context).compositeOverlayIfNeeded(
context.getResourceColor(android.R.attr.navigationBarColor, 0.7F),
elevation
)
}
}

View file

@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.getElevation
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.displayCompat
import eu.kanade.tachiyomi.util.system.isNightMode
@ -40,7 +41,7 @@ abstract class BaseBottomSheetDialog(context: Context) : BottomSheetDialog(conte
// TODO Replace deprecated systemUiVisibility when material-components uses new API to modify status bar icons
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
window?.setNavigationBarTransparentCompat(context)
window?.setNavigationBarTransparentCompat(context, behavior.getElevation())
val bottomSheet = rootView.parent as ViewGroup
var flags = bottomSheet.systemUiVisibility
flags = if (context.isNightMode()) {