Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "[Android] Fix taps triggering while swiping (#7459)" (#7498)

This reverts commit 5130d19ebdb3267f58e2b6407eb5c4f95107887c.

authored by

dan and committed by
GitHub
cb020655 3e0ac0a0

+40 -74
-72
patches/react-native-pager-view+6.6.1.patch
··· 1 - diff --git a/node_modules/react-native-pager-view/android/build/tmp/kotlin-classes/debug/com/reactnativepagerview/NestedScrollableHost.class b/node_modules/react-native-pager-view/android/build/tmp/kotlin-classes/debug/com/reactnativepagerview/NestedScrollableHost.class 2 - new file mode 100644 3 - index 0000000..b64fccc 4 - Binary files /dev/null and b/node_modules/react-native-pager-view/android/build/tmp/kotlin-classes/debug/com/reactnativepagerview/NestedScrollableHost.class differ 5 - diff --git a/node_modules/react-native-pager-view/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt b/node_modules/react-native-pager-view/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt 6 - index 91d9946..87b58d0 100644 7 - --- a/node_modules/react-native-pager-view/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt 8 - +++ b/node_modules/react-native-pager-view/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt 9 - @@ -8,6 +8,7 @@ import android.view.ViewConfiguration 10 - import android.widget.FrameLayout 11 - import androidx.viewpager2.widget.ViewPager2 12 - import androidx.viewpager2.widget.ViewPager2.ORIENTATION_HORIZONTAL 13 - +import com.facebook.react.uimanager.events.NativeGestureUtil 14 - import kotlin.math.absoluteValue 15 - import kotlin.math.sign 16 - 17 - @@ -27,6 +28,7 @@ class NestedScrollableHost : FrameLayout { 18 - private var touchSlop = 0 19 - private var initialX = 0f 20 - private var initialY = 0f 21 - + private var nativeGestureStarted: Boolean = false 22 - private val parentViewPager: ViewPager2? 23 - get() { 24 - var v: View? = parent as? View 25 - @@ -57,17 +59,14 @@ class NestedScrollableHost : FrameLayout { 26 - } 27 - 28 - private fun handleInterceptTouchEvent(e: MotionEvent) { 29 - - val orientation = parentViewPager?.orientation ?: return 30 - - 31 - - // Early return if child can't scroll in same direction as parent 32 - - if (!canChildScroll(orientation, -1f) && !canChildScroll(orientation, 1f)) { 33 - - return 34 - - } 35 - + val orientation = parentViewPager?.orientation 36 - 37 - if (e.action == MotionEvent.ACTION_DOWN) { 38 - initialX = e.x 39 - initialY = e.y 40 - - parent.requestDisallowInterceptTouchEvent(true) 41 - + if (orientation != null) { 42 - + parent.requestDisallowInterceptTouchEvent(true) 43 - + } 44 - } else if (e.action == MotionEvent.ACTION_MOVE) { 45 - val dx = e.x - initialX 46 - val dy = e.y - initialY 47 - @@ -78,6 +77,10 @@ class NestedScrollableHost : FrameLayout { 48 - val scaledDy = dy.absoluteValue * if (isVpHorizontal) 1f else .5f 49 - 50 - if (scaledDx > touchSlop || scaledDy > touchSlop) { 51 - + NativeGestureUtil.notifyNativeGestureStarted(this, e) 52 - + nativeGestureStarted = true 53 - + 54 - + if (orientation == null) return 55 - if (isVpHorizontal == (scaledDy > scaledDx)) { 56 - // Gesture is perpendicular, allow all parents to intercept 57 - parent.requestDisallowInterceptTouchEvent(false) 58 - @@ -94,4 +97,14 @@ class NestedScrollableHost : FrameLayout { 59 - } 60 - } 61 - } 62 - + 63 - + override fun onTouchEvent(e: MotionEvent): Boolean { 64 - + if (e.actionMasked == MotionEvent.ACTION_UP) { 65 - + if (nativeGestureStarted) { 66 - + NativeGestureUtil.notifyNativeGestureEnded(this, e) 67 - + nativeGestureStarted = false 68 - + } 69 - + } 70 - + return super.onTouchEvent(e) 71 - + } 72 - }
+40 -2
src/view/com/pager/Pager.tsx
··· 1 - import React, {forwardRef, useCallback, useContext} from 'react' 1 + import React, {Children, forwardRef, useCallback, useContext} from 'react' 2 2 import {View} from 'react-native' 3 3 import {DrawerGestureContext} from 'react-native-drawer-layout' 4 4 import {Gesture, GestureDetector} from 'react-native-gesture-handler' ··· 17 17 } from 'react-native-reanimated' 18 18 import {useFocusEffect} from '@react-navigation/native' 19 19 20 + import {isAndroid} from '#/platform/detection' 20 21 import {useSetDrawerSwipeDisabled} from '#/state/shell' 21 22 import {atoms as a, native} from '#/alf' 22 23 ··· 148 149 style={[a.flex_1]} 149 150 initialPage={initialPage} 150 151 onPageScroll={handlePageScroll}> 151 - {children} 152 + {isAndroid 153 + ? Children.map(children, child => ( 154 + <CaptureSwipesAndroid>{child}</CaptureSwipesAndroid> 155 + )) 156 + : children} 152 157 </AnimatedPagerView> 153 158 </GestureDetector> 154 159 </View> 155 160 ) 156 161 }, 157 162 ) 163 + 164 + // HACK. 165 + // This works around https://github.com/callstack/react-native-pager-view/issues/960. 166 + // It appears that the Pressables inside the pager get confused if there's enough work 167 + // happening on the JS thread, and mistakingly interpret a pager swipe as a tap. 168 + // We can prevent this by stealing all horizontal movements from the tree inside. 169 + function CaptureSwipesAndroid({children}: {children: React.ReactNode}) { 170 + const lastTouchStart = React.useRef<{x: number; y: number} | null>(null) 171 + return ( 172 + <View 173 + onTouchStart={e => { 174 + lastTouchStart.current = { 175 + x: e.nativeEvent.pageX, 176 + y: e.nativeEvent.pageY, 177 + } 178 + }} 179 + onMoveShouldSetResponderCapture={e => { 180 + const coords = lastTouchStart.current 181 + if (!coords) { 182 + return false 183 + } 184 + const dx = Math.abs(e.nativeEvent.pageX - coords.x) 185 + if (dx > 0) { 186 + // This is a horizontal movement and will result in a swipe. 187 + // Prevent pager children from receiving this touch. 188 + return true 189 + } 190 + return false 191 + }}> 192 + {children} 193 + </View> 194 + ) 195 + } 158 196 159 197 function usePagerHandlers( 160 198 handlers: {