UNPKG

18.2 kBSource Map (JSON)View Raw
1{"version":3,"sources":["PanResponderAdapter.tsx"],"names":["React","Animated","PanResponder","Keyboard","StyleSheet","I18nManager","View","useAnimatedValue","DEAD_ZONE","DefaultTransitionSpec","timing","spring","stiffness","damping","mass","overshootClamping","PanResponderAdapter","layout","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","routes","index","panX","listenersRef","useRef","navigationStateRef","layoutRef","onIndexChangeRef","currentIndexRef","pendingIndexRef","swipeVelocityThreshold","swipeDistanceThreshold","width","jumpToIndex","useCallback","offset","current","transitionConfig","parallel","toValue","useNativeDriver","start","finished","undefined","useEffect","setValue","dismiss","isMovingHorizontally","_","gestureState","Math","abs","dx","dy","vx","vy","canMoveScreen","event","diffX","isRTL","length","startGesture","stopAnimation","setOffset","_value","respondToGesture","position","_offset","next","ceil","floor","forEach","listener","finishGesture","flattenOffset","currentIndex","nextIndex","round","min","max","isFinite","addEnterListener","push","indexOf","splice","jumpTo","key","findIndex","route","panResponder","create","onMoveShouldSetPanResponder","onMoveShouldSetPanResponderCapture","onPanResponderGrant","onPanResponderMove","onPanResponderTerminate","onPanResponderRelease","onPanResponderTerminationRequest","maxTranslate","translateX","multiply","interpolate","inputRange","outputRange","extrapolate","divide","Value","render","styles","sheet","transform","panHandlers","Children","map","child","i","focused","absoluteFill","flex","flexDirection","alignItems"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,QADF,EAEEC,YAFF,EAGEC,QAHF,EAIEC,UAJF,EAOEC,WAPF,EAQEC,IARF,QASO,cATP;AAUA,OAAOC,gBAAP,MAA6B,oBAA7B;AA6BA,MAAMC,SAAS,GAAG,EAAlB;AAEA,MAAMC,qBAAqB,GAAG;AAC5BC,EAAAA,MAAM,EAAET,QAAQ,CAACU,MADW;AAE5BC,EAAAA,SAAS,EAAE,IAFiB;AAG5BC,EAAAA,OAAO,EAAE,GAHmB;AAI5BC,EAAAA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sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n PanResponder,\n Keyboard,\n StyleSheet,\n GestureResponderEvent,\n PanResponderGestureState,\n I18nManager,\n View,\n} from 'react-native';\nimport useAnimatedValue from './useAnimatedValue';\nimport type {\n NavigationState,\n Route,\n Layout,\n EventEmitterProps,\n PagerProps,\n Listener,\n} from './types';\n\ntype Props<T extends Route> = PagerProps & {\n layout: Layout;\n onIndexChange: (index: number) => void;\n navigationState: NavigationState<T>;\n children: (\n props: EventEmitterProps & {\n // Animated value which represents the state of current index\n // It can include fractional digits as it represents the intermediate value\n position: Animated.AnimatedInterpolation;\n // Function to actually render the content of the pager\n // The parent component takes care of rendering\n render: (children: React.ReactNode) => React.ReactNode;\n // Callback to call when switching the tab\n // The tab switch animation is performed even if the index in state is unchanged\n jumpTo: (key: string) => void;\n }\n ) => React.ReactElement;\n};\n\nconst DEAD_ZONE = 12;\n\nconst DefaultTransitionSpec = {\n timing: Animated.spring,\n stiffness: 1000,\n damping: 500,\n mass: 3,\n overshootClamping: true,\n};\n\nexport default function PanResponderAdapter<T extends Route>({\n layout,\n keyboardDismissMode = 'auto',\n swipeEnabled = true,\n navigationState,\n onIndexChange,\n onSwipeStart,\n onSwipeEnd,\n children,\n style,\n}: Props<T>) {\n const { routes, index } = navigationState;\n\n const panX = useAnimatedValue(0);\n\n const listenersRef = React.useRef<Listener[]>([]);\n\n const navigationStateRef = React.useRef(navigationState);\n const layoutRef = React.useRef(layout);\n const onIndexChangeRef = React.useRef(onIndexChange);\n\n const currentIndexRef = React.useRef(index);\n const pendingIndexRef = React.useRef<number>();\n\n const swipeVelocityThreshold = 0.15;\n const swipeDistanceThreshold = layout.width / 1.75;\n\n const jumpToIndex = React.useCallback(\n (index: number) => {\n const offset = -index * layoutRef.current.width;\n\n const { timing, ...transitionConfig } = DefaultTransitionSpec;\n\n Animated.parallel([\n timing(panX, {\n ...transitionConfig,\n toValue: offset,\n useNativeDriver: false,\n }),\n ]).start(({ finished }) => {\n if (finished) {\n onIndexChangeRef.current(index);\n pendingIndexRef.current = undefined;\n }\n });\n\n pendingIndexRef.current = index;\n },\n [panX]\n );\n\n React.useEffect(() => {\n navigationStateRef.current = navigationState;\n layoutRef.current = layout;\n onIndexChangeRef.current = onIndexChange;\n });\n\n React.useEffect(() => {\n const offset = -navigationStateRef.current.index * layout.width;\n\n panX.setValue(offset);\n }, [layout.width, panX]);\n\n React.useEffect(() => {\n if (keyboardDismissMode === 'auto') {\n Keyboard.dismiss();\n }\n\n if (layout.width && currentIndexRef.current !== index) {\n currentIndexRef.current = index;\n jumpToIndex(index);\n }\n }, [jumpToIndex, keyboardDismissMode, layout.width, index]);\n\n const isMovingHorizontally = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n return (\n Math.abs(gestureState.dx) > Math.abs(gestureState.dy * 2) &&\n Math.abs(gestureState.vx) > Math.abs(gestureState.vy * 2)\n );\n };\n\n const canMoveScreen = (\n event: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n if (swipeEnabled === false) {\n return false;\n }\n\n const diffX = I18nManager.isRTL ? -gestureState.dx : gestureState.dx;\n\n return (\n isMovingHorizontally(event, gestureState) &&\n ((diffX >= DEAD_ZONE && currentIndexRef.current > 0) ||\n (diffX <= -DEAD_ZONE && currentIndexRef.current < routes.length - 1))\n );\n };\n\n const startGesture = () => {\n onSwipeStart?.();\n\n if (keyboardDismissMode === 'on-drag') {\n Keyboard.dismiss();\n }\n\n panX.stopAnimation();\n // @ts-expect-error: _value is private, but docs use it as well\n panX.setOffset(panX._value);\n };\n\n const respondToGesture = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n const diffX = I18nManager.isRTL ? -gestureState.dx : gestureState.dx;\n\n if (\n // swiping left\n (diffX > 0 && index <= 0) ||\n // swiping right\n (diffX < 0 && index >= routes.length - 1)\n ) {\n return;\n }\n\n if (layout.width) {\n // @ts-expect-error: _offset is private, but docs use it as well\n const position = (panX._offset + diffX) / -layout.width;\n const next =\n position > index ? Math.ceil(position) : Math.floor(position);\n\n if (next !== index) {\n listenersRef.current.forEach((listener) => listener(next));\n }\n }\n\n panX.setValue(diffX);\n };\n\n const finishGesture = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n panX.flattenOffset();\n\n onSwipeEnd?.();\n\n const currentIndex =\n typeof pendingIndexRef.current === 'number'\n ? pendingIndexRef.current\n : currentIndexRef.current;\n\n let nextIndex = currentIndex;\n\n if (\n Math.abs(gestureState.dx) > Math.abs(gestureState.dy) &&\n Math.abs(gestureState.vx) > Math.abs(gestureState.vy) &&\n (Math.abs(gestureState.dx) > swipeDistanceThreshold ||\n Math.abs(gestureState.vx) > swipeVelocityThreshold)\n ) {\n nextIndex = Math.round(\n Math.min(\n Math.max(\n 0,\n I18nManager.isRTL\n ? currentIndex + gestureState.dx / Math.abs(gestureState.dx)\n : currentIndex - gestureState.dx / Math.abs(gestureState.dx)\n ),\n routes.length - 1\n )\n );\n\n currentIndexRef.current = nextIndex;\n }\n\n if (!isFinite(nextIndex)) {\n nextIndex = currentIndex;\n }\n\n jumpToIndex(nextIndex);\n };\n\n // TODO: use the listeners\n const addEnterListener = React.useCallback((listener: Listener) => {\n listenersRef.current.push(listener);\n\n return () => {\n const index = listenersRef.current.indexOf(listener);\n\n if (index > -1) {\n listenersRef.current.splice(index, 1);\n }\n };\n }, []);\n\n const jumpTo = React.useCallback(\n (key: string) => {\n const index = navigationStateRef.current.routes.findIndex(\n (route: { key: string }) => route.key === key\n );\n\n jumpToIndex(index);\n },\n [jumpToIndex]\n );\n\n const panResponder = PanResponder.create({\n onMoveShouldSetPanResponder: canMoveScreen,\n onMoveShouldSetPanResponderCapture: canMoveScreen,\n onPanResponderGrant: startGesture,\n onPanResponderMove: respondToGesture,\n onPanResponderTerminate: finishGesture,\n onPanResponderRelease: finishGesture,\n onPanResponderTerminationRequest: () => true,\n });\n\n const maxTranslate = layout.width * (routes.length - 1);\n const translateX = Animated.multiply(\n panX.interpolate({\n inputRange: [-maxTranslate, 0],\n outputRange: [-maxTranslate, 0],\n extrapolate: 'clamp',\n }),\n I18nManager.isRTL ? -1 : 1\n );\n\n return children({\n position: layout.width\n ? Animated.divide(panX, -layout.width)\n : new Animated.Value(index),\n addEnterListener,\n jumpTo,\n render: (children) => (\n <Animated.View\n style={[\n styles.sheet,\n layout.width\n ? {\n width: routes.length * layout.width,\n transform: [{ translateX }],\n }\n : null,\n style,\n ]}\n {...panResponder.panHandlers}\n >\n {React.Children.map(children, (child, i) => {\n const route = routes[i];\n const focused = i === index;\n\n return (\n <View\n key={route.key}\n style={\n layout.width\n ? { width: layout.width }\n : focused\n ? StyleSheet.absoluteFill\n : null\n }\n >\n {focused || layout.width ? child : null}\n </View>\n );\n })}\n </Animated.View>\n ),\n });\n}\n\nconst styles = StyleSheet.create({\n sheet: {\n flex: 1,\n flexDirection: 'row',\n alignItems: 'stretch',\n },\n});\n"]}
\No newline at end of file