react-native-pager-view icon indicating copy to clipboard operation
react-native-pager-view copied to clipboard

Strange values of the "offset" property in the "onPageScroll" method.

Open AndrewNes opened this issue 3 years ago • 2 comments

Environment

"react": "17.0.2", "react-native": "0.66.4", "react-native-pager-view": "^6.2.0"

Description

Good afternoon! Initially, I want to thank you for creating such a wonderful library. It covers a lot of tasks in my projects, but I have difficulties with setting up the parallax effect.

Since the offset property cannot have a negative value in the "onPageScroll" method. During which I can't determine the swipe side (backward or forward).

In addition, when I swipe back, the value is not something that does not become less than 0, but also turns into 0.99 by the moment, which is why any animation moves in leaps.

1 offset = (0.000, 0.100, 0.320, ..., 1.000)

2 offset = (0.000, 0.990, 0.800, ..., 0.000)

This does not allow the use of animation of this kind:

  const onPageScroll = usePagerScrollHandler<onPageScrollEventType>(
    {
      onPageScroll: (e: onPageScrollEventType): void => {
        'worklet';
       // ...
        opacityValue.value = 1 - e.offset;
       // ...
      },
    },
    'onPageScroll'
  )

After my research, I found a place to calculate this value on iOS: 3-screen (../node_modules/react-native-pager-view/ios/ReactNativePageView.m)

However, I have not found where to fix it in Android, are there any solutions to my problem?

Sincerely, Andrey!

AndrewNes avatar Jul 28 '23 17:07 AndrewNes

I'm sorry! I didn't notice a change in the "position" property at the time of scrolling back. If we take it into account, then the creation of animations is more than real ... And even despite this, the "offset" property has non-trivial values)

AndrewNes avatar Jul 28 '23 17:07 AndrewNes

@AndrewNes please checkout one of our example here https://github.com/callstack/react-native-pager-view/blob/master/example/src/HeadphonesCarouselExample.tsx . I was not able to reproduce this issue. In case of noticed bug, please create a new issue with the full description.

troZee avatar Dec 05 '24 12:12 troZee