Skip to content
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

onPageScroll not update position when handle by two touch (IOS) #832

Open
jameheller98 opened this issue Jun 18, 2024 · 4 comments
Open

Comments

@jameheller98
Copy link

Environment

product, develop

Description

When keep scroll by first touch and use another touch to scroll to next page, page is keep position but onPageScroll return props "position" not updated and return to 0

Reproducible Demo

IMG_4125.MP4
@MrRefactor
Copy link
Collaborator

What version of library and react native are you using? Can you reproduce the issue in example app?

@jameheller98
Copy link
Author

jameheller98 commented Jun 21, 2024

react-native-pager-view: 6.3.1
react-native: 0.73.6

I have expo test, you can check here: https://snack.expo.dev/@jameheller98/test-gesture
I have another problem is can not use react-native-gesture-handler in PagerView, you can help me something error here! Thank you very much

@MrRefactor
Copy link
Collaborator

Please reproduce it on example app, as in the snack you provided you used nested TabView component inside another TabView.

@jameheller98
Copy link
Author

jameheller98 commented Jun 26, 2024

@MrRefactor
Okay in problem first I think its small bug and with experiences of user its okay and its only hard with my tester.

  • With problem react native gesture handle I have found reason get GestureDetector in react-native-gesture-handler not work.
    And I Found code in here:

NestedScrollableHost.kt

private fun handleInterceptTouchEvent(e: MotionEvent) {
    val orientation = parentViewPager?.orientation ?:  return

    if (!canChildScroll(orientation, -1f) && !canChildScroll(orientation, 1f)) {
      return
    }

    if (e.action == MotionEvent.ACTION_DOWN && isPreventScrollGesture) {
      initialX = e.x
      initialY = e.y
      parent.requestDisallowInterceptTouchEvent(true)
    } else if (e.action == MotionEvent.ACTION_MOVE && isPreventScrollGesture) {
      val dx = e.x - initialX
      val dy = e.y - initialY
      val isVpHorizontal = orientation == ORIENTATION_HORIZONTAL

      val scaledDx = dx.absoluteValue * if (isVpHorizontal) .5f else 1f
      val scaledDy = dy.absoluteValue * if (isVpHorizontal) 1f else .5f

      if (scaledDx > touchSlop || scaledDy > touchSlop) {
        if (isVpHorizontal == (scaledDy > scaledDx)) {
          // Here is reason 
          parent.requestDisallowInterceptTouchEvent(false)
        } else {
          if (canChildScroll(orientation, if (isVpHorizontal) dx else dy)) {
            parent.requestDisallowInterceptTouchEvent(true)
          } else {
            // Here is reason 
            parent.requestDisallowInterceptTouchEvent(false)
          }
        }
      }
    }
  }

You can check here why when I nested tabview and tabview nested cannot use react-native-gesture-handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants