react-native-tab-view 3.2.1 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/{LICENSE.md → LICENSE} +0 -0
  2. package/README.md +5 -36
  3. package/lib/commonjs/PagerViewAdapter.js +2 -1
  4. package/lib/commonjs/PagerViewAdapter.js.map +1 -1
  5. package/lib/commonjs/PanResponderAdapter.js +2 -1
  6. package/lib/commonjs/PanResponderAdapter.js.map +1 -1
  7. package/lib/commonjs/SceneMap.js +9 -12
  8. package/lib/commonjs/SceneMap.js.map +1 -1
  9. package/lib/commonjs/SceneView.js +54 -101
  10. package/lib/commonjs/SceneView.js.map +1 -1
  11. package/lib/commonjs/TabBar.js +358 -325
  12. package/lib/commonjs/TabBar.js.map +1 -1
  13. package/lib/commonjs/TabBarIndicator.js +81 -99
  14. package/lib/commonjs/TabBarIndicator.js.map +1 -1
  15. package/lib/commonjs/TabBarItem.js +184 -161
  16. package/lib/commonjs/TabBarItem.js.map +1 -1
  17. package/lib/commonjs/TabView.js +2 -2
  18. package/lib/commonjs/TabView.js.map +1 -1
  19. package/lib/commonjs/index.js +3 -3
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/module/PagerViewAdapter.js +2 -1
  22. package/lib/module/PagerViewAdapter.js.map +1 -1
  23. package/lib/module/PanResponderAdapter.js +3 -2
  24. package/lib/module/PanResponderAdapter.js.map +1 -1
  25. package/lib/module/SceneMap.js +9 -14
  26. package/lib/module/SceneMap.js.map +1 -1
  27. package/lib/module/SceneView.js +54 -99
  28. package/lib/module/SceneView.js.map +1 -1
  29. package/lib/module/TabBar.js +355 -324
  30. package/lib/module/TabBar.js.map +1 -1
  31. package/lib/module/TabBarIndicator.js +75 -93
  32. package/lib/module/TabBarIndicator.js.map +1 -1
  33. package/lib/module/TabBarItem.js +178 -154
  34. package/lib/module/TabBarItem.js.map +1 -1
  35. package/lib/module/TabView.js +2 -2
  36. package/lib/module/TabView.js.map +1 -1
  37. package/lib/module/index.js +2 -2
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/typescript/{Pager.android.d.ts → src/Pager.android.d.ts} +0 -0
  40. package/lib/typescript/{Pager.d.ts → src/Pager.d.ts} +0 -0
  41. package/lib/typescript/{Pager.ios.d.ts → src/Pager.ios.d.ts} +0 -0
  42. package/lib/typescript/{PagerViewAdapter.d.ts → src/PagerViewAdapter.d.ts} +1 -1
  43. package/lib/typescript/{PanResponderAdapter.d.ts → src/PanResponderAdapter.d.ts} +1 -1
  44. package/lib/typescript/{PlatformPressable.d.ts → src/PlatformPressable.d.ts} +0 -0
  45. package/lib/typescript/{SceneMap.d.ts → src/SceneMap.d.ts} +5 -3
  46. package/lib/typescript/src/SceneView.d.ts +15 -0
  47. package/lib/typescript/src/TabBar.d.ts +42 -0
  48. package/lib/typescript/src/TabBarIndicator.d.ts +12 -0
  49. package/lib/typescript/{TabBarItem.d.ts → src/TabBarItem.d.ts} +5 -7
  50. package/lib/typescript/{TabView.d.ts → src/TabView.d.ts} +1 -1
  51. package/lib/typescript/{index.d.ts → src/index.d.ts} +7 -7
  52. package/lib/typescript/{types.d.ts → src/types.d.ts} +0 -0
  53. package/lib/typescript/{useAnimatedValue.d.ts → src/useAnimatedValue.d.ts} +0 -0
  54. package/package.json +28 -58
  55. package/src/PagerViewAdapter.tsx +11 -5
  56. package/src/PanResponderAdapter.tsx +16 -12
  57. package/src/SceneMap.tsx +12 -7
  58. package/src/SceneView.tsx +73 -108
  59. package/src/TabBar.tsx +506 -401
  60. package/src/TabBarIndicator.tsx +114 -117
  61. package/src/TabBarItem.tsx +230 -200
  62. package/src/TabView.tsx +6 -5
  63. package/src/index.tsx +7 -12
  64. package/lib/typescript/SceneView.d.ts +0 -32
  65. package/lib/typescript/TabBar.d.ts +0 -72
  66. package/lib/typescript/TabBarIndicator.d.ts +0 -20
@@ -1 +1 @@
1
- {"version":3,"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","animationEnabled","routes","index","panX","listenersRef","useRef","navigationStateRef","layoutRef","onIndexChangeRef","currentIndexRef","pendingIndexRef","swipeVelocityThreshold","swipeDistanceThreshold","width","jumpToIndex","useCallback","animate","offset","current","transitionConfig","parallel","toValue","useNativeDriver","start","finished","undefined","setValue","useEffect","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"],"sources":["PanResponderAdapter.tsx"],"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 animationEnabled = false,\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, animate = animationEnabled) => {\n const offset = -index * layoutRef.current.width;\n\n const { timing, ...transitionConfig } = DefaultTransitionSpec;\n\n if (animate) {\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 pendingIndexRef.current = index;\n } else {\n panX.setValue(offset);\n onIndexChangeRef.current(index);\n pendingIndexRef.current = undefined;\n }\n },\n [animationEnabled, 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, true);\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"],"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;EAC5BC,MAAM,EAAET,QAAQ,CAACU,MADW;EAE5BC,SAAS,EAAE,IAFiB;EAG5BC,OAAO,EAAE,GAHmB;EAI5BC,IAAI,EAAE,CAJsB;EAK5BC,iBAAiB,EAAE;AALS,CAA9B;AAQA,eAAe,SAASC,mBAAT,OAWF;EAAA,IAXgD;IAC3DC,MAD2D;IAE3DC,mBAAmB,GAAG,MAFqC;IAG3DC,YAAY,GAAG,IAH4C;IAI3DC,eAJ2D;IAK3DC,aAL2D;IAM3DC,YAN2D;IAO3DC,UAP2D;IAQ3DC,QAR2D;IAS3DC,KAT2D;IAU3DC,gBAAgB,GAAG;EAVwC,CAWhD;EACX,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAoBR,eAA1B;EAEA,MAAMS,IAAI,GAAGtB,gBAAgB,CAAC,CAAD,CAA7B;EAEA,MAAMuB,YAAY,GAAG9B,KAAK,CAAC+B,MAAN,CAAyB,EAAzB,CAArB;EAEA,MAAMC,kBAAkB,GAAGhC,KAAK,CAAC+B,MAAN,CAAaX,eAAb,CAA3B;EACA,MAAMa,SAAS,GAAGjC,KAAK,CAAC+B,MAAN,CAAad,MAAb,CAAlB;EACA,MAAMiB,gBAAgB,GAAG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AK,EAAEtB,MAAM,CAACsB;QAAhB,CADJ,GAEIqF,OAAO,GACPxH,UAAU,CAACyH,YADJ,GAEP;MAPR,GAUGD,OAAO,IAAI3G,MAAM,CAACsB,KAAlB,GAA0BmF,KAA1B,GAAkC,IAVrC,CADF;IAcD,CAlBA,CAbH;EAPY,CAAD,CAAf;AA0CD;AAED,MAAMN,MAAM,GAAGhH,UAAU,CAAC8F,MAAX,CAAkB;EAC/BmB,KAAK,EAAE;IACLS,IAAI,EAAE,CADD;IAELC,aAAa,EAAE,KAFV;IAGLC,UAAU,EAAE;EAHP;AADwB,CAAlB,CAAf"}
1
+ {"version":3,"names":["React","Animated","I18nManager","Keyboard","PanResponder","StyleSheet","View","useAnimatedValue","DEAD_ZONE","DefaultTransitionSpec","timing","spring","stiffness","damping","mass","overshootClamping","PanResponderAdapter","layout","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","animationEnabled","routes","index","panX","listenersRef","useRef","navigationStateRef","layoutRef","onIndexChangeRef","currentIndexRef","pendingIndexRef","swipeVelocityThreshold","swipeDistanceThreshold","width","jumpToIndex","useCallback","animate","offset","current","transitionConfig","parallel","toValue","useNativeDriver","start","finished","undefined","setValue","useEffect","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","useMemo","divide","Value","render","styles","sheet","transform","panHandlers","Children","map","child","i","focused","absoluteFill","flex","flexDirection","alignItems"],"sources":["PanResponderAdapter.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n GestureResponderEvent,\n I18nManager,\n Keyboard,\n PanResponder,\n PanResponderGestureState,\n StyleSheet,\n View,\n} from 'react-native';\n\nimport type {\n EventEmitterProps,\n Layout,\n Listener,\n NavigationState,\n PagerProps,\n Route,\n} from './types';\nimport useAnimatedValue from './useAnimatedValue';\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 animationEnabled = false,\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, animate = animationEnabled) => {\n const offset = -index * layoutRef.current.width;\n\n const { timing, ...transitionConfig } = DefaultTransitionSpec;\n\n if (animate) {\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 pendingIndexRef.current = index;\n } else {\n panX.setValue(offset);\n onIndexChangeRef.current(index);\n pendingIndexRef.current = undefined;\n }\n },\n [animationEnabled, 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, true);\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 const position = React.useMemo(\n () => (layout.width ? Animated.divide(panX, -layout.width) : null),\n [layout.width, panX]\n );\n\n return children({\n position: position ?? 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"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,QADF,EAGEC,WAHF,EAIEC,QAJF,EAKEC,YALF,EAOEC,UAPF,EAQEC,IARF,QASO,cATP;AAmBA,OAAOC,gBAAP,MAA6B,oBAA7B;AAqBA,MAAMC,SAAS,GAAG,EAAlB;AAEA,MAAMC,qBAAqB,GAAG;EAC5BC,MAAM,EAAET,QAAQ,CAACU,MADW;EAE5BC,SAAS,EAAE,IAFiB;EAG5BC,OAAO,EAAE,GAHmB;EAI5BC,IAAI,EAAE,CAJsB;EAK5BC,iBAAiB,EAAE;AALS,CAA9B;AAQA,eAAe,SAASC,mBAAT,OAWF;EAAA,IAXgD;IAC3DC,MAD2D;IAE3DC,mBAAmB,GAAG,MAFqC;IAG3DC,YAAY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D,gBAFc;IAGdI,MAHc;IAIduB,MAAM,EAAG5F,QAAD,iBACN,oBAAC,QAAD,CAAU,IAAV;MACE,KAAK,EAAE,CACL6F,MAAM,CAACC,KADF,EAELrG,MAAM,CAACsB,KAAP,GACI;QACEA,KAAK,EAAEZ,MAAM,CAACyC,MAAP,GAAgBnD,MAAM,CAACsB,KADhC;QAEEgF,SAAS,EAAE,CAAC;UAAEZ;QAAF,CAAD;MAFb,CADJ,GAKI,IAPC,EAQLlF,KARK;IADT,GAWMwE,YAAY,CAACuB,WAXnB,GAaGxH,KAAK,CAACyH,QAAN,CAAeC,GAAf,CAAmBlG,QAAnB,EAA6B,CAACmG,KAAD,EAAQC,CAAR,KAAc;MAC1C,MAAM5B,KAAK,GAAGrE,MAAM,CAACiG,CAAD,CAApB;MACA,MAAMC,OAAO,GAAGD,CAAC,KAAKhG,KAAtB;MAEA,oBACE,oBAAC,IAAD;QACE,GAAG,EAAEoE,KAAK,CAACF,GADb;QAEE,KAAK,EACH7E,MAAM,CAACsB,KAAP,GACI;UAAEA,KAAK,EAAEtB,MAAM,CAACsB;QAAhB,CADJ,GAEIsF,OAAO,GACPxH,UAAU,CAACyH,YADJ,GAEP;MAPR,GAUGD,OAAO,IAAI5G,MAAM,CAACsB,KAAlB,GAA0BoF,KAA1B,GAAkC,IAVrC,CADF;IAcD,CAlBA,CAbH;EALY,CAAD,CAAf;AAwCD;AAED,MAAMN,MAAM,GAAGhH,UAAU,CAAC6F,MAAX,CAAkB;EAC/BoB,KAAK,EAAE;IACLS,IAAI,EAAE,CADD;IAELC,aAAa,EAAE,KAFV;IAGLC,UAAU,EAAE;EAHP;AADwB,CAAlB,CAAf"}
@@ -1,23 +1,18 @@
1
1
  import * as React from 'react';
2
-
3
- class SceneComponent extends React.PureComponent {
4
- render() {
5
- const {
6
- component,
7
- ...rest
8
- } = this.props;
9
- return /*#__PURE__*/React.createElement(component, rest);
10
- }
11
-
12
- }
13
-
2
+ const SceneComponent = /*#__PURE__*/React.memo(_ref => {
3
+ let {
4
+ component,
5
+ ...rest
6
+ } = _ref;
7
+ return /*#__PURE__*/React.createElement(component, rest);
8
+ });
14
9
  export default function SceneMap(scenes) {
15
- return _ref => {
10
+ return _ref2 => {
16
11
  let {
17
12
  route,
18
13
  jumpTo,
19
14
  position
20
- } = _ref;
15
+ } = _ref2;
21
16
  return /*#__PURE__*/React.createElement(SceneComponent, {
22
17
  key: route.key,
23
18
  component: scenes[route.key],
@@ -1 +1 @@
1
- {"version":3,"names":["React","SceneComponent","PureComponent","render","component","rest","props","createElement","SceneMap","scenes","route","jumpTo","position","key"],"sources":["SceneMap.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { SceneRendererProps } from './types';\n\nclass SceneComponent<\n T extends { component: React.ComponentType<any> }\n> extends React.PureComponent<T> {\n render() {\n const { component, ...rest } = this.props;\n return React.createElement(component, rest);\n }\n}\n\nexport default function SceneMap<T extends any>(scenes: {\n [key: string]: React.ComponentType<T>;\n}) {\n return ({ route, jumpTo, position }: SceneRendererProps & { route: any }) => (\n <SceneComponent\n key={route.key}\n component={scenes[route.key]}\n route={route}\n jumpTo={jumpTo}\n position={position}\n />\n );\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAGA,MAAMC,cAAN,SAEUD,KAAK,CAACE,aAFhB,CAEiC;EAC/BC,MAAM,GAAG;IACP,MAAM;MAAEC,SAAF;MAAa,GAAGC;IAAhB,IAAyB,KAAKC,KAApC;IACA,oBAAON,KAAK,CAACO,aAAN,CAAoBH,SAApB,EAA+BC,IAA/B,CAAP;EACD;;AAJ8B;;AAOjC,eAAe,SAASG,QAAT,CAAiCC,MAAjC,EAEZ;EACD,OAAO;IAAA,IAAC;MAAEC,KAAF;MAASC,MAAT;MAAiBC;IAAjB,CAAD;IAAA,oBACL,oBAAC,cAAD;MACE,GAAG,EAAEF,KAAK,CAACG,GADb;MAEE,SAAS,EAAEJ,MAAM,CAACC,KAAK,CAACG,GAAP,CAFnB;MAGE,KAAK,EAAEH,KAHT;MAIE,MAAM,EAAEC,MAJV;MAKE,QAAQ,EAAEC;IALZ,EADK;EAAA,CAAP;AASD"}
1
+ {"version":3,"names":["React","SceneComponent","memo","component","rest","createElement","SceneMap","scenes","route","jumpTo","position","key"],"sources":["SceneMap.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport type { SceneRendererProps } from './types';\n\ntype SceneProps = {\n route: any;\n} & Omit<SceneRendererProps, 'layout'>;\n\nconst SceneComponent = React.memo(\n <T extends { component: React.ComponentType<any> } & SceneProps>({\n component,\n ...rest\n }: T) => {\n return React.createElement(component, rest);\n }\n);\n\nexport default function SceneMap<T extends any>(scenes: {\n [key: string]: React.ComponentType<T>;\n}) {\n return ({ route, jumpTo, position }: SceneProps) => (\n <SceneComponent\n key={route.key}\n component={scenes[route.key]}\n route={route}\n jumpTo={jumpTo}\n position={position}\n />\n );\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAQA,MAAMC,cAAc,gBAAGD,KAAK,CAACE,IAAN,CACrB,QAGS;EAAA,IAHwD;IAC/DC,SAD+D;IAE/D,GAAGC;EAF4D,CAGxD;EACP,oBAAOJ,KAAK,CAACK,aAAN,CAAoBF,SAApB,EAA+BC,IAA/B,CAAP;AACD,CANoB,CAAvB;AASA,eAAe,SAASE,QAAT,CAAiCC,MAAjC,EAEZ;EACD,OAAO;IAAA,IAAC;MAAEC,KAAF;MAASC,MAAT;MAAiBC;IAAjB,CAAD;IAAA,oBACL,oBAAC,cAAD;MACE,GAAG,EAAEF,KAAK,CAACG,GADb;MAEE,SAAS,EAAEJ,MAAM,CAACC,KAAK,CAACG,GAAP,CAFnB;MAGE,KAAK,EAAEH,KAHT;MAIE,MAAM,EAAEC,MAJV;MAKE,QAAQ,EAAEC;IALZ,EADK;EAAA,CAAP;AASD"}
@@ -1,116 +1,71 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
1
  import * as React from 'react';
4
- import { View, StyleSheet } from 'react-native';
5
- export default class SceneView extends React.Component {
6
- constructor() {
7
- super(...arguments);
8
-
9
- _defineProperty(this, "state", {
10
- loading: Math.abs(this.props.navigationState.index - this.props.index) > this.props.lazyPreloadDistance
11
- });
12
-
13
- _defineProperty(this, "timerHandler", void 0);
14
-
15
- _defineProperty(this, "unsubscribe", null);
16
-
17
- _defineProperty(this, "handleEnter", value => {
18
- const {
19
- index
20
- } = this.props; // If we're entering the current route, we need to load it
2
+ import { StyleSheet, View } from 'react-native';
3
+ export default function SceneView(_ref) {
4
+ let {
5
+ children,
6
+ navigationState,
7
+ lazy,
8
+ layout,
9
+ index,
10
+ lazyPreloadDistance,
11
+ addEnterListener,
12
+ style
13
+ } = _ref;
14
+ const [isLoading, setIsLoading] = React.useState(Math.abs(navigationState.index - index) > lazyPreloadDistance);
15
+
16
+ if (isLoading && Math.abs(navigationState.index - index) <= lazyPreloadDistance) {
17
+ // Always render the route when it becomes focused
18
+ setIsLoading(false);
19
+ }
21
20
 
21
+ React.useEffect(() => {
22
+ const handleEnter = value => {
23
+ // If we're entering the current route, we need to load it
22
24
  if (value === index) {
23
- this.setState(prevState => {
24
- if (prevState.loading) {
25
- return {
26
- loading: false
27
- };
25
+ setIsLoading(prevState => {
26
+ if (prevState) {
27
+ return false;
28
28
  }
29
29
 
30
- return null;
30
+ return prevState;
31
31
  });
32
32
  }
33
- });
34
- }
35
-
36
- static getDerivedStateFromProps(props, state) {
37
- if (state.loading && Math.abs(props.navigationState.index - props.index) <= props.lazyPreloadDistance) {
38
- // Always render the route when it becomes focused
39
- return {
40
- loading: false
41
- };
42
- }
33
+ };
43
34
 
44
- return null;
45
- }
35
+ let unsubscribe;
36
+ let timer;
46
37
 
47
- componentDidMount() {
48
- if (this.props.lazy) {
38
+ if (lazy && isLoading) {
49
39
  // If lazy mode is enabled, listen to when we enter screens
50
- this.unsubscribe = this.props.addEnterListener(this.handleEnter);
51
- } else if (this.state.loading) {
40
+ unsubscribe = addEnterListener(handleEnter);
41
+ } else if (isLoading) {
52
42
  // If lazy mode is not enabled, render the scene with a delay if not loaded already
53
43
  // This improves the initial startup time as the scene is no longer blocking
54
- this.timerHandler = setTimeout(() => this.setState({
55
- loading: false
56
- }), 0);
57
- }
58
- }
59
-
60
- componentDidUpdate(prevProps, prevState) {
61
- if (this.props.lazy !== prevProps.lazy || this.state.loading !== prevState.loading) {
62
- // We only need the listener if the tab hasn't loaded yet and lazy is enabled
63
- if (this.props.lazy && this.state.loading) {
64
- var _this$unsubscribe;
65
-
66
- (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
67
- this.unsubscribe = this.props.addEnterListener(this.handleEnter);
68
- } else {
69
- var _this$unsubscribe2;
70
-
71
- (_this$unsubscribe2 = this.unsubscribe) === null || _this$unsubscribe2 === void 0 ? void 0 : _this$unsubscribe2.call(this);
72
- }
73
- }
74
- }
75
-
76
- componentWillUnmount() {
77
- var _this$unsubscribe3;
78
-
79
- (_this$unsubscribe3 = this.unsubscribe) === null || _this$unsubscribe3 === void 0 ? void 0 : _this$unsubscribe3.call(this);
80
-
81
- if (this.timerHandler) {
82
- clearTimeout(this.timerHandler);
83
- this.timerHandler = undefined;
44
+ timer = setTimeout(() => setIsLoading(false), 0);
84
45
  }
85
- }
86
-
87
- render() {
88
- const {
89
- navigationState,
90
- index,
91
- layout,
92
- style
93
- } = this.props;
94
- const {
95
- loading
96
- } = this.state;
97
- const focused = navigationState.index === index;
98
- return /*#__PURE__*/React.createElement(View, {
99
- accessibilityElementsHidden: !focused,
100
- importantForAccessibility: focused ? 'auto' : 'no-hide-descendants',
101
- style: [styles.route, // If we don't have the layout yet, make the focused screen fill the container
102
- // This avoids delay before we are able to render pages side by side
103
- layout.width ? {
104
- width: layout.width
105
- } : focused ? StyleSheet.absoluteFill : null, style]
106
- }, // Only render the route only if it's either focused or layout is available
107
- // When layout is not available, we must not render unfocused routes
108
- // so that the focused route can fill the screen
109
- focused || layout.width ? this.props.children({
110
- loading
111
- }) : null);
112
- }
113
46
 
47
+ return () => {
48
+ var _unsubscribe;
49
+
50
+ (_unsubscribe = unsubscribe) === null || _unsubscribe === void 0 ? void 0 : _unsubscribe();
51
+ clearTimeout(timer);
52
+ };
53
+ }, [addEnterListener, index, isLoading, lazy]);
54
+ const focused = navigationState.index === index;
55
+ return /*#__PURE__*/React.createElement(View, {
56
+ accessibilityElementsHidden: !focused,
57
+ importantForAccessibility: focused ? 'auto' : 'no-hide-descendants',
58
+ style: [styles.route, // If we don't have the layout yet, make the focused screen fill the container
59
+ // This avoids delay before we are able to render pages side by side
60
+ layout.width ? {
61
+ width: layout.width
62
+ } : focused ? StyleSheet.absoluteFill : null, style]
63
+ }, // Only render the route only if it's either focused or layout is available
64
+ // When layout is not available, we must not render unfocused routes
65
+ // so that the focused route can fill the screen
66
+ focused || layout.width ? children({
67
+ loading: isLoading
68
+ }) : null);
114
69
  }
115
70
  const styles = StyleSheet.create({
116
71
  route: {
@@ -1 +1 @@
1
- {"version":3,"names":["React","View","StyleSheet","SceneView","Component","loading","Math","abs","props","navigationState","index","lazyPreloadDistance","value","setState","prevState","getDerivedStateFromProps","state","componentDidMount","lazy","unsubscribe","addEnterListener","handleEnter","timerHandler","setTimeout","componentDidUpdate","prevProps","componentWillUnmount","clearTimeout","undefined","render","layout","style","focused","styles","route","width","absoluteFill","children","create","flex","overflow"],"sources":["SceneView.tsx"],"sourcesContent":["import * as React from 'react';\nimport { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';\nimport type {\n SceneRendererProps,\n EventEmitterProps,\n NavigationState,\n Route,\n} from './types';\n\ntype Props<T extends Route> = SceneRendererProps &\n EventEmitterProps & {\n navigationState: NavigationState<T>;\n lazy: boolean;\n lazyPreloadDistance: number;\n index: number;\n children: (props: { loading: boolean }) => React.ReactNode;\n style?: StyleProp<ViewStyle>;\n };\n\ntype State = {\n loading: boolean;\n};\n\nexport default class SceneView<T extends Route> extends React.Component<\n Props<T>,\n State\n> {\n static getDerivedStateFromProps(props: Props<Route>, state: State) {\n if (\n state.loading &&\n Math.abs(props.navigationState.index - props.index) <=\n props.lazyPreloadDistance\n ) {\n // Always render the route when it becomes focused\n return { loading: false };\n }\n\n return null;\n }\n\n state = {\n loading:\n Math.abs(this.props.navigationState.index - this.props.index) >\n this.props.lazyPreloadDistance,\n };\n\n componentDidMount() {\n if (this.props.lazy) {\n // If lazy mode is enabled, listen to when we enter screens\n this.unsubscribe = this.props.addEnterListener(this.handleEnter);\n } else if (this.state.loading) {\n // If lazy mode is not enabled, render the scene with a delay if not loaded already\n // This improves the initial startup time as the scene is no longer blocking\n this.timerHandler = setTimeout(\n () => this.setState({ loading: false }),\n 0\n );\n }\n }\n\n componentDidUpdate(prevProps: Props<T>, prevState: State) {\n if (\n this.props.lazy !== prevProps.lazy ||\n this.state.loading !== prevState.loading\n ) {\n // We only need the listener if the tab hasn't loaded yet and lazy is enabled\n if (this.props.lazy && this.state.loading) {\n this.unsubscribe?.();\n this.unsubscribe = this.props.addEnterListener(this.handleEnter);\n } else {\n this.unsubscribe?.();\n }\n }\n }\n\n componentWillUnmount() {\n this.unsubscribe?.();\n\n if (this.timerHandler) {\n clearTimeout(this.timerHandler);\n this.timerHandler = undefined;\n }\n }\n\n private timerHandler: NodeJS.Timeout | undefined;\n\n private unsubscribe: (() => void) | null = null;\n\n private handleEnter = (value: number) => {\n const { index } = this.props;\n\n // If we're entering the current route, we need to load it\n if (value === index) {\n this.setState((prevState) => {\n if (prevState.loading) {\n return { loading: false };\n }\n\n return null;\n });\n }\n };\n\n render() {\n const { navigationState, index, layout, style } = this.props;\n const { loading } = this.state;\n\n const focused = navigationState.index === index;\n\n return (\n <View\n accessibilityElementsHidden={!focused}\n importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}\n style={[\n styles.route,\n // If we don't have the layout yet, make the focused screen fill the container\n // This avoids delay before we are able to render pages side by side\n layout.width\n ? { width: layout.width }\n : focused\n ? StyleSheet.absoluteFill\n : null,\n style,\n ]}\n >\n {\n // Only render the route only if it's either focused or layout is available\n // When layout is not available, we must not render unfocused routes\n // so that the focused route can fill the screen\n focused || layout.width ? this.props.children({ loading }) : null\n }\n </View>\n );\n }\n}\n\nconst styles = StyleSheet.create({\n route: {\n flex: 1,\n overflow: 'hidden',\n },\n});\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,IAAT,EAAeC,UAAf,QAAuD,cAAvD;AAsBA,eAAe,MAAMC,SAAN,SAAyCH,KAAK,CAACI,SAA/C,CAGb;EAAA;IAAA;;IAAA,+BAcQ;MACNC,OAAO,EACLC,IAAI,CAACC,GAAL,CAAS,KAAKC,KAAL,CAAWC,eAAX,CAA2BC,KAA3B,GAAmC,KAAKF,KAAL,CAAWE,KAAvD,IACA,KAAKF,KAAL,CAAWG;IAHP,CAdR;;IAAA;;IAAA,qCA4D2C,IA5D3C;;IAAA,qCA8DuBC,KAAD,IAAmB;MACvC,MAAM;QAAEF;MAAF,IAAY,KAAKF,KAAvB,CADuC,CAGvC;;MACA,IAAII,KAAK,KAAKF,KAAd,EAAqB;QACnB,KAAKG,QAAL,CAAeC,SAAD,IAAe;UAC3B,IAAIA,SAAS,CAACT,OAAd,EAAuB;YACrB,OAAO;cAAEA,OAAO,EAAE;YAAX,CAAP;UACD;;UAED,OAAO,IAAP;QACD,CAND;MAOD;IACF,CA3ED;EAAA;;EAC+B,OAAxBU,wBAAwB,CAACP,KAAD,EAAsBQ,KAAtB,EAAoC;IACjE,IACEA,KAAK,CAACX,OAAN,IACAC,IAAI,CAACC,GAAL,CAASC,KAAK,CAACC,eAAN,CAAsBC,KAAtB,GAA8BF,KAAK,CAACE,KAA7C,KACEF,KAAK,CAACG,mBAHV,EAIE;MACA;MACA,OAAO;QAAEN,OAAO,EAAE;MAAX,CAAP;IACD;;IAED,OAAO,IAAP;EACD;;EAQDY,i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;MAEE,yBAAyB,EAAEA,OAAO,GAAG,MAAH,GAAY,qBAFhD;MAGE,KAAK,EAAE,CACLC,MAAM,CAACC,KADF,EAEL;MACA;MACAJ,MAAM,CAACK,KAAP,GACI;QAAEA,KAAK,EAAEL,MAAM,CAACK;MAAhB,CADJ,GAEIH,OAAO,GACP9B,UAAU,CAACkC,YADJ,GAEP,IARC,EASLL,KATK;IAHT,GAgBI;IACA;IACA;IACAC,OAAO,IAAIF,MAAM,CAACK,KAAlB,GAA0B,KAAK3B,KAAL,CAAW6B,QAAX,CAAoB;MAAEhC;IAAF,CAApB,CAA1B,GAA6D,IAnBjE,CADF;EAwBD;;AA3GD;AA8GF,MAAM4B,MAAM,GAAG/B,UAAU,CAACoC,MAAX,CAAkB;EAC/BJ,KAAK,EAAE;IACLK,IAAI,EAAE,CADD;IAELC,QAAQ,EAAE;EAFL;AADwB,CAAlB,CAAf"}
1
+ {"version":3,"names":["React","StyleSheet","View","SceneView","children","navigationState","lazy","layout","index","lazyPreloadDistance","addEnterListener","style","isLoading","setIsLoading","useState","Math","abs","useEffect","handleEnter","value","prevState","unsubscribe","timer","setTimeout","clearTimeout","focused","styles","route","width","absoluteFill","loading","create","flex","overflow"],"sources":["SceneView.tsx"],"sourcesContent":["import * as React from 'react';\nimport { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';\n\nimport type {\n EventEmitterProps,\n NavigationState,\n Route,\n SceneRendererProps,\n} from './types';\n\ntype Props<T extends Route> = SceneRendererProps &\n EventEmitterProps & {\n navigationState: NavigationState<T>;\n lazy: boolean;\n lazyPreloadDistance: number;\n index: number;\n children: (props: { loading: boolean }) => React.ReactNode;\n style?: StyleProp<ViewStyle>;\n };\n\nexport default function SceneView<T extends Route>({\n children,\n navigationState,\n lazy,\n layout,\n index,\n lazyPreloadDistance,\n addEnterListener,\n style,\n}: Props<T>) {\n const [isLoading, setIsLoading] = React.useState(\n Math.abs(navigationState.index - index) > lazyPreloadDistance\n );\n\n if (\n isLoading &&\n Math.abs(navigationState.index - index) <= lazyPreloadDistance\n ) {\n // Always render the route when it becomes focused\n setIsLoading(false);\n }\n\n React.useEffect(() => {\n const handleEnter = (value: number) => {\n // If we're entering the current route, we need to load it\n if (value === index) {\n setIsLoading((prevState) => {\n if (prevState) {\n return false;\n }\n return prevState;\n });\n }\n };\n\n let unsubscribe: (() => void) | undefined;\n let timer: NodeJS.Timeout;\n\n if (lazy && isLoading) {\n // If lazy mode is enabled, listen to when we enter screens\n unsubscribe = addEnterListener(handleEnter);\n } else if (isLoading) {\n // If lazy mode is not enabled, render the scene with a delay if not loaded already\n // This improves the initial startup time as the scene is no longer blocking\n timer = setTimeout(() => setIsLoading(false), 0);\n }\n\n return () => {\n unsubscribe?.();\n clearTimeout(timer);\n };\n }, [addEnterListener, index, isLoading, lazy]);\n\n const focused = navigationState.index === index;\n\n return (\n <View\n accessibilityElementsHidden={!focused}\n importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}\n style={[\n styles.route,\n // If we don't have the layout yet, make the focused screen fill the container\n // This avoids delay before we are able to render pages side by side\n layout.width\n ? { width: layout.width }\n : focused\n ? StyleSheet.absoluteFill\n : null,\n style,\n ]}\n >\n {\n // Only render the route only if it's either focused or layout is available\n // When layout is not available, we must not render unfocused routes\n // so that the focused route can fill the screen\n focused || layout.width ? children({ loading: isLoading }) : null\n }\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n route: {\n flex: 1,\n overflow: 'hidden',\n },\n});\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAAoBC,UAApB,EAAgCC,IAAhC,QAAuD,cAAvD;AAmBA,eAAe,SAASC,SAAT,OASF;EAAA,IATsC;IACjDC,QADiD;IAEjDC,eAFiD;IAGjDC,IAHiD;IAIjDC,MAJiD;IAKjDC,KALiD;IAMjDC,mBANiD;IAOjDC,gBAPiD;IAQjDC;EARiD,CAStC;EACX,MAAM,CAACC,SAAD,EAAYC,YAAZ,IAA4Bb,KAAK,CAAC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