react-native-tab-view 5.0.0-alpha.7 → 5.0.0-alpha.9
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/lib/module/DefaultAdapter.android.js +4 -0
- package/lib/module/DefaultAdapter.android.js.map +1 -0
- package/lib/module/DefaultAdapter.ios.js +4 -0
- package/lib/module/DefaultAdapter.ios.js.map +1 -0
- package/lib/module/DefaultAdapter.js +5 -0
- package/lib/module/DefaultAdapter.js.map +1 -0
- package/lib/module/PagerViewAdapter.native.js +29 -13
- package/lib/module/PagerViewAdapter.native.js.map +1 -1
- package/lib/module/PlatformPressable.js +1 -1
- package/lib/module/ScrollViewAdapter.js +46 -18
- package/lib/module/ScrollViewAdapter.js.map +1 -1
- package/lib/module/TabBar.js +260 -148
- package/lib/module/TabBar.js.map +1 -1
- package/lib/module/TabBarIndicator.js +282 -168
- package/lib/module/TabBarIndicator.js.map +1 -1
- package/lib/module/TabBarItem.js +94 -44
- package/lib/module/TabBarItem.js.map +1 -1
- package/lib/module/TabBarItemLabel.js +3 -2
- package/lib/module/TabBarItemLabel.js.map +1 -1
- package/lib/module/TabView.js +2 -2
- package/lib/module/TabView.js.map +1 -1
- package/lib/module/constants.js +10 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/useLayoutWidths.js +46 -0
- package/lib/module/useLayoutWidths.js.map +1 -0
- package/lib/typescript/src/DefaultAdapter.android.d.ts +2 -0
- package/lib/typescript/src/DefaultAdapter.android.d.ts.map +1 -0
- package/lib/typescript/src/DefaultAdapter.d.ts +6 -0
- package/lib/typescript/src/DefaultAdapter.d.ts.map +1 -0
- package/lib/typescript/src/DefaultAdapter.ios.d.ts +2 -0
- package/lib/typescript/src/DefaultAdapter.ios.d.ts.map +1 -0
- package/lib/typescript/src/PagerViewAdapter.native.d.ts +1 -1
- package/lib/typescript/src/PagerViewAdapter.native.d.ts.map +1 -1
- package/lib/typescript/src/ScrollViewAdapter.d.ts +1 -2
- package/lib/typescript/src/ScrollViewAdapter.d.ts.map +1 -1
- package/lib/typescript/src/TabBar.d.ts +2 -1
- package/lib/typescript/src/TabBar.d.ts.map +1 -1
- package/lib/typescript/src/TabBarIndicator.d.ts +4 -7
- package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -1
- package/lib/typescript/src/TabBarItem.d.ts +10 -4
- package/lib/typescript/src/TabBarItem.d.ts.map +1 -1
- package/lib/typescript/src/TabBarItemLabel.d.ts +4 -3
- package/lib/typescript/src/TabBarItemLabel.d.ts.map +1 -1
- package/lib/typescript/src/TabView.d.ts.map +1 -1
- package/lib/typescript/src/constants.d.ts +8 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/useLayoutWidths.d.ts +2 -0
- package/lib/typescript/src/useLayoutWidths.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/DefaultAdapter.android.tsx +1 -0
- package/src/DefaultAdapter.ios.tsx +1 -0
- package/src/DefaultAdapter.tsx +13 -0
- package/src/PagerViewAdapter.native.tsx +36 -18
- package/src/PlatformPressable.tsx +1 -1
- package/src/ScrollViewAdapter.tsx +81 -21
- package/src/TabBar.tsx +386 -181
- package/src/TabBarIndicator.tsx +323 -248
- package/src/TabBarItem.tsx +102 -41
- package/src/TabBarItemLabel.tsx +5 -4
- package/src/TabView.tsx +2 -2
- package/src/constants.tsx +8 -0
- package/src/index.tsx +5 -1
- package/src/useLayoutWidths.tsx +51 -0
- package/lib/module/Pager.android.js +0 -4
- package/lib/module/Pager.android.js.map +0 -1
- package/lib/module/Pager.ios.js +0 -4
- package/lib/module/Pager.ios.js.map +0 -1
- package/lib/module/Pager.js +0 -4
- package/lib/module/Pager.js.map +0 -1
- package/lib/typescript/src/Pager.android.d.ts +0 -2
- package/lib/typescript/src/Pager.android.d.ts.map +0 -1
- package/lib/typescript/src/Pager.d.ts +0 -2
- package/lib/typescript/src/Pager.d.ts.map +0 -1
- package/lib/typescript/src/Pager.ios.d.ts +0 -2
- package/lib/typescript/src/Pager.ios.d.ts.map +0 -1
- package/src/Pager.android.tsx +0 -1
- package/src/Pager.ios.tsx +0 -1
- package/src/Pager.tsx +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabBarItemLabel.d.ts","sourceRoot":"","sources":["../../../src/TabBarItemLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGrE,UAAU,oBAAoB;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,
|
|
1
|
+
{"version":3,"file":"TabBarItemLabel.d.ts","sourceRoot":"","sources":["../../../src/TabBarItemLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGrE,UAAU,oBAAoB;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;IACtB,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACxC;AAED,eAAO,MAAM,eAAe,8EACwB,oBAAoB,oDAmBvE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabView.d.ts","sourceRoot":"","sources":["../../../src/TabView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAGL,KAAK,SAAS,EAGd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAKtB,OAA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EG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAC9C;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACzC;;OAEG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,kBAAkB,GAAG;QAAE,KAAK,EAAE,CAAC,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAC;IAC3E;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACvD;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CAC9C,CAAC;AAIF,wBAAgB,OAAO,CAAC,CAAC,SAAS,KAAK,EAAE,EACvC,aAAa,EACb,WAAW,EACX,eAAe,EACf,WAAW,EACX,mBAA4B,EAC5B,IAAY,EACZ,mBAAuB,EACvB,YAAY,EACZ,UAAU,EACV,qBAAoD,EAEpD,YAA+C,EAE/C,aAAwD,EACxD,UAAU,EACV,KAAK,EACL,SAA4D,EAC5D,YAAmB,EACnB,cAAsB,EACtB,gBAAuB,EACvB,OAAO,EAAE,YAAY,EACrB,aAAa,GACd,EAAE,KAAK,CAAC,CAAC,CAAC,2CAgGV"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const TAB_BAR_PRIMARY_ACTIVE_COLOR = "#6750a4";
|
|
2
|
+
export declare const TAB_BAR_SECONDARY_ACTIVE_COLOR = "#1d1b20";
|
|
3
|
+
export declare const TAB_BAR_INACTIVE_COLOR = "#49454f";
|
|
4
|
+
export declare const TAB_BAR_BACKGROUND_COLOR = "#fef7ff";
|
|
5
|
+
export declare const TAB_BAR_BORDER_COLOR = "#cac4d0";
|
|
6
|
+
export declare const PRIMARY_INDICATOR_MIN_WIDTH = 24;
|
|
7
|
+
export declare const TAB_MIN_WIDTH = 90;
|
|
8
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.tsx"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,YAAY,CAAC;AACtD,eAAO,MAAM,8BAA8B,YAAY,CAAC;AACxD,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAChD,eAAO,MAAM,wBAAwB,YAAY,CAAC;AAClD,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAE9C,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,eAAO,MAAM,aAAa,KAAK,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export { DefaultAdapter, type DefaultAdapterProps } from './DefaultAdapter';
|
|
1
2
|
export { PagerViewAdapter, type PagerViewAdapterProps, } from './PagerViewAdapter';
|
|
2
|
-
export { PanResponderAdapter } from './PanResponderAdapter';
|
|
3
|
+
export { PanResponderAdapter, type PanResponderAdapterProps, } from './PanResponderAdapter';
|
|
3
4
|
export { SceneMap } from './SceneMap';
|
|
4
5
|
export { ScrollViewAdapter, type ScrollViewAdapterProps, } from './ScrollViewAdapter';
|
|
5
6
|
export type { Props as TabBarProps } from './TabBar';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,mBAAmB,EACnB,KAAK,wBAAwB,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,KAAK,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,YAAY,EACZ,eAAe,EACf,KAAK,EACL,kBAAkB,EAClB,aAAa,GACd,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLayoutWidths.d.ts","sourceRoot":"","sources":["../../../src/useLayoutWidths.tsx"],"names":[],"mappings":"AAIA,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,2CAkBL,MAAM,SAAS,MAAM,iBA4BrE"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-tab-view",
|
|
3
3
|
"description": "Tab view component for React Native",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.9",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native-component",
|
|
7
7
|
"react-component",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
]
|
|
81
81
|
]
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "f7b2582ce8d3c3fbe4188b271dd194f46f773654"
|
|
84
84
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PagerViewAdapter as DefaultAdapter } from './PagerViewAdapter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PagerViewAdapter as DefaultAdapter } from './PagerViewAdapter';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { PagerViewAdapterProps } from './PagerViewAdapter';
|
|
4
|
+
import {
|
|
5
|
+
PanResponderAdapter,
|
|
6
|
+
type PanResponderAdapterProps,
|
|
7
|
+
} from './PanResponderAdapter';
|
|
8
|
+
|
|
9
|
+
export type DefaultAdapterProps = PagerViewAdapterProps &
|
|
10
|
+
PanResponderAdapterProps;
|
|
11
|
+
|
|
12
|
+
export const DefaultAdapter: React.ComponentType<DefaultAdapterProps> =
|
|
13
|
+
PanResponderAdapter;
|
|
@@ -36,9 +36,19 @@ export function PagerViewAdapter({
|
|
|
36
36
|
children,
|
|
37
37
|
style,
|
|
38
38
|
animationEnabled,
|
|
39
|
+
layoutDirection = 'ltr',
|
|
39
40
|
...rest
|
|
40
41
|
}: PagerViewAdapterProps) {
|
|
41
|
-
const { index } = navigationState;
|
|
42
|
+
const { index, routes } = navigationState;
|
|
43
|
+
|
|
44
|
+
const isRTL = layoutDirection === 'rtl';
|
|
45
|
+
|
|
46
|
+
// iOS reports RTL pager offsets from the opposite end
|
|
47
|
+
// So we need to invert them to get the logical route index
|
|
48
|
+
const shouldInvertOffset = Platform.OS === 'ios' && isRTL;
|
|
49
|
+
const initialPosition = shouldInvertOffset
|
|
50
|
+
? routes.length - 1 - index
|
|
51
|
+
: index;
|
|
42
52
|
|
|
43
53
|
const listeners = React.useRef<Set<Listener>>(new Set()).current;
|
|
44
54
|
|
|
@@ -46,25 +56,33 @@ export function PagerViewAdapter({
|
|
|
46
56
|
const indexRef = React.useRef<number>(index);
|
|
47
57
|
const navigationStateRef = React.useRef(navigationState);
|
|
48
58
|
|
|
49
|
-
const position = useAnimatedValue(
|
|
59
|
+
const position = useAnimatedValue(initialPosition);
|
|
50
60
|
const offset = useAnimatedValue(0);
|
|
51
61
|
|
|
52
62
|
React.useEffect(() => {
|
|
53
63
|
navigationStateRef.current = navigationState;
|
|
54
64
|
});
|
|
55
65
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
const setReportedOffset = useLatestCallback((index: number) => {
|
|
67
|
+
position.setValue(shouldInvertOffset ? routes.length - 1 - index : index);
|
|
68
|
+
offset.setValue(0);
|
|
69
|
+
});
|
|
60
70
|
|
|
71
|
+
const setPage = useLatestCallback((index: number) => {
|
|
61
72
|
if (animationEnabled) {
|
|
62
73
|
pagerRef.current?.setPage(index);
|
|
63
74
|
} else {
|
|
64
75
|
pagerRef.current?.setPageWithoutAnimation(index);
|
|
65
|
-
|
|
76
|
+
setReportedOffset(index);
|
|
66
77
|
}
|
|
78
|
+
});
|
|
67
79
|
|
|
80
|
+
const jumpTo = useLatestCallback((key: string) => {
|
|
81
|
+
const index = navigationStateRef.current.routes.findIndex(
|
|
82
|
+
(route: { key: string }) => route.key === key
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
setPage(index);
|
|
68
86
|
onIndexChange(index);
|
|
69
87
|
});
|
|
70
88
|
|
|
@@ -74,14 +92,9 @@ export function PagerViewAdapter({
|
|
|
74
92
|
}
|
|
75
93
|
|
|
76
94
|
if (indexRef.current !== index) {
|
|
77
|
-
|
|
78
|
-
pagerRef.current?.setPage(index);
|
|
79
|
-
} else {
|
|
80
|
-
pagerRef.current?.setPageWithoutAnimation(index);
|
|
81
|
-
position.setValue(index);
|
|
82
|
-
}
|
|
95
|
+
setPage(index);
|
|
83
96
|
}
|
|
84
|
-
}, [keyboardDismissMode, index,
|
|
97
|
+
}, [keyboardDismissMode, index, setPage]);
|
|
85
98
|
|
|
86
99
|
const onPageScrollStateChanged = (
|
|
87
100
|
state: PageScrollStateChangedNativeEvent
|
|
@@ -123,10 +136,14 @@ export function PagerViewAdapter({
|
|
|
123
136
|
};
|
|
124
137
|
});
|
|
125
138
|
|
|
126
|
-
const memoizedPosition = React.useMemo(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
139
|
+
const memoizedPosition = React.useMemo(() => {
|
|
140
|
+
const value = Animated.add(position, offset);
|
|
141
|
+
|
|
142
|
+
// Convert the native RTL offset back to the logical route index
|
|
143
|
+
return shouldInvertOffset
|
|
144
|
+
? Animated.subtract(routes.length - 1, value)
|
|
145
|
+
: value;
|
|
146
|
+
}, [offset, position, routes.length, shouldInvertOffset]);
|
|
130
147
|
|
|
131
148
|
return children({
|
|
132
149
|
position: memoizedPosition,
|
|
@@ -138,6 +155,7 @@ export function PagerViewAdapter({
|
|
|
138
155
|
ref={pagerRef}
|
|
139
156
|
style={[styles.container, style]}
|
|
140
157
|
initialPage={index}
|
|
158
|
+
layoutDirection={layoutDirection}
|
|
141
159
|
keyboardDismissMode={
|
|
142
160
|
keyboardDismissMode === 'auto' ? 'on-drag' : keyboardDismissMode
|
|
143
161
|
}
|
|
@@ -36,7 +36,7 @@ export function ScrollViewAdapter({
|
|
|
36
36
|
children,
|
|
37
37
|
style,
|
|
38
38
|
animationEnabled = true,
|
|
39
|
-
layoutDirection
|
|
39
|
+
layoutDirection = 'ltr',
|
|
40
40
|
decelerationRate = 'fast',
|
|
41
41
|
bounces = false,
|
|
42
42
|
overScrollMode = 'never',
|
|
@@ -45,6 +45,16 @@ export function ScrollViewAdapter({
|
|
|
45
45
|
}: ScrollViewAdapterProps) {
|
|
46
46
|
const { index, routes } = navigationState;
|
|
47
47
|
|
|
48
|
+
const isRTL = layoutDirection === 'rtl';
|
|
49
|
+
|
|
50
|
+
// Android reports RTL scroll offsets from the opposite end (0 at the max scroll offset)
|
|
51
|
+
// So we need to invert them to get the logical route index
|
|
52
|
+
const shouldInvertOffset = Platform.OS === 'android' && isRTL;
|
|
53
|
+
|
|
54
|
+
// Web uses negative scroll offsets in RTL
|
|
55
|
+
// So we need to negate them to get the logical route index
|
|
56
|
+
const shouldNegateOffset = Platform.OS === 'web' && isRTL;
|
|
57
|
+
|
|
48
58
|
const listeners = React.useRef<Set<Listener>>(new Set()).current;
|
|
49
59
|
|
|
50
60
|
const scrollViewRef = React.useRef<ScrollView>(null);
|
|
@@ -52,13 +62,48 @@ export function ScrollViewAdapter({
|
|
|
52
62
|
|
|
53
63
|
const isInitialRef = React.useRef(true);
|
|
54
64
|
|
|
65
|
+
const getScrollOffsetForIndex = React.useCallback(
|
|
66
|
+
(index: number, width: number) =>
|
|
67
|
+
(shouldNegateOffset ? -index : index) * width,
|
|
68
|
+
[shouldNegateOffset]
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const getReportedOffsetForIndex = React.useCallback(
|
|
72
|
+
(index: number, width: number) =>
|
|
73
|
+
shouldInvertOffset
|
|
74
|
+
? (routes.length - 1 - index) * width
|
|
75
|
+
: getScrollOffsetForIndex(index, width),
|
|
76
|
+
[getScrollOffsetForIndex, routes.length, shouldInvertOffset]
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const getIndexFromOffset = React.useCallback(
|
|
80
|
+
(x: number, width: number) => {
|
|
81
|
+
const offset = clamp(
|
|
82
|
+
x / width,
|
|
83
|
+
shouldNegateOffset ? -(routes.length - 1) : 0,
|
|
84
|
+
routes.length - 1
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (shouldInvertOffset) {
|
|
88
|
+
return routes.length - 1 - offset;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (shouldNegateOffset) {
|
|
92
|
+
return -offset;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return offset;
|
|
96
|
+
},
|
|
97
|
+
[routes.length, shouldInvertOffset, shouldNegateOffset]
|
|
98
|
+
);
|
|
99
|
+
|
|
55
100
|
const [layout, onLayout] = useMeasureLayout(containerRef, ({ width }) => {
|
|
56
101
|
if (isInitialRef.current) {
|
|
57
|
-
const x = index
|
|
102
|
+
const x = getScrollOffsetForIndex(index, width);
|
|
58
103
|
|
|
59
104
|
setContentOffset({ x, y: 0 });
|
|
60
105
|
|
|
61
|
-
offsetX.setValue(
|
|
106
|
+
offsetX.setValue(getReportedOffsetForIndex(index, width));
|
|
62
107
|
} else if (indexRef.current !== index) {
|
|
63
108
|
scrollToIndex(index);
|
|
64
109
|
}
|
|
@@ -67,14 +112,14 @@ export function ScrollViewAdapter({
|
|
|
67
112
|
});
|
|
68
113
|
|
|
69
114
|
const [contentOffset, setContentOffset] = React.useState(() => ({
|
|
70
|
-
x: index
|
|
115
|
+
x: getScrollOffsetForIndex(index, layout.width),
|
|
71
116
|
y: 0,
|
|
72
117
|
}));
|
|
73
118
|
|
|
74
119
|
React.useEffect(() => {
|
|
75
|
-
// FIXME: contentOffset is not supported on Android
|
|
120
|
+
// FIXME: contentOffset is not supported on Android and Web
|
|
76
121
|
// So we manually scroll after state update
|
|
77
|
-
if (Platform.OS === 'android') {
|
|
122
|
+
if (Platform.OS === 'android' || Platform.OS === 'web') {
|
|
78
123
|
requestAnimationFrame(() => {
|
|
79
124
|
scrollViewRef.current?.scrollTo({
|
|
80
125
|
x: contentOffset.x,
|
|
@@ -82,13 +127,13 @@ export function ScrollViewAdapter({
|
|
|
82
127
|
});
|
|
83
128
|
});
|
|
84
129
|
}
|
|
85
|
-
}, [
|
|
130
|
+
}, [contentOffset.x]);
|
|
86
131
|
|
|
87
132
|
const [offsetX] = React.useState(() => new Animated.Value(contentOffset.x));
|
|
88
133
|
|
|
89
134
|
const scrollToIndex = useLatestCallback((index: number) => {
|
|
90
135
|
scrollViewRef.current?.scrollTo({
|
|
91
|
-
x: index
|
|
136
|
+
x: getScrollOffsetForIndex(index, layout.width),
|
|
92
137
|
animated: animationEnabled,
|
|
93
138
|
});
|
|
94
139
|
});
|
|
@@ -119,10 +164,26 @@ export function ScrollViewAdapter({
|
|
|
119
164
|
};
|
|
120
165
|
});
|
|
121
166
|
|
|
122
|
-
const position = React.useMemo(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
167
|
+
const position = React.useMemo(() => {
|
|
168
|
+
if (!layout.width) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const value = Animated.divide(offsetX, layout.width);
|
|
173
|
+
|
|
174
|
+
// Convert platform scroll offsets back to logical route index
|
|
175
|
+
return shouldInvertOffset
|
|
176
|
+
? Animated.subtract(routes.length - 1, value)
|
|
177
|
+
: shouldNegateOffset
|
|
178
|
+
? Animated.multiply(value, -1)
|
|
179
|
+
: value;
|
|
180
|
+
}, [
|
|
181
|
+
layout.width,
|
|
182
|
+
offsetX,
|
|
183
|
+
routes.length,
|
|
184
|
+
shouldInvertOffset,
|
|
185
|
+
shouldNegateOffset,
|
|
186
|
+
]);
|
|
126
187
|
|
|
127
188
|
const indexRef = React.useRef(index);
|
|
128
189
|
const timerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(
|
|
@@ -130,16 +191,16 @@ export function ScrollViewAdapter({
|
|
|
130
191
|
);
|
|
131
192
|
|
|
132
193
|
const onScrollEnd = (x: number) => {
|
|
133
|
-
const
|
|
194
|
+
const nextIndex = getIndexFromOffset(x, layout.width);
|
|
134
195
|
|
|
135
|
-
if (
|
|
136
|
-
indexRef.current =
|
|
196
|
+
if (nextIndex % 1 === 0) {
|
|
197
|
+
indexRef.current = nextIndex;
|
|
137
198
|
|
|
138
|
-
if (
|
|
139
|
-
onIndexChange(
|
|
199
|
+
if (nextIndex !== index) {
|
|
200
|
+
onIndexChange(nextIndex);
|
|
140
201
|
}
|
|
141
202
|
|
|
142
|
-
onTabSelect?.({ index:
|
|
203
|
+
onTabSelect?.({ index: nextIndex });
|
|
143
204
|
}
|
|
144
205
|
};
|
|
145
206
|
|
|
@@ -152,11 +213,10 @@ export function ScrollViewAdapter({
|
|
|
152
213
|
},
|
|
153
214
|
],
|
|
154
215
|
{
|
|
155
|
-
useNativeDriver:
|
|
216
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
156
217
|
listener: (event: ScrollEvent) => {
|
|
157
218
|
const { x } = event.nativeEvent.contentOffset;
|
|
158
|
-
|
|
159
|
-
const value = clamp(x / layout.width, 0, routes.length - 1);
|
|
219
|
+
const value = getIndexFromOffset(x, layout.width);
|
|
160
220
|
|
|
161
221
|
// The offset will overlap the current and the adjacent page
|
|
162
222
|
// So we need to get the index of the adjacent page
|