From 458a0e608ac9cff97e8152f1a6f9bb4242b69dc2 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 4 Dec 2021 21:57:02 +0700 Subject: [PATCH] Apply elevation overlay to colored navbar (#6308) --- .../bottomsheet/BottomSheetBehaviorExtensions.kt | 10 ++++++++++ .../java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 3 ++- .../eu/kanade/tachiyomi/util/view/WindowExtensions.kt | 8 ++++++-- .../tachiyomi/widget/sheet/BaseBottomSheetDialog.kt | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/google/android/material/bottomsheet/BottomSheetBehaviorExtensions.kt diff --git a/app/src/main/java/com/google/android/material/bottomsheet/BottomSheetBehaviorExtensions.kt b/app/src/main/java/com/google/android/material/bottomsheet/BottomSheetBehaviorExtensions.kt new file mode 100644 index 0000000000..aba4d99608 --- /dev/null +++ b/app/src/main/java/com/google/android/material/bottomsheet/BottomSheetBehaviorExtensions.kt @@ -0,0 +1,10 @@ +package com.google.android.material.bottomsheet + +import android.view.View + +/** + * Returns package-private elevation value + */ +fun BottomSheetBehavior.getElevation(): Float { + return elevation.takeIf { it >= 0F } ?: 0F +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index b972b1243f..d805543689 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -279,7 +279,8 @@ class MainActivity : BaseViewBindingActivity() { // 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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/WindowExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/WindowExtensions.kt index e3f8724a23..98dd588d5f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/WindowExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/WindowExtensions.kt @@ -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 + ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/sheet/BaseBottomSheetDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/sheet/BaseBottomSheetDialog.kt index 202dc78fd6..d19623525a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/sheet/BaseBottomSheetDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/sheet/BaseBottomSheetDialog.kt @@ -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()) {