kinda hacky solution for gesturedetector rerender problem
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
useContext,
|
useContext,
|
||||||
|
useEffect,
|
||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
@@ -139,10 +141,6 @@ export function Pager({
|
|||||||
[parentOnPageScrollStateChanged],
|
[parentOnPageScrollStateChanged],
|
||||||
)
|
)
|
||||||
|
|
||||||
const drawerGesture = useContext(DrawerGestureContext) ?? Gesture.Native() // noop for web
|
|
||||||
const nativeGesture =
|
|
||||||
Gesture.Native().requireExternalGestureToFail(drawerGesture)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View testID={testID} style={[a.flex_1, native(a.overflow_hidden)]}>
|
<View testID={testID} style={[a.flex_1, native(a.overflow_hidden)]}>
|
||||||
{renderTabBar({
|
{renderTabBar({
|
||||||
@@ -151,7 +149,7 @@ export function Pager({
|
|||||||
dragProgress,
|
dragProgress,
|
||||||
dragState,
|
dragState,
|
||||||
})}
|
})}
|
||||||
<GestureDetector gesture={nativeGesture}>
|
<DrawerGestureRequireFail>
|
||||||
<AnimatedPagerView
|
<AnimatedPagerView
|
||||||
ref={pagerView}
|
ref={pagerView}
|
||||||
style={[a.flex_1]}
|
style={[a.flex_1]}
|
||||||
@@ -159,11 +157,31 @@ export function Pager({
|
|||||||
onPageScroll={handlePageScroll}>
|
onPageScroll={handlePageScroll}>
|
||||||
{children}
|
{children}
|
||||||
</AnimatedPagerView>
|
</AnimatedPagerView>
|
||||||
</GestureDetector>
|
</DrawerGestureRequireFail>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function DrawerGestureRequireFail({children}: {children: React.ReactNode}) {
|
||||||
|
const drawerGesture = useContext(DrawerGestureContext)
|
||||||
|
|
||||||
|
const nativeGesture = useMemo(() => Gesture.Native(), [])
|
||||||
|
|
||||||
|
// the drawer gesture identity changes whenever the drawer opens/closes,
|
||||||
|
// but we don't want the GestureDetector to rerender when that happens
|
||||||
|
// therefore we just keep adding the gestures every time it changes to the same
|
||||||
|
// native gesture -sfn
|
||||||
|
useEffect(() => {
|
||||||
|
if (drawerGesture) {
|
||||||
|
nativeGesture.requireExternalGestureToFail(drawerGesture)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: figure out how to clean this up
|
||||||
|
}, [drawerGesture, nativeGesture])
|
||||||
|
|
||||||
|
return <GestureDetector gesture={nativeGesture}>{children}</GestureDetector>
|
||||||
|
}
|
||||||
|
|
||||||
function usePagerHandlers(
|
function usePagerHandlers(
|
||||||
handlers: {
|
handlers: {
|
||||||
onPageScroll: (e: PagerViewOnPageScrollEventData) => void
|
onPageScroll: (e: PagerViewOnPageScrollEventData) => void
|
||||||
|
|||||||
Reference in New Issue
Block a user