Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit dfd4dbf

Browse files
committed
feat: add disableChangeTabAnimation to TabView
1 parent 86e66d0 commit dfd4dbf

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ Style to apply to the view wrapping each screen. You can pass this to override s
335335

336336
Style to apply to the tab view container.
337337

338+
### `disableChangeTabAnimation`
339+
340+
Boolean indicating whether to disable the change tab animation.
341+
338342
### `TabBar`
339343

340344
Material design themed tab bar. To customize the tab bar, you'd need to use the `renderTabBar` prop of `TabView` to render the `TabBar` and pass additional props.

src/PagerViewAdapter.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default function PagerViewAdapter<T extends Route>({
4141
onSwipeEnd,
4242
children,
4343
style,
44+
disableChangeTabAnimation,
4445
...rest
4546
}: Props<T>) {
4647
const { index } = navigationState;
@@ -63,7 +64,13 @@ export default function PagerViewAdapter<T extends Route>({
6364
(route: { key: string }) => route.key === key
6465
);
6566

66-
pagerRef.current?.setPage(index);
67+
if (disableChangeTabAnimation) {
68+
pagerRef.current?.setPageWithoutAnimation(index);
69+
position.setValue(index);
70+
} else {
71+
pagerRef.current?.setPage(index);
72+
}
73+
// eslint-disable-next-line react-hooks/exhaustive-deps
6774
}, []);
6875

6976
React.useEffect(() => {
@@ -72,8 +79,14 @@ export default function PagerViewAdapter<T extends Route>({
7279
}
7380

7481
if (indexRef.current !== index) {
75-
pagerRef.current?.setPage(index);
82+
if (disableChangeTabAnimation) {
83+
pagerRef.current?.setPageWithoutAnimation(index);
84+
position.setValue(index);
85+
} else {
86+
pagerRef.current?.setPage(index);
87+
}
7688
}
89+
// eslint-disable-next-line react-hooks/exhaustive-deps
7790
}, [keyboardDismissMode, index]);
7891

7992
const onPageScrollStateChanged = (

src/TabView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default function TabView<T extends Route>({
4949
style,
5050
swipeEnabled = true,
5151
tabBarPosition = 'top',
52+
disableChangeTabAnimation,
5253
}: Props<T>) {
5354
const [layout, setLayout] = React.useState({
5455
width: 0,
@@ -84,6 +85,7 @@ export default function TabView<T extends Route>({
8485
onSwipeStart={onSwipeStart}
8586
onSwipeEnd={onSwipeEnd}
8687
onIndexChange={jumpToIndex}
88+
disableChangeTabAnimation={disableChangeTabAnimation}
8789
>
8890
{({ position, render, addEnterListener, jumpTo }) => {
8991
// All of the props here must not change between re-renders

src/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ export type PagerProps = Omit<
5555
swipeEnabled?: boolean;
5656
onSwipeStart?: () => void;
5757
onSwipeEnd?: () => void;
58+
disableChangeTabAnimation?: boolean;
5859
};

0 commit comments

Comments
 (0)