ui: fix bottom sheet initialization
Fix an issue on some devices where bottom sheet transitions would not initialize correctly. Turns out I can't try to do transitions using the callback and simply initalizing them on startup. Apparently on some devices, CoordinatorLayout will simply not lay out until some arbitrary point past onResume. This breaks our transitions. Fix it by using a pre-draw listener instead. I cannot believe I have to do this.
This commit is contained in:
parent
a4fa8a84fa
commit
5536dd48df
2 changed files with 13 additions and 19 deletions
|
@ -506,6 +506,8 @@ public class NeoBottomSheetBehavior<V extends View> extends CoordinatorLayout.Be
|
|||
}
|
||||
|
||||
if (viewRef == null) {
|
||||
|
||||
Log.d("NeoBottomSheetBehavior", "Lay out time");
|
||||
// First layout with this behavior.
|
||||
peekHeightMin =
|
||||
parent.getResources().getDimensionPixelSize(R.dimen.design_bottom_sheet_peek_height_min);
|
||||
|
@ -1076,6 +1078,7 @@ public class NeoBottomSheetBehavior<V extends View> extends CoordinatorLayout.Be
|
|||
*/
|
||||
public float calculateSlideOffset() {
|
||||
if (viewRef == null) {
|
||||
Log.d("NeoBottomSheetBehavior", "No view ref");
|
||||
return Float.MIN_VALUE;
|
||||
}
|
||||
|
||||
|
@ -1084,6 +1087,8 @@ public class NeoBottomSheetBehavior<V extends View> extends CoordinatorLayout.Be
|
|||
return calculateSlideOffset(bottomSheet.getTop());
|
||||
}
|
||||
|
||||
Log.d("NeoBottomSheetBehavior", "No bottom sheet");
|
||||
|
||||
return Float.MIN_VALUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,23 +75,11 @@ class MainFragment : ViewBindingFragment<FragmentMainBinding>() {
|
|||
|
||||
val playbackSheetBehavior =
|
||||
binding.playbackSheet.coordinatorLayoutBehavior as PlaybackSheetBehavior
|
||||
|
||||
playbackSheetBehavior.addBottomSheetCallback(
|
||||
object : NeoBottomSheetBehavior.BottomSheetCallback() {
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
||||
handleSheetTransitions()
|
||||
}
|
||||
|
||||
override fun onStateChanged(bottomSheet: View, newState: Int) {}
|
||||
})
|
||||
|
||||
val queueSheetBehavior = binding.queueSheet.coordinatorLayoutBehavior as QueueSheetBehavior
|
||||
|
||||
queueSheetBehavior.addBottomSheetCallback(
|
||||
object : NeoBottomSheetBehavior.BottomSheetCallback() {
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
||||
handleSheetTransitions()
|
||||
}
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
|
||||
|
||||
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||
playbackSheetBehavior.isDraggable =
|
||||
|
@ -100,11 +88,13 @@ class MainFragment : ViewBindingFragment<FragmentMainBinding>() {
|
|||
}
|
||||
})
|
||||
|
||||
binding.root.post {
|
||||
// We would use the onSlide callback, but doing that would require us to initialize
|
||||
// when the view first starts up, and that may not always work due to the insanity of
|
||||
// the CoordinatorLayout lifecycle. Instead, do the less efficient alternative of updating
|
||||
// the transition on every redraw.
|
||||
binding.playbackSheet.viewTreeObserver.addOnPreDrawListener {
|
||||
handleSheetTransitions()
|
||||
playbackSheetBehavior.isDraggable =
|
||||
!playbackSheetBehavior.isHideable &&
|
||||
queueSheetBehavior.state == BottomSheetBehavior.STATE_COLLAPSED
|
||||
true
|
||||
}
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
@ -164,8 +154,7 @@ class MainFragment : ViewBindingFragment<FragmentMainBinding>() {
|
|||
|
||||
private fun handleMainNavigation(action: MainNavigationAction?) {
|
||||
if (action == null) return
|
||||
|
||||
val binding = requireBinding()
|
||||
|
||||
when (action) {
|
||||
is MainNavigationAction.Expand -> tryExpandAll()
|
||||
is MainNavigationAction.Collapse -> tryCollapseAll()
|
||||
|
|
Loading…
Reference in a new issue