photo-compose
photo-compose copied to clipboard
fix: fixed error in judgement when offset is zero
When I use it in conjunction HorizontalPager, I've found that sometimes swiping left or right doesn't work.
After some troubleshooting, I found that the problem occurs when the Offset is judged to be zero.
The currentOffset
maybe get -0.0F
value, even though -0.0F == 0.0F
, but Offset(-0F, 0.F) != Offset(0F, 0F)
.
This is a problem caused by the algorithm of the packFloats
function.
So we can only determine if Offset is 0 by looking at the x and y values.
Looks like PhotoBoxInPagerDemo is correct!
I'm guessing it might be an inconsistency in the version of HorizontalPager, which I'm using compose foundation HorizontalPager.
@0xZhangKe First, thanks for reporting! 😃 Recently I've been focusing on preparing a presentation. So, sorry for the late.
Could you please provide the example code and video that reproduces it?
@fornewid I've created a demo branch to reproduce the problem. https://github.com/0xZhangKe/photo-compose/tree/pager_test
Also you can see this screenshot.
As shown above.
Also, I found one more thing about Pager, If you run the code in the demo branch above, you'll notice that you can't swipe left or right. It looks like this is caused by a sliding conflict between Pager and PhotoBox.
transformable
function will consume this MotionEvent, so Pager can't drag.
I've taken a more ad hoc approach in one of my other projects by providing a transformable
function that doesn't consume events.
@0xZhangKe
Thank you for reporting the scrolling issue that occurred when using compose foundation's Pager
.
I'll check that again. 👍 👍 👍
And I have a question about the -0.0F
value issue.
I couldn't reproduce this issue.
Could you please explain the reproducible path in more detail? :bow:
Okay, first run the code of the branch I posted in the previous comment.
Then continue to quickly slide the pictures in the app left and right.
At this time, open logcat and you can see the situation in the picture above.
It can be seen that even if the x and y of Offset are both 0, it is still not equal to Offset.Zero.