about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorgpp <52042597+gpp-0@users.noreply.github.com>2025-01-17 04:02:59 +0200
committerGitHub <noreply@github.com>2025-01-17 02:02:59 +0000
commit5130d19ebdb3267f58e2b6407eb5c4f95107887c (patch)
tree9be2247941dfee1cd7a3b9a8f935103a0e73a699 /src
parent9e3f2f43745eed9c71cb985e48135b7363d91aa9 (diff)
downloadvoidsky-5130d19ebdb3267f58e2b6407eb5c4f95107887c.tar.zst
[Android] Fix taps triggering while swiping (#7459)
* [Android] Fix taps triggering while swiping

* Revert "[Android] Try to disambiguate taps from swipes (#7448)"

This reverts commit 96054f4addb63994b3d2f5fe1d288f4dd3c246c2.

* Update patch to match callstack/react-native-pager-view#961

* Make it symmetrical

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/view/com/pager/Pager.tsx42
1 files changed, 2 insertions, 40 deletions
diff --git a/src/view/com/pager/Pager.tsx b/src/view/com/pager/Pager.tsx
index 772cb1715..f62bffc53 100644
--- a/src/view/com/pager/Pager.tsx
+++ b/src/view/com/pager/Pager.tsx
@@ -1,4 +1,4 @@
-import React, {Children, forwardRef, useCallback, useContext} from 'react'
+import React, {forwardRef, useCallback, useContext} from 'react'
 import {View} from 'react-native'
 import {DrawerGestureContext} from 'react-native-drawer-layout'
 import {Gesture, GestureDetector} from 'react-native-gesture-handler'
@@ -17,7 +17,6 @@ import Animated, {
 } from 'react-native-reanimated'
 import {useFocusEffect} from '@react-navigation/native'
 
-import {isAndroid} from '#/platform/detection'
 import {useSetDrawerSwipeDisabled} from '#/state/shell'
 import {atoms as a, native} from '#/alf'
 
@@ -149,11 +148,7 @@ export const Pager = forwardRef<PagerRef, React.PropsWithChildren<Props>>(
             style={[a.flex_1]}
             initialPage={initialPage}
             onPageScroll={handlePageScroll}>
-            {isAndroid
-              ? Children.map(children, child => (
-                  <CaptureSwipesAndroid>{child}</CaptureSwipesAndroid>
-                ))
-              : children}
+            {children}
           </AnimatedPagerView>
         </GestureDetector>
       </View>
@@ -161,39 +156,6 @@ export const Pager = forwardRef<PagerRef, React.PropsWithChildren<Props>>(
   },
 )
 
-// HACK.
-// This works around https://github.com/callstack/react-native-pager-view/issues/960.
-// It appears that the Pressables inside the pager get confused if there's enough work
-// happening on the JS thread, and mistakingly interpret a pager swipe as a tap.
-// We can prevent this by stealing all horizontal movements from the tree inside.
-function CaptureSwipesAndroid({children}: {children: React.ReactNode}) {
-  const lastTouchStart = React.useRef<{x: number; y: number} | null>(null)
-  return (
-    <View
-      onTouchStart={e => {
-        lastTouchStart.current = {
-          x: e.nativeEvent.pageX,
-          y: e.nativeEvent.pageY,
-        }
-      }}
-      onMoveShouldSetResponderCapture={e => {
-        const coords = lastTouchStart.current
-        if (!coords) {
-          return false
-        }
-        const dx = Math.abs(e.nativeEvent.pageX - coords.x)
-        if (dx > 0) {
-          // This is a horizontal movement and will result in a swipe.
-          // Prevent pager children from receiving this touch.
-          return true
-        }
-        return false
-      }}>
-      {children}
-    </View>
-  )
-}
-
 function usePagerHandlers(
   handlers: {
     onPageScroll: (e: PagerViewOnPageScrollEventData) => void