mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-13 20:48:56 +01:00
More bottom sheet improvements (#5183)
* Edge-to-edge bottom sheet when possible * ReaderSettingsSheet: Animate background dim changes * Adjust modal bottom sheet in-out animation * Use public method to get bottom sheet behavior * Set bottom sheet peek size to 50% screen height The current auto peek height gives too low value on landscape orientation * Set bottom sheet navigation bar scrim when needed
This commit is contained in:
@@ -33,7 +33,7 @@ class SourceFilterSheet(
|
||||
|
||||
override fun show() {
|
||||
super.show()
|
||||
sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
|
||||
fun setFilters(items: List<IFlexible<*>>) {
|
||||
|
||||
@@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.ui.main
|
||||
|
||||
import android.app.SearchManager
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
@@ -52,9 +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 eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@@ -119,14 +116,7 @@ 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.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, 0.7F)
|
||||
}
|
||||
window.setNavigationBarTransparentCompat(this)
|
||||
}
|
||||
insets
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class TrackSheet(
|
||||
override fun show() {
|
||||
super.show()
|
||||
controller.presenter.refreshTrackers()
|
||||
sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
|
||||
fun onNextTrackers(trackers: List<TrackItem>) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.setting
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.os.Bundle
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import eu.kanade.tachiyomi.R
|
||||
@@ -16,13 +17,21 @@ class ReaderSettingsSheet(
|
||||
private val generalSettings = ReaderGeneralSettings(activity)
|
||||
private val colorFilterSettings = ReaderColorFilterSettings(activity)
|
||||
|
||||
private val backgroundDimAnimator by lazy {
|
||||
val sheetBackgroundDim = window?.attributes?.dimAmount ?: 0.25f
|
||||
ValueAnimator.ofFloat(sheetBackgroundDim, 0f).also { valueAnimator ->
|
||||
valueAnimator.duration = 250
|
||||
valueAnimator.addUpdateListener {
|
||||
window?.setDimAmount(it.animatedValue as Float)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
sheetBehavior.isFitToContents = false
|
||||
sheetBehavior.halfExpandedRatio = 0.25f
|
||||
|
||||
val sheetBackgroundDim = window?.attributes?.dimAmount ?: 0.25f
|
||||
behavior.isFitToContents = false
|
||||
behavior.halfExpandedRatio = 0.25f
|
||||
|
||||
val filterTabIndex = getTabViews().indexOf(colorFilterSettings)
|
||||
binding.tabs.addOnTabSelectedListener(object : SimpleTabSelectedListener() {
|
||||
@@ -30,7 +39,15 @@ class ReaderSettingsSheet(
|
||||
val isFilterTab = tab?.position == filterTabIndex
|
||||
|
||||
// Remove dimmed backdrop so color filter changes can be previewed
|
||||
window?.setDimAmount(if (isFilterTab) 0f else sheetBackgroundDim)
|
||||
backgroundDimAnimator.run {
|
||||
if (isFilterTab) {
|
||||
if (animatedFraction < 1f) {
|
||||
start()
|
||||
}
|
||||
} else if (animatedFraction > 0f) {
|
||||
reverse()
|
||||
}
|
||||
}
|
||||
|
||||
// Hide toolbars
|
||||
if (activity.menuVisible != !isFilterTab) {
|
||||
|
||||
Reference in New Issue
Block a user