photo-compose icon indicating copy to clipboard operation
photo-compose copied to clipboard

fix: fixed error in judgement when offset is zero

Open 0xZhangKe opened this issue 1 year ago • 6 comments

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.

0xZhangKe avatar Sep 03 '23 12:09 0xZhangKe

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 avatar Sep 03 '23 12:09 0xZhangKe

@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 avatar Sep 07 '23 14:09 fornewid

@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. image

As shown above.

0xZhangKe avatar Sep 12 '23 13:09 0xZhangKe

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 avatar Sep 12 '23 13:09 0xZhangKe

@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:

fornewid avatar Sep 16 '23 07:09 fornewid

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.

0xZhangKe avatar Sep 18 '23 02:09 0xZhangKe