react-native-tab-view 3.2.0 → 3.3.0
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.
- package/README.md +4 -0
- package/lib/commonjs/PagerViewAdapter.js +25 -8
- package/lib/commonjs/PagerViewAdapter.js.map +1 -1
- package/lib/commonjs/PanResponderAdapter.js +29 -20
- package/lib/commonjs/PanResponderAdapter.js.map +1 -1
- package/lib/commonjs/SceneMap.js +9 -12
- package/lib/commonjs/SceneMap.js.map +1 -1
- package/lib/commonjs/SceneView.js +54 -101
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/TabBar.js +327 -327
- package/lib/commonjs/TabBar.js.map +1 -1
- package/lib/commonjs/TabBarIndicator.js +81 -99
- package/lib/commonjs/TabBarIndicator.js.map +1 -1
- package/lib/commonjs/TabBarItem.js +184 -161
- package/lib/commonjs/TabBarItem.js.map +1 -1
- package/lib/commonjs/TabView.js +3 -1
- package/lib/commonjs/TabView.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/PagerViewAdapter.js +25 -8
- package/lib/module/PagerViewAdapter.js.map +1 -1
- package/lib/module/PanResponderAdapter.js +29 -19
- package/lib/module/PanResponderAdapter.js.map +1 -1
- package/lib/module/SceneMap.js +9 -14
- package/lib/module/SceneMap.js.map +1 -1
- package/lib/module/SceneView.js +53 -98
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/TabBar.js +323 -323
- package/lib/module/TabBar.js.map +1 -1
- package/lib/module/TabBarIndicator.js +74 -92
- package/lib/module/TabBarIndicator.js.map +1 -1
- package/lib/module/TabBarItem.js +178 -154
- package/lib/module/TabBarItem.js.map +1 -1
- package/lib/module/TabView.js +3 -1
- package/lib/module/TabView.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/PagerViewAdapter.d.ts +1 -1
- package/lib/typescript/PanResponderAdapter.d.ts +1 -1
- package/lib/typescript/SceneMap.d.ts +5 -3
- package/lib/typescript/SceneView.d.ts +1 -18
- package/lib/typescript/TabBar.d.ts +7 -38
- package/lib/typescript/TabBarIndicator.d.ts +2 -10
- package/lib/typescript/TabBarItem.d.ts +3 -5
- package/lib/typescript/TabView.d.ts +1 -1
- package/lib/typescript/types.d.ts +1 -0
- package/package.json +4 -1
- package/src/PagerViewAdapter.tsx +29 -10
- package/src/PanResponderAdapter.tsx +29 -20
- package/src/SceneMap.tsx +11 -7
- package/src/SceneView.tsx +70 -106
- package/src/TabBar.tsx +451 -391
- package/src/TabBarIndicator.tsx +108 -114
- package/src/TabBarItem.tsx +214 -185
- package/src/TabView.tsx +2 -0
- package/src/types.tsx +1 -0
package/README.md
CHANGED
|
@@ -308,6 +308,10 @@ String indicating whether the keyboard gets dismissed in response to a drag gest
|
|
|
308
308
|
|
|
309
309
|
Boolean indicating whether to enable swipe gestures. Swipe gestures are enabled by default. Passing `false` will disable swipe gestures, but the user can still switch tabs by pressing the tab bar.
|
|
310
310
|
|
|
311
|
+
#### `animationEnabled`
|
|
312
|
+
|
|
313
|
+
Enables animation when changing tab. By default it's true.
|
|
314
|
+
|
|
311
315
|
##### `onSwipeStart`
|
|
312
316
|
|
|
313
317
|
Callback which is called when the swipe gesture starts, i.e. the user touches the screen and moves it.
|
|
@@ -33,6 +33,7 @@ function PagerViewAdapter(_ref) {
|
|
|
33
33
|
onSwipeEnd,
|
|
34
34
|
children,
|
|
35
35
|
style,
|
|
36
|
+
animationEnabled,
|
|
36
37
|
...rest
|
|
37
38
|
} = _ref;
|
|
38
39
|
const {
|
|
@@ -48,22 +49,37 @@ function PagerViewAdapter(_ref) {
|
|
|
48
49
|
navigationStateRef.current = navigationState;
|
|
49
50
|
});
|
|
50
51
|
const jumpTo = React.useCallback(key => {
|
|
51
|
-
var _pagerRef$current;
|
|
52
|
-
|
|
53
52
|
const index = navigationStateRef.current.routes.findIndex(route => route.key === key);
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
|
|
54
|
+
if (animationEnabled) {
|
|
55
|
+
var _pagerRef$current;
|
|
56
|
+
|
|
57
|
+
(_pagerRef$current = pagerRef.current) === null || _pagerRef$current === void 0 ? void 0 : _pagerRef$current.setPage(index);
|
|
58
|
+
} else {
|
|
59
|
+
var _pagerRef$current2;
|
|
60
|
+
|
|
61
|
+
(_pagerRef$current2 = pagerRef.current) === null || _pagerRef$current2 === void 0 ? void 0 : _pagerRef$current2.setPageWithoutAnimation(index);
|
|
62
|
+
position.setValue(index);
|
|
63
|
+
}
|
|
64
|
+
}, [animationEnabled, position]);
|
|
56
65
|
React.useEffect(() => {
|
|
57
66
|
if (keyboardDismissMode === 'auto') {
|
|
58
67
|
_reactNative.Keyboard.dismiss();
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
if (indexRef.current !== index) {
|
|
62
|
-
|
|
71
|
+
if (animationEnabled) {
|
|
72
|
+
var _pagerRef$current3;
|
|
63
73
|
|
|
64
|
-
|
|
74
|
+
(_pagerRef$current3 = pagerRef.current) === null || _pagerRef$current3 === void 0 ? void 0 : _pagerRef$current3.setPage(index);
|
|
75
|
+
} else {
|
|
76
|
+
var _pagerRef$current4;
|
|
77
|
+
|
|
78
|
+
(_pagerRef$current4 = pagerRef.current) === null || _pagerRef$current4 === void 0 ? void 0 : _pagerRef$current4.setPageWithoutAnimation(index);
|
|
79
|
+
position.setValue(index);
|
|
80
|
+
}
|
|
65
81
|
}
|
|
66
|
-
}, [keyboardDismissMode, index]);
|
|
82
|
+
}, [keyboardDismissMode, index, animationEnabled, position]);
|
|
67
83
|
|
|
68
84
|
const onPageScrollStateChanged = state => {
|
|
69
85
|
const {
|
|
@@ -105,8 +121,9 @@ function PagerViewAdapter(_ref) {
|
|
|
105
121
|
}
|
|
106
122
|
};
|
|
107
123
|
}, []);
|
|
124
|
+
const memoizedPosition = React.useMemo(() => _reactNative.Animated.add(position, offset), [offset, position]);
|
|
108
125
|
return children({
|
|
109
|
-
position:
|
|
126
|
+
position: memoizedPosition,
|
|
110
127
|
addEnterListener,
|
|
111
128
|
jumpTo,
|
|
112
129
|
render: children => /*#__PURE__*/React.createElement(AnimatedViewPager, _extends({}, rest, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AnimatedViewPager","Animated","createAnimatedComponent","ViewPager","PagerViewAdapter","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","rest","index","listenersRef","React","useRef","pagerRef","indexRef","navigationStateRef","position","useAnimatedValue","offset","useEffect","current","jumpTo","useCallback","key","routes","findIndex","route","setPage","Keyboard","dismiss","onPageScrollStateChanged","state","pageScrollState","nativeEvent","subscription","addListener","value","next","Math","ceil","floor","forEach","listener","removeListener","addEnterListener","push","indexOf","splice","add","render","styles","container","event","useNativeDriver","e","StyleSheet","create","flex"],"sources":["PagerViewAdapter.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Animated, Keyboard, StyleSheet } from 'react-native';\nimport ViewPager, {\n PageScrollStateChangedNativeEvent,\n} from 'react-native-pager-view';\nimport useAnimatedValue from './useAnimatedValue';\nimport type {\n NavigationState,\n Route,\n Listener,\n EventEmitterProps,\n PagerProps,\n} from './types';\n\nconst AnimatedViewPager = Animated.createAnimatedComponent(ViewPager);\n\ntype Props<T extends Route> = PagerProps & {\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\nexport default function PagerViewAdapter<T extends Route>({\n keyboardDismissMode = 'auto',\n swipeEnabled = true,\n navigationState,\n onIndexChange,\n onSwipeStart,\n onSwipeEnd,\n children,\n style,\n ...rest\n}: Props<T>) {\n const { index } = navigationState;\n\n const listenersRef = React.useRef<Listener[]>([]);\n\n const pagerRef = React.useRef<ViewPager>();\n const indexRef = React.useRef<number>(index);\n const navigationStateRef = React.useRef(navigationState);\n\n const position = useAnimatedValue(index);\n const offset = useAnimatedValue(0);\n\n React.useEffect(() => {\n navigationStateRef.current = navigationState;\n });\n\n const jumpTo = React.useCallback((key: string) => {\n
|
|
1
|
+
{"version":3,"names":["AnimatedViewPager","Animated","createAnimatedComponent","ViewPager","PagerViewAdapter","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","animationEnabled","rest","index","listenersRef","React","useRef","pagerRef","indexRef","navigationStateRef","position","useAnimatedValue","offset","useEffect","current","jumpTo","useCallback","key","routes","findIndex","route","setPage","setPageWithoutAnimation","setValue","Keyboard","dismiss","onPageScrollStateChanged","state","pageScrollState","nativeEvent","subscription","addListener","value","next","Math","ceil","floor","forEach","listener","removeListener","addEnterListener","push","indexOf","splice","memoizedPosition","useMemo","add","render","styles","container","event","useNativeDriver","e","StyleSheet","create","flex"],"sources":["PagerViewAdapter.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Animated, Keyboard, StyleSheet } from 'react-native';\nimport ViewPager, {\n PageScrollStateChangedNativeEvent,\n} from 'react-native-pager-view';\nimport useAnimatedValue from './useAnimatedValue';\nimport type {\n NavigationState,\n Route,\n Listener,\n EventEmitterProps,\n PagerProps,\n} from './types';\n\nconst AnimatedViewPager = Animated.createAnimatedComponent(ViewPager);\n\ntype Props<T extends Route> = PagerProps & {\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\nexport default function PagerViewAdapter<T extends Route>({\n keyboardDismissMode = 'auto',\n swipeEnabled = true,\n navigationState,\n onIndexChange,\n onSwipeStart,\n onSwipeEnd,\n children,\n style,\n animationEnabled,\n ...rest\n}: Props<T>) {\n const { index } = navigationState;\n\n const listenersRef = React.useRef<Listener[]>([]);\n\n const pagerRef = React.useRef<ViewPager>();\n const indexRef = React.useRef<number>(index);\n const navigationStateRef = React.useRef(navigationState);\n\n const position = useAnimatedValue(index);\n const offset = useAnimatedValue(0);\n\n React.useEffect(() => {\n navigationStateRef.current = navigationState;\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 if (animationEnabled) {\n pagerRef.current?.setPage(index);\n } else {\n pagerRef.current?.setPageWithoutAnimation(index);\n position.setValue(index);\n }\n },\n [animationEnabled, position]\n );\n\n React.useEffect(() => {\n if (keyboardDismissMode === 'auto') {\n Keyboard.dismiss();\n }\n\n if (indexRef.current !== index) {\n if (animationEnabled) {\n pagerRef.current?.setPage(index);\n } else {\n pagerRef.current?.setPageWithoutAnimation(index);\n position.setValue(index);\n }\n }\n }, [keyboardDismissMode, index, animationEnabled, position]);\n\n const onPageScrollStateChanged = (\n state: PageScrollStateChangedNativeEvent\n ) => {\n const { pageScrollState } = state.nativeEvent;\n\n switch (pageScrollState) {\n case 'idle':\n onSwipeEnd?.();\n return;\n case 'dragging': {\n const subscription = offset.addListener(({ value }) => {\n const next =\n index + (value > 0 ? Math.ceil(value) : Math.floor(value));\n\n if (next !== index) {\n listenersRef.current.forEach((listener) => listener(next));\n }\n\n offset.removeListener(subscription);\n });\n\n onSwipeStart?.();\n return;\n }\n }\n };\n\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 memoizedPosition = React.useMemo(\n () => Animated.add(position, offset),\n [offset, position]\n );\n\n return children({\n position: memoizedPosition,\n addEnterListener,\n jumpTo,\n render: (children) => (\n <AnimatedViewPager\n {...rest}\n ref={pagerRef}\n style={[styles.container, style]}\n initialPage={index}\n keyboardDismissMode={\n keyboardDismissMode === 'auto' ? 'on-drag' : keyboardDismissMode\n }\n onPageScroll={Animated.event(\n [\n {\n nativeEvent: {\n position: position,\n offset: offset,\n },\n },\n ],\n { useNativeDriver: true }\n )}\n onPageSelected={(e) => {\n const index = e.nativeEvent.position;\n indexRef.current = index;\n onIndexChange(index);\n }}\n onPageScrollStateChanged={onPageScrollStateChanged}\n scrollEnabled={swipeEnabled}\n >\n {children}\n </AnimatedViewPager>\n ),\n });\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAGA;;;;;;;;;;AASA,MAAMA,iBAAiB,GAAGC,qBAAA,CAASC,uBAAT,CAAiCC,6BAAjC,CAA1B;;AAoBe,SAASC,gBAAT,OAWF;EAAA,IAX6C;IACxDC,mBAAmB,GAAG,MADkC;IAExDC,YAAY,GAAG,IAFyC;IAGxDC,eAHwD;IAIxDC,aAJwD;IAKxDC,YALwD;IAMxDC,UANwD;IAOxDC,QAPwD;IAQxDC,KARwD;IASxDC,gBATwD;IAUxD,GAAGC;EAVqD,CAW7C;EACX,MAAM;IAAEC;EAAF,IAAYR,eAAlB;EAEA,MAAMS,YAAY,GAAGC,KAAK,CAACC,MAAN,CAAyB,EAAzB,CAArB;EAEA,MAAMC,QAAQ,GAAGF,KAAK,CAACC,MAAN,EAAjB;EACA,MAAME,QAAQ,GAAGH,KAAK,CAACC,MAAN,CAAqBH,KAArB,CAAjB;EACA,MAAMM,kBAAkB,GAAGJ,KAAK,CAACC,MAAN,CAAaX,eAAb,CAA3B;EAEA,MAAMe,QAAQ,GAAG,IAAAC,yBAAA,EAAiBR,KAAjB,CAAjB;EACA,MAAMS,MAAM,GAAG,IAAAD,yBAAA,EAAiB,CAAjB,CAAf;E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AAEkC,gBADI;IAEdJ,gBAFc;IAGdzB,MAHc;IAIdgC,MAAM,EAAGhD,QAAD,iBACN,oBAAC,iBAAD,eACMG,IADN;MAEE,GAAG,EAAEK,QAFP;MAGE,KAAK,EAAE,CAACyC,MAAM,CAACC,SAAR,EAAmBjD,KAAnB,CAHT;MAIE,WAAW,EAAEG,KAJf;MAKE,mBAAmB,EACjBV,mBAAmB,KAAK,MAAxB,GAAiC,SAAjC,GAA6CA,mBANjD;MAQE,YAAY,EAAEJ,qBAAA,CAAS6D,KAAT,CACZ,CACE;QACErB,WAAW,EAAE;UACXnB,QAAQ,EAAEA,QADC;UAEXE,MAAM,EAAEA;QAFG;MADf,CADF,CADY,EASZ;QAAEuC,eAAe,EAAE;MAAnB,CATY,CARhB;MAmBE,cAAc,EAAGC,CAAD,IAAO;QACrB,MAAMjD,KAAK,GAAGiD,CAAC,CAACvB,WAAF,CAAcnB,QAA5B;QACAF,QAAQ,CAACM,OAAT,GAAmBX,KAAnB;QACAP,aAAa,CAACO,KAAD,CAAb;MACD,CAvBH;MAwBE,wBAAwB,EAAEuB,wBAxB5B;MAyBE,aAAa,EAAEhC;IAzBjB,IA2BGK,QA3BH;EALY,CAAD,CAAf;AAoCD;;AAED,MAAMiD,MAAM,GAAGK,uBAAA,CAAWC,MAAX,CAAkB;EAC/BL,SAAS,EAAE;IACTM,IAAI,EAAE;EADG;AADoB,CAAlB,CAAf"}
|
|
@@ -38,7 +38,8 @@ function PanResponderAdapter(_ref) {
|
|
|
38
38
|
onSwipeStart,
|
|
39
39
|
onSwipeEnd,
|
|
40
40
|
children,
|
|
41
|
-
style
|
|
41
|
+
style,
|
|
42
|
+
animationEnabled = false
|
|
42
43
|
} = _ref;
|
|
43
44
|
const {
|
|
44
45
|
routes,
|
|
@@ -53,29 +54,36 @@ function PanResponderAdapter(_ref) {
|
|
|
53
54
|
const pendingIndexRef = React.useRef();
|
|
54
55
|
const swipeVelocityThreshold = 0.15;
|
|
55
56
|
const swipeDistanceThreshold = layout.width / 1.75;
|
|
56
|
-
const jumpToIndex = React.useCallback(index
|
|
57
|
+
const jumpToIndex = React.useCallback(function (index) {
|
|
58
|
+
let animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : animationEnabled;
|
|
57
59
|
const offset = -index * layoutRef.current.width;
|
|
58
60
|
const {
|
|
59
61
|
timing,
|
|
60
62
|
...transitionConfig
|
|
61
63
|
} = DefaultTransitionSpec;
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
65
|
+
if (animate) {
|
|
66
|
+
_reactNative.Animated.parallel([timing(panX, { ...transitionConfig,
|
|
67
|
+
toValue: offset,
|
|
68
|
+
useNativeDriver: false
|
|
69
|
+
})]).start(_ref2 => {
|
|
70
|
+
let {
|
|
71
|
+
finished
|
|
72
|
+
} = _ref2;
|
|
73
|
+
|
|
74
|
+
if (finished) {
|
|
75
|
+
onIndexChangeRef.current(index);
|
|
76
|
+
pendingIndexRef.current = undefined;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
pendingIndexRef.current = index;
|
|
81
|
+
} else {
|
|
82
|
+
panX.setValue(offset);
|
|
83
|
+
onIndexChangeRef.current(index);
|
|
84
|
+
pendingIndexRef.current = undefined;
|
|
85
|
+
}
|
|
86
|
+
}, [animationEnabled, panX]);
|
|
79
87
|
React.useEffect(() => {
|
|
80
88
|
navigationStateRef.current = navigationState;
|
|
81
89
|
layoutRef.current = layout;
|
|
@@ -158,7 +166,7 @@ function PanResponderAdapter(_ref) {
|
|
|
158
166
|
nextIndex = currentIndex;
|
|
159
167
|
}
|
|
160
168
|
|
|
161
|
-
jumpToIndex(nextIndex);
|
|
169
|
+
jumpToIndex(nextIndex, true);
|
|
162
170
|
}; // TODO: use the listeners
|
|
163
171
|
|
|
164
172
|
|
|
@@ -195,8 +203,9 @@ function PanResponderAdapter(_ref) {
|
|
|
195
203
|
extrapolate: 'clamp'
|
|
196
204
|
}), _reactNative.I18nManager.isRTL ? -1 : 1);
|
|
197
205
|
|
|
206
|
+
const position = React.useMemo(() => layout.width ? _reactNative.Animated.divide(panX, -layout.width) : null, [layout.width, panX]);
|
|
198
207
|
return children({
|
|
199
|
-
position:
|
|
208
|
+
position: position ?? new _reactNative.Animated.Value(index),
|
|
200
209
|
addEnterListener,
|
|
201
210
|
jumpTo,
|
|
202
211
|
render: children => /*#__PURE__*/React.createElement(_reactNative.Animated.View, _extends({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEAD_ZONE","DefaultTransitionSpec","timing","Animated","spring","stiffness","damping","mass","overshootClamping","PanResponderAdapter","layout","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","routes","index","panX","useAnimatedValue","listenersRef","React","useRef","navigationStateRef","layoutRef","onIndexChangeRef","currentIndexRef","pendingIndexRef","swipeVelocityThreshold","swipeDistanceThreshold","width","jumpToIndex","useCallback","offset","current","transitionConfig","parallel","toValue","useNativeDriver","start","finished","undefined","useEffect","setValue","Keyboard","dismiss","isMovingHorizontally","_","gestureState","Math","abs","dx","dy","vx","vy","canMoveScreen","event","diffX","I18nManager","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","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","StyleSheet","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}: 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"],"mappings":";;;;;;;AAAA;;AACA;;AAUA;;;;;;;;;;AA6BA,MAAMA,SAAS,GAAG,EAAlB;AAEA,MAAMC,qBAAqB,GAAG;EAC5BC,MAAM,EAAEC,qBAAA,CAASC,MADW;EAE5BC,SAAS,EAAE,IAFiB;EAG5BC,OAAO,EAAE,GAHmB;EAI5BC,IAAI,EAAE,CAJsB;EAK5BC,iBAAiB,EAAE;AALS,CAA9B;;AAQe,SAASC,mBAAT,OAUF;EAAA,IAVgD;IAC3DC,MAD2D;IAE3DC,mBAAmB,GAAG,MAFqC;IAG3DC,YAAY,GAAG,IAH4C;IAI3DC,eAJ2D;IAK3DC,aAL2D;IAM3DC,YAN2D;IAO3DC,UAP2D;IAQ3DC,QAR2D;IAS3DC;EAT2D,CAUhD;EACX,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAoBP,eAA1B;EAEA,MAAMQ,IAAI,GAAG,IAAAC,yBAAA,EAAiB,CAAjB,CAAb;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,CADJ,GAEIuF,OAAO,GACPC,uBAAA,CAAWC,YADJ,GAEP;MAPR,GAUGF,OAAO,IAAI9G,MAAM,CAACuB,KAAlB,GAA0BqF,KAA1B,GAAkC,IAVrC,CADF;IAcD,CAlBA,CAbH;EAPY,CAAD,CAAf;AA0CD;;AAED,MAAMN,MAAM,GAAGS,uBAAA,CAAW3B,MAAX,CAAkB;EAC/BmB,KAAK,EAAE;IACLU,IAAI,EAAE,CADD;IAELC,aAAa,EAAE,KAFV;IAGLC,UAAU,EAAE;EAHP;AADwB,CAAlB,CAAf"}
|
|
1
|
+
{"version":3,"names":["DEAD_ZONE","DefaultTransitionSpec","timing","Animated","spring","stiffness","damping","mass","overshootClamping","PanResponderAdapter","layout","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","animationEnabled","routes","index","panX","useAnimatedValue","listenersRef","React","useRef","navigationStateRef","layoutRef","onIndexChangeRef","currentIndexRef","pendingIndexRef","swipeVelocityThreshold","swipeDistanceThreshold","width","jumpToIndex","useCallback","animate","offset","current","transitionConfig","parallel","toValue","useNativeDriver","start","finished","undefined","setValue","useEffect","Keyboard","dismiss","isMovingHorizontally","_","gestureState","Math","abs","dx","dy","vx","vy","canMoveScreen","event","diffX","I18nManager","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","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","StyleSheet","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 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;;AACA;;AAUA;;;;;;;;;;AA6BA,MAAMA,SAAS,GAAG,EAAlB;AAEA,MAAMC,qBAAqB,GAAG;EAC5BC,MAAM,EAAEC,qBAAA,CAASC,MADW;EAE5BC,SAAS,EAAE,IAFiB;EAG5BC,OAAO,EAAE,GAHmB;EAI5BC,IAAI,EAAE,CAJsB;EAK5BC,iBAAiB,EAAE;AALS,CAA9B;;AAQe,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;IAA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P,GAAgBvD,MAAM,CAACwB,KADhC;QAEEmF,SAAS,EAAE,CAAC;UAAEZ;QAAF,CAAD;MAFb,CADJ,GAKI,IAPC,EAQLvF,KARK;IADT,GAWM4E,YAAY,CAACwB,WAXnB,GAaG7F,KAAK,CAAC8F,QAAN,CAAeC,GAAf,CAAmBvG,QAAnB,EAA6B,CAACwG,KAAD,EAAQC,CAAR,KAAc;MAC1C,MAAM7B,KAAK,GAAGzE,MAAM,CAACsG,CAAD,CAApB;MACA,MAAMC,OAAO,GAAGD,CAAC,KAAKrG,KAAtB;MAEA,oBACE,oBAAC,iBAAD;QACE,GAAG,EAAEwE,KAAK,CAACF,GADb;QAEE,KAAK,EACHjF,MAAM,CAACwB,KAAP,GACI;UAAEA,KAAK,EAAExB,MAAM,CAACwB;QAAhB,CADJ,GAEIyF,OAAO,GACPC,uBAAA,CAAWC,YADJ,GAEP;MAPR,GAUGF,OAAO,IAAIjH,MAAM,CAACwB,KAAlB,GAA0BuF,KAA1B,GAAkC,IAVrC,CADF;IAcD,CAlBA,CAbH;EALY,CAAD,CAAf;AAwCD;;AAED,MAAMN,MAAM,GAAGS,uBAAA,CAAW5B,MAAX,CAAkB;EAC/BoB,KAAK,EAAE;IACLU,IAAI,EAAE,CADD;IAELC,aAAa,EAAE,KAFV;IAGLC,UAAU,EAAE;EAHP;AADwB,CAAlB,CAAf"}
|
package/lib/commonjs/SceneMap.js
CHANGED
|
@@ -11,24 +11,21 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
|
14
|
+
const SceneComponent = /*#__PURE__*/React.memo(_ref => {
|
|
15
|
+
let {
|
|
16
|
+
component,
|
|
17
|
+
...rest
|
|
18
|
+
} = _ref;
|
|
19
|
+
return /*#__PURE__*/React.createElement(component, rest);
|
|
20
|
+
});
|
|
24
21
|
|
|
25
22
|
function SceneMap(scenes) {
|
|
26
|
-
return
|
|
23
|
+
return _ref2 => {
|
|
27
24
|
let {
|
|
28
25
|
route,
|
|
29
26
|
jumpTo,
|
|
30
27
|
position
|
|
31
|
-
} =
|
|
28
|
+
} = _ref2;
|
|
32
29
|
return /*#__PURE__*/React.createElement(SceneComponent, {
|
|
33
30
|
key: route.key,
|
|
34
31
|
component: scenes[route.key],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SceneComponent","React","
|
|
1
|
+
{"version":3,"names":["SceneComponent","React","memo","component","rest","createElement","SceneMap","scenes","route","jumpTo","position","key"],"sources":["SceneMap.tsx"],"sourcesContent":["import * as React from 'react';\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;;;;;;AAOA,MAAMA,cAAc,gBAAGC,KAAK,CAACC,IAAN,CACrB,QAGS;EAAA,IAHwD;IAC/DC,SAD+D;IAE/D,GAAGC;EAF4D,CAGxD;EACP,oBAAOH,KAAK,CAACI,aAAN,CAAoBF,SAApB,EAA+BC,IAA/B,CAAP;AACD,CANoB,CAAvB;;AASe,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"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = SceneView;
|
|
7
7
|
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
@@ -13,121 +13,74 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
15
|
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} = this.props; // If we're entering the current route, we need to load it
|
|
16
|
+
function SceneView(_ref) {
|
|
17
|
+
let {
|
|
18
|
+
children,
|
|
19
|
+
navigationState,
|
|
20
|
+
lazy,
|
|
21
|
+
layout,
|
|
22
|
+
index,
|
|
23
|
+
lazyPreloadDistance,
|
|
24
|
+
addEnterListener,
|
|
25
|
+
style
|
|
26
|
+
} = _ref;
|
|
27
|
+
const [isLoading, setIsLoading] = React.useState(Math.abs(navigationState.index - index) > lazyPreloadDistance);
|
|
28
|
+
|
|
29
|
+
if (isLoading && Math.abs(navigationState.index - index) <= lazyPreloadDistance) {
|
|
30
|
+
// Always render the route when it becomes focused
|
|
31
|
+
setIsLoading(false);
|
|
32
|
+
}
|
|
34
33
|
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
const handleEnter = value => {
|
|
36
|
+
// If we're entering the current route, we need to load it
|
|
35
37
|
if (value === index) {
|
|
36
|
-
|
|
37
|
-
if (prevState
|
|
38
|
-
return
|
|
39
|
-
loading: false
|
|
40
|
-
};
|
|
38
|
+
setIsLoading(prevState => {
|
|
39
|
+
if (prevState) {
|
|
40
|
+
return false;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
return
|
|
43
|
+
return prevState;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static getDerivedStateFromProps(props, state) {
|
|
50
|
-
if (state.loading && Math.abs(props.navigationState.index - props.index) <= props.lazyPreloadDistance) {
|
|
51
|
-
// Always render the route when it becomes focused
|
|
52
|
-
return {
|
|
53
|
-
loading: false
|
|
54
|
-
};
|
|
55
|
-
}
|
|
46
|
+
};
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
let unsubscribe;
|
|
49
|
+
let timer;
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
if (this.props.lazy) {
|
|
51
|
+
if (lazy && isLoading) {
|
|
62
52
|
// If lazy mode is enabled, listen to when we enter screens
|
|
63
|
-
|
|
64
|
-
} else if (
|
|
53
|
+
unsubscribe = addEnterListener(handleEnter);
|
|
54
|
+
} else if (isLoading) {
|
|
65
55
|
// If lazy mode is not enabled, render the scene with a delay if not loaded already
|
|
66
56
|
// This improves the initial startup time as the scene is no longer blocking
|
|
67
|
-
|
|
68
|
-
loading: false
|
|
69
|
-
}), 0);
|
|
57
|
+
timer = setTimeout(() => setIsLoading(false), 0);
|
|
70
58
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
componentDidUpdate(prevProps, prevState) {
|
|
74
|
-
if (this.props.lazy !== prevProps.lazy || this.state.loading !== prevState.loading) {
|
|
75
|
-
// We only need the listener if the tab hasn't loaded yet and lazy is enabled
|
|
76
|
-
if (this.props.lazy && this.state.loading) {
|
|
77
|
-
var _this$unsubscribe;
|
|
78
|
-
|
|
79
|
-
(_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
|
|
80
|
-
this.unsubscribe = this.props.addEnterListener(this.handleEnter);
|
|
81
|
-
} else {
|
|
82
|
-
var _this$unsubscribe2;
|
|
83
|
-
|
|
84
|
-
(_this$unsubscribe2 = this.unsubscribe) === null || _this$unsubscribe2 === void 0 ? void 0 : _this$unsubscribe2.call(this);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
componentWillUnmount() {
|
|
90
|
-
var _this$unsubscribe3;
|
|
91
|
-
|
|
92
|
-
(_this$unsubscribe3 = this.unsubscribe) === null || _this$unsubscribe3 === void 0 ? void 0 : _this$unsubscribe3.call(this);
|
|
93
|
-
|
|
94
|
-
if (this.timerHandler) {
|
|
95
|
-
clearTimeout(this.timerHandler);
|
|
96
|
-
this.timerHandler = undefined;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
render() {
|
|
101
|
-
const {
|
|
102
|
-
navigationState,
|
|
103
|
-
index,
|
|
104
|
-
layout,
|
|
105
|
-
style
|
|
106
|
-
} = this.props;
|
|
107
|
-
const {
|
|
108
|
-
loading
|
|
109
|
-
} = this.state;
|
|
110
|
-
const focused = navigationState.index === index;
|
|
111
|
-
return /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
112
|
-
accessibilityElementsHidden: !focused,
|
|
113
|
-
importantForAccessibility: focused ? 'auto' : 'no-hide-descendants',
|
|
114
|
-
style: [styles.route, // If we don't have the layout yet, make the focused screen fill the container
|
|
115
|
-
// This avoids delay before we are able to render pages side by side
|
|
116
|
-
layout.width ? {
|
|
117
|
-
width: layout.width
|
|
118
|
-
} : focused ? _reactNative.StyleSheet.absoluteFill : null, style]
|
|
119
|
-
}, // Only render the route only if it's either focused or layout is available
|
|
120
|
-
// When layout is not available, we must not render unfocused routes
|
|
121
|
-
// so that the focused route can fill the screen
|
|
122
|
-
focused || layout.width ? this.props.children({
|
|
123
|
-
loading
|
|
124
|
-
}) : null);
|
|
125
|
-
}
|
|
126
59
|
|
|
60
|
+
return () => {
|
|
61
|
+
var _unsubscribe;
|
|
62
|
+
|
|
63
|
+
(_unsubscribe = unsubscribe) === null || _unsubscribe === void 0 ? void 0 : _unsubscribe();
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
};
|
|
66
|
+
}, [addEnterListener, index, isLoading, lazy]);
|
|
67
|
+
const focused = navigationState.index === index;
|
|
68
|
+
return /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
69
|
+
accessibilityElementsHidden: !focused,
|
|
70
|
+
importantForAccessibility: focused ? 'auto' : 'no-hide-descendants',
|
|
71
|
+
style: [styles.route, // If we don't have the layout yet, make the focused screen fill the container
|
|
72
|
+
// This avoids delay before we are able to render pages side by side
|
|
73
|
+
layout.width ? {
|
|
74
|
+
width: layout.width
|
|
75
|
+
} : focused ? _reactNative.StyleSheet.absoluteFill : null, style]
|
|
76
|
+
}, // Only render the route only if it's either focused or layout is available
|
|
77
|
+
// When layout is not available, we must not render unfocused routes
|
|
78
|
+
// so that the focused route can fill the screen
|
|
79
|
+
focused || layout.width ? children({
|
|
80
|
+
loading: isLoading
|
|
81
|
+
}) : null);
|
|
127
82
|
}
|
|
128
83
|
|
|
129
|
-
exports.default = SceneView;
|
|
130
|
-
|
|
131
84
|
const styles = _reactNative.StyleSheet.create({
|
|
132
85
|
route: {
|
|
133
86
|
flex: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SceneView","
|
|
1
|
+
{"version":3,"names":["SceneView","children","navigationState","lazy","layout","index","lazyPreloadDistance","addEnterListener","style","isLoading","setIsLoading","React","useState","Math","abs","useEffect","handleEnter","value","prevState","unsubscribe","timer","setTimeout","clearTimeout","focused","styles","route","width","StyleSheet","absoluteFill","loading","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\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;;AACA;;;;;;AAkBe,SAASA,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,IAA4BC,KAAK,CAACC,QAAN,CAChCC,IAAI,CAACC,GAAL,CAASZ,eAAe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