@zoverdoser/react-native-tab-view 1.0.2 → 1.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.
- package/lib/module/PagerViewAdapter.js +28 -13
- package/lib/module/PagerViewAdapter.js.map +1 -1
- package/lib/module/PanResponderAdapter.js.map +1 -1
- package/lib/module/PlatformPressable.js +1 -1
- package/lib/module/PlatformPressable.js.map +1 -1
- package/lib/module/TabBar.js +27 -32
- package/lib/module/TabBar.js.map +1 -1
- package/lib/module/TabBarIndicator.js +110 -35
- package/lib/module/TabBarIndicator.js.map +1 -1
- package/lib/module/TabBarItem.js +63 -32
- package/lib/module/TabBarItem.js.map +1 -1
- package/lib/module/TabBarItemLabel.js.map +1 -1
- package/lib/module/TabView.js +2 -0
- package/lib/module/TabView.js.map +1 -1
- package/lib/module/useAnimatedValue.js.map +1 -1
- package/lib/typescript/src/Pager.android.d.ts +1 -1
- package/lib/typescript/src/Pager.android.d.ts.map +1 -1
- package/lib/typescript/src/Pager.d.ts +1 -1
- package/lib/typescript/src/Pager.d.ts.map +1 -1
- package/lib/typescript/src/Pager.ios.d.ts +1 -1
- package/lib/typescript/src/Pager.ios.d.ts.map +1 -1
- package/lib/typescript/src/PagerViewAdapter.d.ts +3 -1
- package/lib/typescript/src/PagerViewAdapter.d.ts.map +1 -1
- package/lib/typescript/src/PanResponderAdapter.d.ts +3 -1
- package/lib/typescript/src/PanResponderAdapter.d.ts.map +1 -1
- package/lib/typescript/src/PlatformPressable.d.ts +1 -1
- package/lib/typescript/src/PlatformPressable.d.ts.map +1 -1
- package/lib/typescript/src/SceneMap.d.ts +2 -2
- package/lib/typescript/src/SceneMap.d.ts.map +1 -1
- package/lib/typescript/src/SceneView.d.ts +2 -2
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/TabBar.d.ts +4 -4
- package/lib/typescript/src/TabBar.d.ts.map +1 -1
- package/lib/typescript/src/TabBarIndicator.d.ts +2 -2
- package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -1
- package/lib/typescript/src/TabBarItem.d.ts +5 -2
- package/lib/typescript/src/TabBarItem.d.ts.map +1 -1
- package/lib/typescript/src/TabBarItemLabel.d.ts +1 -1
- package/lib/typescript/src/TabBarItemLabel.d.ts.map +1 -1
- package/lib/typescript/src/TabView.d.ts +2 -2
- package/lib/typescript/src/TabView.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +10 -10
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +2 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useAnimatedValue.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/PagerViewAdapter.tsx +67 -17
- package/src/PanResponderAdapter.tsx +2 -0
- package/src/PlatformPressable.tsx +1 -1
- package/src/TabBar.tsx +50 -47
- package/src/TabBarIndicator.tsx +182 -41
- package/src/TabBarItem.tsx +111 -47
- package/src/TabBarItemLabel.tsx +1 -0
- package/src/TabView.tsx +2 -1
- package/src/types.tsx +2 -1
- package/src/useAnimatedValue.tsx +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
-
import type { Layout, LocaleDirection, NavigationState, PagerProps, Route, SceneRendererProps, TabDescriptor } from './types';
|
|
3
|
+
import type { Layout, LocaleDirection, NavigationState, PagerProps, Route, SceneRendererProps, TabDescriptor } from './types.js';
|
|
4
4
|
export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
|
|
5
5
|
onIndexChange: (index: number) => void;
|
|
6
6
|
onTabSelect?: (props: {
|
|
@@ -29,5 +29,5 @@ export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
|
|
|
29
29
|
options?: Record<string, TabDescriptor<T>>;
|
|
30
30
|
commonOptions?: TabDescriptor<T>;
|
|
31
31
|
};
|
|
32
|
-
export declare function TabView<T extends Route>({ onIndexChange, onTabSelect, navigationState, renderScene, initialLayout, keyboardDismissMode, lazy, lazyPreloadDistance, onSwipeStart, onSwipeEnd, renderLazyPlaceholder, renderTabBar, pagerStyle, style, direction, swipeEnabled, tabBarPosition, animationEnabled, overScrollMode, options: sceneOptions, commonOptions, }: Props<T>):
|
|
32
|
+
export declare function TabView<T extends Route>({ onIndexChange, onTabSelect, navigationState, renderScene, initialLayout, keyboardDismissMode, lazy, lazyPreloadDistance, onSwipeStart, onSwipeEnd, renderLazyPlaceholder, renderTabBar, pagerStyle, style, direction, swipeEnabled, tabBarPosition, animationEnabled, overScrollMode, options: sceneOptions, commonOptions, }: Props<T>): React.JSX.Element;
|
|
33
33
|
//# sourceMappingURL=TabView.d.ts.map
|
|
@@ -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,EAIL,KAAK,SAAS,EAGd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EACV,MAAM,EACN,eAAe,EACf,eAAe,EACf,UAAU,EACV,KAAK,EACL,kBAAkB,EAClB,aAAa,EACd,MAAM,
|
|
1
|
+
{"version":3,"file":"TabView.d.ts","sourceRoot":"","sources":["../../../src/TabView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAIL,KAAK,SAAS,EAGd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EACV,MAAM,EACN,eAAe,EACf,eAAe,EACf,UAAU,EACV,KAAK,EACL,kBAAkB,EAClB,aAAa,EACd,MAAM,YAAS,CAAC;AAEjB,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,GAAG;IACzE,aAAa,EAAE,CAAC,KAAK,E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KAAK,EAAE,EACvC,aAAa,EACb,WAAW,EACX,eAAe,EACf,WAAW,EACX,aAAa,EACb,mBAA4B,EAC5B,IAAY,EACZ,mBAAuB,EACvB,YAAY,EACZ,UAAU,EACV,qBAAoD,EAEpD,YAA+C,EAC/C,UAAU,EACV,KAAK,EACL,SAA4D,EAC5D,YAAmB,EACnB,cAAsB,EACtB,gBAAuB,EACvB,cAAc,EACd,OAAO,EAAE,YAAY,EACrB,aAAa,GACd,EAAE,KAAK,CAAC,CAAC,CAAC,qBAuHV"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { SceneMap } from './SceneMap';
|
|
2
|
-
export type { Props as TabBarProps } from './TabBar';
|
|
3
|
-
export { TabBar } from './TabBar';
|
|
4
|
-
export type { Props as TabBarIndicatorProps } from './TabBarIndicator';
|
|
5
|
-
export { TabBarIndicator } from './TabBarIndicator';
|
|
6
|
-
export type { Props as TabBarItemProps } from './TabBarItem';
|
|
7
|
-
export { TabBarItem } from './TabBarItem';
|
|
8
|
-
export type { Props as TabViewProps } from './TabView';
|
|
9
|
-
export { TabView } from './TabView';
|
|
10
|
-
export type { AnimatedStyles, NavigationState, Route, SceneRendererProps, TabDescriptor, } from './types';
|
|
1
|
+
export { SceneMap } from './SceneMap.js';
|
|
2
|
+
export type { Props as TabBarProps } from './TabBar.js';
|
|
3
|
+
export { TabBar } from './TabBar.js';
|
|
4
|
+
export type { Props as TabBarIndicatorProps } from './TabBarIndicator.js';
|
|
5
|
+
export { TabBarIndicator } from './TabBarIndicator.js';
|
|
6
|
+
export type { Props as TabBarItemProps } from './TabBarItem.js';
|
|
7
|
+
export { TabBarItem } from './TabBarItem.js';
|
|
8
|
+
export type { Props as TabViewProps } from './TabView.js';
|
|
9
|
+
export { TabView } from './TabView.js';
|
|
10
|
+
export type { AnimatedStyles, NavigationState, Route, SceneRendererProps, TabDescriptor, } from './types.js';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAY,CAAC;AACtC,YAAY,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,aAAU,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAU,CAAC;AAClC,YAAY,EAAE,KAAK,IAAI,oBAAoB,EAAE,MAAM,sBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAmB,CAAC;AACpD,YAAY,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,iBAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAc,CAAC;AAC1C,YAAY,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,cAAW,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAW,CAAC;AACpC,YAAY,EACV,cAAc,EACd,eAAe,EACf,KAAK,EACL,kBAAkB,EAClB,aAAa,GACd,MAAM,YAAS,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Animated, StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
2
2
|
import type { PagerViewProps } from 'react-native-pager-view';
|
|
3
|
-
import type { AnimatedStyle } from 'react-native-reanimated';
|
|
3
|
+
import type { AnimatedStyle, SharedValue } from 'react-native-reanimated';
|
|
4
4
|
export type TabDescriptor<T extends Route> = {
|
|
5
5
|
accessibilityLabel?: string;
|
|
6
6
|
accessible?: boolean;
|
|
@@ -56,6 +56,7 @@ export type Listener = (value: number) => void;
|
|
|
56
56
|
export type SceneRendererProps = {
|
|
57
57
|
layout: Layout;
|
|
58
58
|
position: Animated.AnimatedInterpolation<number>;
|
|
59
|
+
animatedPosition?: SharedValue<number>;
|
|
59
60
|
jumpTo: (key: string) => void;
|
|
60
61
|
};
|
|
61
62
|
export type EventEmitterProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE1E,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,KAAK,IAAI;IAC3C,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE;QACd,KAAK,EAAE,CAAC,CAAC;QACT,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;QACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7B,cAAc,CAAC,EAAE,aAAa,CAAC,SAAS,CAA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AAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useAnimatedValue.d.ts","sourceRoot":"","sources":["../../../src/useAnimatedValue.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,QAAQ,CAAC,KAAK,CAQrE"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zoverdoser/react-native-tab-view",
|
|
3
3
|
"description": "Tab view component for React Native",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native-component",
|
|
7
7
|
"react-component",
|
|
@@ -50,12 +50,13 @@
|
|
|
50
50
|
"@jest/globals": "^30.0.0",
|
|
51
51
|
"@testing-library/react-native": "^13.2.1",
|
|
52
52
|
"del-cli": "^6.0.0",
|
|
53
|
-
"react": "19.
|
|
54
|
-
"react-native": "0.
|
|
55
|
-
"react-native-builder-bob": "^0.
|
|
56
|
-
"react-native-pager-view": "
|
|
57
|
-
"react-
|
|
58
|
-
"
|
|
53
|
+
"react": "19.2.3",
|
|
54
|
+
"react-native": "0.85.3",
|
|
55
|
+
"react-native-builder-bob": "^0.42.1",
|
|
56
|
+
"react-native-pager-view": "8.0.1",
|
|
57
|
+
"react-native-worklets": "0.8.3",
|
|
58
|
+
"react-test-renderer": "19.2.3",
|
|
59
|
+
"typescript": "~6.0.3"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
62
|
"react": ">= 18.2.0",
|
package/src/PagerViewAdapter.tsx
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Animated, Keyboard,
|
|
2
|
+
import { Animated, Keyboard, StyleSheet } from 'react-native';
|
|
3
3
|
import ViewPager, {
|
|
4
|
+
type PagerViewOnPageScrollEventData,
|
|
4
5
|
type PageScrollStateChangedNativeEvent,
|
|
5
6
|
} from 'react-native-pager-view';
|
|
7
|
+
import Reanimated, {
|
|
8
|
+
type SharedValue,
|
|
9
|
+
useEvent,
|
|
10
|
+
useSharedValue,
|
|
11
|
+
} from 'react-native-reanimated';
|
|
6
12
|
import useLatestCallback from 'use-latest-callback';
|
|
7
13
|
|
|
8
14
|
import type {
|
|
@@ -14,7 +20,18 @@ import type {
|
|
|
14
20
|
} from './types';
|
|
15
21
|
import { useAnimatedValue } from './useAnimatedValue';
|
|
16
22
|
|
|
17
|
-
const AnimatedViewPager =
|
|
23
|
+
const AnimatedViewPager = Reanimated.createAnimatedComponent(ViewPager);
|
|
24
|
+
|
|
25
|
+
const attachNativeEvent = (
|
|
26
|
+
Animated as typeof Animated & {
|
|
27
|
+
attachNativeEvent: (
|
|
28
|
+
viewRef: unknown,
|
|
29
|
+
eventName: string,
|
|
30
|
+
argMapping: readonly unknown[],
|
|
31
|
+
platformConfig?: unknown
|
|
32
|
+
) => { detach: () => void };
|
|
33
|
+
}
|
|
34
|
+
).attachNativeEvent;
|
|
18
35
|
|
|
19
36
|
type Props<T extends Route> = PagerProps & {
|
|
20
37
|
onIndexChange: (index: number) => void;
|
|
@@ -25,6 +42,8 @@ type Props<T extends Route> = PagerProps & {
|
|
|
25
42
|
// Animated value which represents the state of current index
|
|
26
43
|
// It can include fractional digits as it represents the intermediate value
|
|
27
44
|
position: Animated.AnimatedInterpolation<number>;
|
|
45
|
+
// Reanimated value updated directly from the native page scroll event
|
|
46
|
+
animatedPosition: SharedValue<number>;
|
|
28
47
|
// Function to actually render the content of the pager
|
|
29
48
|
// The parent component takes care of rendering
|
|
30
49
|
render: (children: React.ReactNode) => React.ReactNode;
|
|
@@ -35,8 +54,6 @@ type Props<T extends Route> = PagerProps & {
|
|
|
35
54
|
) => React.ReactElement;
|
|
36
55
|
};
|
|
37
56
|
|
|
38
|
-
const useNativeDriver = Platform.OS !== 'web';
|
|
39
|
-
|
|
40
57
|
export function PagerViewAdapter<T extends Route>({
|
|
41
58
|
keyboardDismissMode = 'auto',
|
|
42
59
|
swipeEnabled = true,
|
|
@@ -60,6 +77,35 @@ export function PagerViewAdapter<T extends Route>({
|
|
|
60
77
|
|
|
61
78
|
const position = useAnimatedValue(index);
|
|
62
79
|
const offset = useAnimatedValue(0);
|
|
80
|
+
const animatedPosition = useSharedValue(index);
|
|
81
|
+
|
|
82
|
+
const onPageScroll = useEvent<PagerViewOnPageScrollEventData>(
|
|
83
|
+
(event) => {
|
|
84
|
+
'worklet';
|
|
85
|
+
if (event.eventName.endsWith('onPageScroll')) {
|
|
86
|
+
animatedPosition.value = event.position + event.offset;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
['onPageScroll']
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
React.useEffect(() => {
|
|
93
|
+
const subscription = attachNativeEvent(
|
|
94
|
+
pagerRef.current,
|
|
95
|
+
'onPageScroll',
|
|
96
|
+
[
|
|
97
|
+
{
|
|
98
|
+
nativeEvent: {
|
|
99
|
+
position,
|
|
100
|
+
offset,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
undefined
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return () => subscription.detach();
|
|
108
|
+
}, [offset, position]);
|
|
63
109
|
|
|
64
110
|
React.useEffect(() => {
|
|
65
111
|
navigationStateRef.current = navigationState;
|
|
@@ -75,6 +121,7 @@ export function PagerViewAdapter<T extends Route>({
|
|
|
75
121
|
} else {
|
|
76
122
|
pagerRef.current?.setPageWithoutAnimation(index);
|
|
77
123
|
position.setValue(index);
|
|
124
|
+
animatedPosition.value = index;
|
|
78
125
|
}
|
|
79
126
|
|
|
80
127
|
onIndexChange(index);
|
|
@@ -91,9 +138,16 @@ export function PagerViewAdapter<T extends Route>({
|
|
|
91
138
|
} else {
|
|
92
139
|
pagerRef.current?.setPageWithoutAnimation(index);
|
|
93
140
|
position.setValue(index);
|
|
141
|
+
animatedPosition.value = index;
|
|
94
142
|
}
|
|
95
143
|
}
|
|
96
|
-
}, [
|
|
144
|
+
}, [
|
|
145
|
+
keyboardDismissMode,
|
|
146
|
+
index,
|
|
147
|
+
animationEnabled,
|
|
148
|
+
position,
|
|
149
|
+
animatedPosition,
|
|
150
|
+
]);
|
|
97
151
|
|
|
98
152
|
const onPageScrollStateChanged = (
|
|
99
153
|
state: PageScrollStateChangedNativeEvent
|
|
@@ -102,7 +156,7 @@ export function PagerViewAdapter<T extends Route>({
|
|
|
102
156
|
|
|
103
157
|
switch (pageScrollState) {
|
|
104
158
|
case 'idle':
|
|
105
|
-
offset.setValue(0);
|
|
159
|
+
// offset.setValue(0);
|
|
106
160
|
onSwipeEnd?.();
|
|
107
161
|
return;
|
|
108
162
|
case 'dragging': {
|
|
@@ -142,6 +196,7 @@ export function PagerViewAdapter<T extends Route>({
|
|
|
142
196
|
|
|
143
197
|
return children({
|
|
144
198
|
position: memoizedPosition,
|
|
199
|
+
animatedPosition,
|
|
145
200
|
addEnterListener,
|
|
146
201
|
jumpTo,
|
|
147
202
|
render: (children) => (
|
|
@@ -153,20 +208,15 @@ export function PagerViewAdapter<T extends Route>({
|
|
|
153
208
|
keyboardDismissMode={
|
|
154
209
|
keyboardDismissMode === 'auto' ? 'on-drag' : keyboardDismissMode
|
|
155
210
|
}
|
|
156
|
-
onPageScroll={
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
offset: offset,
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
{ useNativeDriver }
|
|
166
|
-
)}
|
|
211
|
+
onPageScroll={
|
|
212
|
+
onPageScroll as unknown as React.ComponentProps<
|
|
213
|
+
typeof AnimatedViewPager
|
|
214
|
+
>['onPageScroll']
|
|
215
|
+
}
|
|
167
216
|
onPageSelected={(e) => {
|
|
168
217
|
const index = e.nativeEvent.position;
|
|
169
218
|
indexRef.current = index;
|
|
219
|
+
animatedPosition.value = index;
|
|
170
220
|
onIndexChange(index);
|
|
171
221
|
onTabSelect?.({ index });
|
|
172
222
|
}}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
StyleSheet,
|
|
9
9
|
View,
|
|
10
10
|
} from 'react-native';
|
|
11
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
11
12
|
import useLatestCallback from 'use-latest-callback';
|
|
12
13
|
|
|
13
14
|
import type {
|
|
@@ -30,6 +31,7 @@ type Props<T extends Route> = PagerProps & {
|
|
|
30
31
|
// Animated value which represents the state of current index
|
|
31
32
|
// It can include fractional digits as it represents the intermediate value
|
|
32
33
|
position: Animated.AnimatedInterpolation<number>;
|
|
34
|
+
animatedPosition?: SharedValue<number>;
|
|
33
35
|
// Function to actually render the content of the pager
|
|
34
36
|
// The parent component takes care of rendering
|
|
35
37
|
render: (children: React.ReactNode) => React.ReactNode;
|
|
@@ -50,7 +50,7 @@ export function PlatformPressable({
|
|
|
50
50
|
// let browser handle "target=_blank" etc.
|
|
51
51
|
const isSelfTarget =
|
|
52
52
|
e.currentTarget && 'target' in e.currentTarget
|
|
53
|
-
? [undefined, null, '', '
|
|
53
|
+
? [undefined, null, '', '_self'].includes(e.currentTarget.target)
|
|
54
54
|
: true;
|
|
55
55
|
|
|
56
56
|
if (!hasModifierKey && isLeftClick && isSelfTarget) {
|
package/src/TabBar.tsx
CHANGED
|
@@ -12,9 +12,7 @@ import {
|
|
|
12
12
|
StyleSheet,
|
|
13
13
|
View,
|
|
14
14
|
type ViewStyle,
|
|
15
|
-
type ViewToken,
|
|
16
15
|
} from 'react-native';
|
|
17
|
-
import useLatestCallback from 'use-latest-callback';
|
|
18
16
|
|
|
19
17
|
import {
|
|
20
18
|
type Props as IndicatorProps,
|
|
@@ -338,6 +336,7 @@ export function TabBar<T extends Route>({
|
|
|
338
336
|
jumpTo,
|
|
339
337
|
navigationState,
|
|
340
338
|
position,
|
|
339
|
+
animatedPosition,
|
|
341
340
|
bounces,
|
|
342
341
|
contentContainerStyle,
|
|
343
342
|
indicatorContainerStyle,
|
|
@@ -363,8 +362,41 @@ export function TabBar<T extends Route>({
|
|
|
363
362
|
const flatListRef = React.useRef<FlatList | null>(null);
|
|
364
363
|
const isFirst = React.useRef(true);
|
|
365
364
|
const scrollAmount = useAnimatedValue(0);
|
|
366
|
-
const measuredTabWidths = React.useRef<Record<string, number>>({});
|
|
367
365
|
const { routes } = navigationState;
|
|
366
|
+
const animatedColorInactive = animatedStyles?.color?.[0];
|
|
367
|
+
const animatedColorActive = animatedStyles?.color?.[1];
|
|
368
|
+
const animatedOpacityInactive = animatedStyles?.opacity?.[0];
|
|
369
|
+
const animatedOpacityActive = animatedStyles?.opacity?.[1];
|
|
370
|
+
const animatedScaleInactive = animatedStyles?.scale?.[0];
|
|
371
|
+
const animatedScaleActive = animatedStyles?.scale?.[1];
|
|
372
|
+
const animatedStylesMemoized = React.useMemo<
|
|
373
|
+
AnimatedStyles | undefined
|
|
374
|
+
>(() => {
|
|
375
|
+
const color: AnimatedStyles['color'] =
|
|
376
|
+
animatedColorInactive !== undefined && animatedColorActive !== undefined
|
|
377
|
+
? [animatedColorInactive, animatedColorActive]
|
|
378
|
+
: undefined;
|
|
379
|
+
const opacity: AnimatedStyles['opacity'] =
|
|
380
|
+
animatedOpacityInactive !== undefined &&
|
|
381
|
+
animatedOpacityActive !== undefined
|
|
382
|
+
? [animatedOpacityInactive, animatedOpacityActive]
|
|
383
|
+
: undefined;
|
|
384
|
+
const scale: AnimatedStyles['scale'] =
|
|
385
|
+
animatedScaleInactive !== undefined && animatedScaleActive !== undefined
|
|
386
|
+
? [animatedScaleInactive, animatedScaleActive]
|
|
387
|
+
: undefined;
|
|
388
|
+
|
|
389
|
+
return color === undefined && opacity === undefined && scale === undefined
|
|
390
|
+
? undefined
|
|
391
|
+
: { color, opacity, scale };
|
|
392
|
+
}, [
|
|
393
|
+
animatedColorActive,
|
|
394
|
+
animatedColorInactive,
|
|
395
|
+
animatedOpacityActive,
|
|
396
|
+
animatedOpacityInactive,
|
|
397
|
+
animatedScaleActive,
|
|
398
|
+
animatedScaleInactive,
|
|
399
|
+
]);
|
|
368
400
|
const flattenedTabWidth = getFlattenedTabWidth(tabStyle);
|
|
369
401
|
const isWidthDynamic = flattenedTabWidth === 'auto';
|
|
370
402
|
const flattenedPaddingEnd = getFlattenedPaddingEnd(contentContainerStyle);
|
|
@@ -443,6 +475,10 @@ export function TabBar<T extends Route>({
|
|
|
443
475
|
[direction, layout.width, scrollAmount, tabBarWidth]
|
|
444
476
|
);
|
|
445
477
|
|
|
478
|
+
const measuredTabWidths = React.useRef<Record<string, number>>({});
|
|
479
|
+
const animationFrameHandle =
|
|
480
|
+
React.useRef<ReturnType<typeof requestAnimationFrame>>(null);
|
|
481
|
+
|
|
446
482
|
const renderItem = React.useCallback(
|
|
447
483
|
({ item: route, index }: ListRenderItemInfo<T>) => {
|
|
448
484
|
const {
|
|
@@ -457,28 +493,13 @@ export function TabBar<T extends Route>({
|
|
|
457
493
|
? (e: LayoutChangeEvent) => {
|
|
458
494
|
measuredTabWidths.current[route.key] = e.nativeEvent.layout.width;
|
|
459
495
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
// If we have more than 10 routes divide updating tabWidths into multiple batches. Here we update only first batch of 10 items.
|
|
463
|
-
if (
|
|
464
|
-
routes.length > MEASURE_PER_BATCH &&
|
|
465
|
-
index === MEASURE_PER_BATCH &&
|
|
466
|
-
routes
|
|
467
|
-
.slice(0, MEASURE_PER_BATCH)
|
|
468
|
-
.every(
|
|
469
|
-
(r) => typeof measuredTabWidths.current[r.key] === 'number'
|
|
470
|
-
)
|
|
471
|
-
) {
|
|
472
|
-
setTabWidths({ ...measuredTabWidths.current });
|
|
473
|
-
} else if (
|
|
474
|
-
routes.every(
|
|
475
|
-
(r) => typeof measuredTabWidths.current[r.key] === 'number'
|
|
476
|
-
)
|
|
477
|
-
) {
|
|
478
|
-
// When we have measured widths for all of the tabs, we should updates the state
|
|
479
|
-
// We avoid doing separate setState for each layout since it triggers multiple renders and slows down app
|
|
480
|
-
setTabWidths({ ...measuredTabWidths.current });
|
|
496
|
+
if (animationFrameHandle.current != null) {
|
|
497
|
+
cancelAnimationFrame(animationFrameHandle.current);
|
|
481
498
|
}
|
|
499
|
+
|
|
500
|
+
animationFrameHandle.current = requestAnimationFrame(() => {
|
|
501
|
+
setTabWidths({ ...measuredTabWidths.current });
|
|
502
|
+
});
|
|
482
503
|
}
|
|
483
504
|
: undefined;
|
|
484
505
|
|
|
@@ -520,6 +541,7 @@ export function TabBar<T extends Route>({
|
|
|
520
541
|
const props = {
|
|
521
542
|
...rest,
|
|
522
543
|
position,
|
|
544
|
+
animatedPosition,
|
|
523
545
|
route,
|
|
524
546
|
navigationState,
|
|
525
547
|
testID,
|
|
@@ -534,7 +556,7 @@ export function TabBar<T extends Route>({
|
|
|
534
556
|
style: tabStyle,
|
|
535
557
|
defaultTabWidth,
|
|
536
558
|
android_ripple,
|
|
537
|
-
animatedStyles,
|
|
559
|
+
animatedStyles: animatedStylesMemoized,
|
|
538
560
|
} satisfies TabBarItemProps<T>;
|
|
539
561
|
|
|
540
562
|
return (
|
|
@@ -550,6 +572,7 @@ export function TabBar<T extends Route>({
|
|
|
550
572
|
},
|
|
551
573
|
[
|
|
552
574
|
position,
|
|
575
|
+
animatedPosition,
|
|
553
576
|
navigationState,
|
|
554
577
|
options,
|
|
555
578
|
pressColor,
|
|
@@ -567,7 +590,7 @@ export function TabBar<T extends Route>({
|
|
|
567
590
|
onTabPress,
|
|
568
591
|
jumpTo,
|
|
569
592
|
onTabLongPress,
|
|
570
|
-
|
|
593
|
+
animatedStylesMemoized,
|
|
571
594
|
]
|
|
572
595
|
);
|
|
573
596
|
|
|
@@ -597,32 +620,13 @@ export function TabBar<T extends Route>({
|
|
|
597
620
|
[scrollAmount]
|
|
598
621
|
);
|
|
599
622
|
|
|
600
|
-
const handleViewableItemsChanged = useLatestCallback(
|
|
601
|
-
({ changed }: { changed: ViewToken[] }) => {
|
|
602
|
-
if (routes.length <= MEASURE_PER_BATCH) {
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
// Get next vievable item
|
|
606
|
-
const item = changed[changed.length - 1];
|
|
607
|
-
const index = item?.index || 0;
|
|
608
|
-
if (
|
|
609
|
-
item.isViewable &&
|
|
610
|
-
(index % 10 === 0 ||
|
|
611
|
-
index === navigationState.index ||
|
|
612
|
-
index === routes.length - 1)
|
|
613
|
-
) {
|
|
614
|
-
setTabWidths({ ...measuredTabWidths.current });
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
);
|
|
618
|
-
|
|
619
623
|
return (
|
|
620
624
|
<Animated.View onLayout={handleLayout} style={[styles.tabBar, style]}>
|
|
621
625
|
<Animated.View
|
|
622
626
|
pointerEvents="none"
|
|
623
627
|
style={[
|
|
624
628
|
styles.indicatorContainer,
|
|
625
|
-
scrollEnabled ? { transform: [{ translateX }]
|
|
629
|
+
scrollEnabled ? { transform: [{ translateX }] } : null,
|
|
626
630
|
scrollEnabled ? { width: tabBarWidth } : null,
|
|
627
631
|
indicatorContainerStyle,
|
|
628
632
|
]}
|
|
@@ -668,7 +672,6 @@ export function TabBar<T extends Route>({
|
|
|
668
672
|
scrollEnabled={scrollEnabled}
|
|
669
673
|
bounces={bounces}
|
|
670
674
|
initialNumToRender={MEASURE_PER_BATCH}
|
|
671
|
-
onViewableItemsChanged={handleViewableItemsChanged}
|
|
672
675
|
alwaysBounceHorizontal={false}
|
|
673
676
|
scrollsToTop={false}
|
|
674
677
|
showsHorizontalScrollIndicator={false}
|