Add navigation bar scrim (#4845)
* Revert "Add navigation bar scrim (closes #4836)"
This reverts commit 2a69d1b0
* Add navigation bar scrim
This commit is contained in:
parent
b4577d6676
commit
1f729f1cb3
@ -13,7 +13,7 @@ abstract class BaseThemedActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
val preferences: PreferencesHelper by injectLazy()
|
val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
val isDarkMode: Boolean by lazy {
|
private val isDarkMode: Boolean by lazy {
|
||||||
val themeMode = preferences.themeMode().get()
|
val themeMode = preferences.themeMode().get()
|
||||||
(themeMode == Values.ThemeMode.dark) ||
|
(themeMode == Values.ThemeMode.dark) ||
|
||||||
(
|
(
|
||||||
|
@ -24,7 +24,6 @@ import com.bluelinelabs.conductor.Router
|
|||||||
import com.bluelinelabs.conductor.RouterTransaction
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
|
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
|
||||||
import dev.chrisbanes.insetter.Insetter
|
|
||||||
import dev.chrisbanes.insetter.applyInsetter
|
import dev.chrisbanes.insetter.applyInsetter
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.Migrations
|
import eu.kanade.tachiyomi.Migrations
|
||||||
@ -51,6 +50,8 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController
|
|||||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
|
import eu.kanade.tachiyomi.util.system.InternalResourceHelper
|
||||||
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
@ -103,33 +104,27 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
margin(top = true)
|
margin(top = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.rootFab.applyInsetter {
|
|
||||||
type(navigationBars = true) {
|
|
||||||
margin()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binding.bottomNav.applyInsetter {
|
binding.bottomNav.applyInsetter {
|
||||||
type(navigationBars = true) {
|
type(navigationBars = true) {
|
||||||
padding()
|
padding()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Insetter.builder()
|
binding.rootFab.applyInsetter {
|
||||||
.consume(Insetter.CONSUME_ALL)
|
type(navigationBars = true) {
|
||||||
.setOnApplyInsetsListener { view, insets, _ ->
|
margin()
|
||||||
val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
|
||||||
view.isVisible = systemInsets.bottom > 0
|
|
||||||
view.updateLayoutParams<ViewGroup.LayoutParams> {
|
|
||||||
height = systemInsets.bottom
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.applyToView(binding.navigationScrim)
|
}
|
||||||
|
|
||||||
// Make sure navigation bar is on bottom when making it transparent
|
// Make sure navigation bar is on bottom before we modify it
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets ->
|
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets ->
|
||||||
if (insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom > 0) {
|
if (insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom > 0) {
|
||||||
// Keep scrim on light theme if windowLightNavigationBar is not available
|
window.navigationBarColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 || isDarkMode) {
|
!InternalResourceHelper.getBoolean(this, "config_navBarNeedsScrim", true)
|
||||||
window.navigationBarColor = Color.TRANSPARENT
|
) {
|
||||||
|
Color.TRANSPARENT
|
||||||
|
} else {
|
||||||
|
// Set navbar scrim 70% of navigationBarColor
|
||||||
|
getResourceColor(android.R.attr.navigationBarColor, .7F)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insets
|
insets
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package eu.kanade.tachiyomi.util.system
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.Resources
|
||||||
|
|
||||||
|
object InternalResourceHelper {
|
||||||
|
/**
|
||||||
|
* Get resource id from system resources
|
||||||
|
* @param resName resource name to get
|
||||||
|
* @param type resource type of [resName] to get
|
||||||
|
* @return 0 if not available
|
||||||
|
*/
|
||||||
|
private fun getResourceId(resName: String, type: String): Int {
|
||||||
|
return Resources.getSystem().getIdentifier(resName, type, "android")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBoolean(context: Context, resName: String, defaultValue: Boolean): Boolean {
|
||||||
|
val id = getResourceId(resName, "bool")
|
||||||
|
return if (id != 0) {
|
||||||
|
context.createPackageContext("android", 0).resources.getBoolean(id)
|
||||||
|
} else {
|
||||||
|
defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -91,17 +91,4 @@
|
|||||||
app:layout_insetEdge="bottom"
|
app:layout_insetEdge="bottom"
|
||||||
app:menu="@menu/bottom_nav" />
|
app:menu="@menu/bottom_nav" />
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/navigation_scrim"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:alpha="0.5"
|
|
||||||
android:background="?android:attr/navigationBarColor"
|
|
||||||
android:clickable="false"
|
|
||||||
android:focusable="false"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:layout_height="?attr/actionBarSize"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
@ -201,7 +201,7 @@
|
|||||||
<item name="android:colorBackground">@color/colorAmoledPrimary</item>
|
<item name="android:colorBackground">@color/colorAmoledPrimary</item>
|
||||||
|
|
||||||
<!-- Some ROMs make black navbars white (e.g. OxygenOS) -->
|
<!-- Some ROMs make black navbars white (e.g. OxygenOS) -->
|
||||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
<item name="android:navigationBarColor">#000001</item>
|
||||||
|
|
||||||
<!-- Custom Attributes-->
|
<!-- Custom Attributes-->
|
||||||
<item name="colorLibrarySelection">@color/selectorColorDark</item>
|
<item name="colorLibrarySelection">@color/selectorColorDark</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user