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 isDarkMode: Boolean by lazy {
|
||||
private val isDarkMode: Boolean by lazy {
|
||||
val themeMode = preferences.themeMode().get()
|
||||
(themeMode == Values.ThemeMode.dark) ||
|
||||
(
|
||||
|
@ -24,7 +24,6 @@ import com.bluelinelabs.conductor.Router
|
||||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
|
||||
import dev.chrisbanes.insetter.Insetter
|
||||
import dev.chrisbanes.insetter.applyInsetter
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
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.util.lang.launchIO
|
||||
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 kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@ -103,33 +104,27 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
margin(top = true)
|
||||
}
|
||||
}
|
||||
binding.rootFab.applyInsetter {
|
||||
type(navigationBars = true) {
|
||||
margin()
|
||||
}
|
||||
}
|
||||
binding.bottomNav.applyInsetter {
|
||||
type(navigationBars = true) {
|
||||
padding()
|
||||
}
|
||||
}
|
||||
Insetter.builder()
|
||||
.consume(Insetter.CONSUME_ALL)
|
||||
.setOnApplyInsetsListener { view, insets, _ ->
|
||||
val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
view.isVisible = systemInsets.bottom > 0
|
||||
view.updateLayoutParams<ViewGroup.LayoutParams> {
|
||||
height = systemInsets.bottom
|
||||
}
|
||||
binding.rootFab.applyInsetter {
|
||||
type(navigationBars = true) {
|
||||
margin()
|
||||
}
|
||||
.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 ->
|
||||
if (insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom > 0) {
|
||||
// Keep scrim on light theme if windowLightNavigationBar is not available
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 || isDarkMode) {
|
||||
window.navigationBarColor = Color.TRANSPARENT
|
||||
window.navigationBarColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
|
||||
!InternalResourceHelper.getBoolean(this, "config_navBarNeedsScrim", true)
|
||||
) {
|
||||
Color.TRANSPARENT
|
||||
} else {
|
||||
// Set navbar scrim 70% of navigationBarColor
|
||||
getResourceColor(android.R.attr.navigationBarColor, .7F)
|
||||
}
|
||||
}
|
||||
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: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>
|
||||
|
@ -201,7 +201,7 @@
|
||||
<item name="android:colorBackground">@color/colorAmoledPrimary</item>
|
||||
|
||||
<!-- 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-->
|
||||
<item name="colorLibrarySelection">@color/selectorColorDark</item>
|
||||
|
Loading…
Reference in New Issue
Block a user