-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ViewPager2 swipe support #368
Add ViewPager2 swipe support #368
Conversation
Pinging some of the maintainers to see that you at least have noticed this PR |
Hi @daniellAlgar! Thanks for the PR and for the ping! I saw the notification but it got lost in my inbox, sorry 😭 The approach you mentioned is fine by me if there's no other easy option. Let me take a look at the code to make sure there's nothing too weird :) |
Thank you @Sloy . There's no rush! I just wanted to make sure it wasn't getting forgotten :) |
@@ -43,6 +55,12 @@ object SwipeActions { | |||
NormalizedLocation(from.first, from.second), | |||
NormalizedLocation(to.first, to.second), | |||
Press.FINGER)) | |||
|
|||
@JvmStatic | |||
fun swipeViewPager2Forward(): ViewAction = ViewPager2SwipeAction(direction = FORWARD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just thinking...
Should we add viewpager2 as part of viewpager swipe? aas other methods on barista do for list and recyclers for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. It's just that swiping a ViewPager2 is a bit more complicated than swiping the old ViewPager, since ViewPager2 supports both horizontal/vertical directions (plus we always have "right-to-left" layout to consider).
So if I were to add ViewPager2 directly in SwipeActions.swipe(from: Pair<..>, to: Pair<..>)
I would have to figure out the pairs even before getting to this call. And that would make it even worse than what I have done today I think 🤷♂️
Now it is still the case that the user only do swipeViewPagerForward/Back()
regardless of which view pager is being used.
But maybe I misunderstood your comment or I haven't thought this through enough :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good. Thanks for the explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just add this even if it might be obvious. But a "swipe forward" means different things in ViewPager2 depending on the horizontal/vertical orientation of it. That's what I was trying to say above :)
assertDisplayed("1") | ||
} | ||
|
||
/** Helper function */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the comment. But it's not an stopper to approve the PR, of course 😄
It looks great to me. Thanks for the contribution, @daniellAlgar ! 👏 |
Yes for me @rocboronat . Go for it |
Yes!! |
🎉 |
Thank you all :) |
Released on 3.7.0 release |
Hello!
This PR will add swipe support for ViewPager2.
It will use the exact same API as the current
swipeViewPagerForward()
andswipeViewPagerBack()
but will automatically use the available ViewPager/ViewPager2.I ended up with a few nested
try/catch
which I'm not proud of. Please give input on it if you have a better solution. But I did see that you already have this pattern in the code base (e.g.BaristaListAssertions
) so I thought I'd give it a try.Best regards,
Daniell Algar