Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Scrolling PlayerFragment sheet vertically is awkward #125

Closed
squivix opened this issue Jul 22, 2021 · 10 comments · Fixed by #188
Closed

Scrolling PlayerFragment sheet vertically is awkward #125

squivix opened this issue Jul 22, 2021 · 10 comments · Fixed by #188
Assignees
Labels
bug Something isn't working

Comments

@squivix
Copy link
Collaborator

squivix commented Jul 22, 2021

Describe the bug
Due to the newly added viewpager in PlayerFragment, the bottom sheet that the whole fragment is on is not scrolling very well. If you start scrolling vertically where the ViewPager is, it doesn't register. ViewPagers and BottomSheets don't work well together, so it seems this is a common problem.

To Reproduce
Steps to reproduce the behavior:

  1. Open app
  2. Click on song to open PlayerFragment
  3. Try to duck down the bottomsheet that pops up by dragging from the center (where the album art and song title go)
  4. Notice scrolling doesn't work until you reach the bottom where the ViewPager ends
@Benji377 Benji377 added the bug Something isn't working label Jul 25, 2021
@Benji377 Benji377 added this to To Do in Exceptions and Bugs via automation Jul 25, 2021
@Benji377 Benji377 moved this from To Do to In progress in Exceptions and Bugs Jul 25, 2021
@Benji377
Copy link
Owner

If you try to drag it down from anywhere else than where the somg thumbnail or title is it works just fine. I think it has something do to with the new viewpager that has been added recently. It probably only accepts left and right swipes so you need to add a listener for down swipes too.

@Benji377
Copy link
Owner

Looking at this tutorial it seems like a Viewpager2 can get top to bottom swipes. So then there was this guy which had a similar problem I think. Another similar problem could be this one.
It just seems like the Viewpager2 only accepts one direction, either horizontally or vertically, not both at the same time.

Another solution we might try is to always prioritize top to bottom swipes to Viewpager2 swipes. We would need to check if the user is swiping downwards and if he is, lock the Viewpager and make him move downwards, else unlock the viewpager2.

@Benji377
Copy link
Owner

Actually, check this out:

  1. Edit the Viewpager2 code in fragment_player.xml to this:
        <androidx.viewpager2.widget.ViewPager2
            android:id="@+id/viewpager_player_song"
            android:layout_width="match_parent"
            android:layout_height="325dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="75dp"
            android:orientation="vertical"/>
  1. Start the emulator or whatever and go to the first song. Click on it
  2. Now that the Playerfragment showed up, try to swipe up and down and it will change the songs as normal
  3. BUT if you are on the first song and try to swipe any further, the Viewpager2 does exactly what we want it to do:
  4. The whole playerfragment gets dragged along because the Viwpager2 can't go any further.

@squivix
Copy link
Collaborator Author

squivix commented Aug 15, 2021

I'm pretty sure the solution isn't to change the scrolling direction of the viewpager2 but to somehow make it pass vertical scrolling to its container.

@Benji377
Copy link
Owner

But we still need something like a swipe listener to check for vertical swipes, right?

@Benji377
Copy link
Owner

Benji377 commented Sep 1, 2021

This might be a solution? Stackoverflow Or maybe this one is probably a better one

@squivix
Copy link
Collaborator Author

squivix commented Sep 3, 2021

This might be a solution? Stackoverflow Or maybe this one is probably a better one

The first one is using ViewPager instead of ViewPager2. The second one I already tried.

@squivix
Copy link
Collaborator Author

squivix commented Sep 3, 2021

Ok I asked around the discord servers and someone helped me out with it. His solution was to access the RecyclerView inside the ViewPager2 and disable its nested scrolling with a Kotlin extension function:

    fun ViewPager2.disableNestedScrolling() {
        (getChildAt(0) as? RecyclerView)?.apply {
            isNestedScrollingEnabled = false
            overScrollMode = View.OVER_SCROLL_NEVER
        }
    }

Unfortunately it meant I had to convert the CustomViewPager2 class to Kotlin, which I don't speak. Still it's worth it. Although you'll have to download a Kotlin plugin to compile. I wanna learn Kotlin some day anyway.

EDIT: I'll commit after PR #186 is tested and merged.

@Benji377
Copy link
Owner

Benji377 commented Sep 3, 2021

Damn this bug is hard to get rid off. I have never coded a line in Kotlin, this is also the reason why the app is in Java. I really hope it works.

@squivix
Copy link
Collaborator Author

squivix commented Sep 3, 2021

Good news! I managed to get it to work in Java! So forget the last update.

squivix pushed a commit to squivix/SocyMusic that referenced this issue Sep 3, 2021
@squivix squivix linked a pull request Sep 3, 2021 that will close this issue
Exceptions and Bugs automation moved this from In progress to Done Sep 3, 2021
squivix added a commit that referenced this issue Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants