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

Commit 2f568d8

Browse files
committed
feat: add animationEnabled on web
1 parent bb5baea commit 2f568d8

File tree

8 files changed

+9664
-9063
lines changed

8 files changed

+9664
-9063
lines changed

example/package-lock.json

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"react-native": "0.69.5",
2323
"react-native-pager-view": "5.4.25",
2424
"react-native-safe-area-context": "4.3.1",
25-
"react-native-web": "~0.18.7",
26-
"use-latest-callback": "^0.1.5"
25+
"react-native-web": "~0.18.7"
2726
},
2827
"devDependencies": {
2928
"babel-plugin-module-resolver": "^4.1.0",

example/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11415,11 +11415,6 @@ url@^0.11.0:
1141511415
punycode "1.3.2"
1141611416
querystring "0.2.0"
1141711417

11418-
use-latest-callback@^0.1.5:
11419-
version "0.1.5"
11420-
resolved "https://registry.yarnpkg.com/use-latest-callback/-/use-latest-callback-0.1.5.tgz#a4a836c08fa72f6608730b5b8f4bbd9c57c04f51"
11421-
integrity sha512-HtHatS2U4/h32NlkhupDsPlrbiD27gSH5swBdtXbCAlc6pfOFzaj0FehW/FO12rx8j2Vy4/lJScCiJyM01E+bQ==
11422-
1142311418
use-sync-external-store@^1.0.0:
1142411419
version "1.2.0"
1142511420
resolved "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz"

package-lock.json

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@
6464
"react-native-builder-bob": "^0.18.3",
6565
"react-native-pager-view": "5.4.24",
6666
"release-it": "^15.4.0",
67-
"typescript": "^4.8.2",
68-
"use-latest-callback": "^0.1.5"
67+
"typescript": "^4.8.2"
6968
},
7069
"peerDependencies": {
7170
"react": "*",

src/PagerViewAdapter.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
EventEmitterProps,
1212
PagerProps,
1313
} from './types';
14-
import useLatestCallback from 'use-latest-callback';
1514

1615
const AnimatedViewPager = Animated.createAnimatedComponent(ViewPager);
1716

@@ -60,18 +59,21 @@ export default function PagerViewAdapter<T extends Route>({
6059
navigationStateRef.current = navigationState;
6160
});
6261

63-
const jumpTo = useLatestCallback((key: string) => {
64-
const index = navigationStateRef.current.routes.findIndex(
65-
(route: { key: string }) => route.key === key
66-
);
62+
const jumpTo = React.useCallback(
63+
(key: string) => {
64+
const index = navigationStateRef.current.routes.findIndex(
65+
(route: { key: string }) => route.key === key
66+
);
6767

68-
if (animationEnabled) {
69-
pagerRef.current?.setPage(index);
70-
} else {
71-
pagerRef.current?.setPageWithoutAnimation(index);
72-
position.setValue(index);
73-
}
74-
});
68+
if (animationEnabled) {
69+
pagerRef.current?.setPage(index);
70+
} else {
71+
pagerRef.current?.setPageWithoutAnimation(index);
72+
position.setValue(index);
73+
}
74+
},
75+
[animationEnabled, position]
76+
);
7577

7678
React.useEffect(() => {
7779
if (keyboardDismissMode === 'auto') {
@@ -86,8 +88,7 @@ export default function PagerViewAdapter<T extends Route>({
8688
position.setValue(index);
8789
}
8890
}
89-
// eslint-disable-next-line react-hooks/exhaustive-deps
90-
}, [keyboardDismissMode, index, animationEnabled]);
91+
}, [keyboardDismissMode, index, animationEnabled, position]);
9192

9293
const onPageScrollStateChanged = (
9394
state: PageScrollStateChangedNativeEvent

src/PanResponderAdapter.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default function PanResponderAdapter<T extends Route>({
5858
onSwipeEnd,
5959
children,
6060
style,
61+
animationEnabled,
6162
}: Props<T>) {
6263
const { routes, index } = navigationState;
6364

@@ -81,22 +82,27 @@ export default function PanResponderAdapter<T extends Route>({
8182

8283
const { timing, ...transitionConfig } = DefaultTransitionSpec;
8384

84-
Animated.parallel([
85-
timing(panX, {
86-
...transitionConfig,
87-
toValue: offset,
88-
useNativeDriver: false,
89-
}),
90-
]).start(({ finished }) => {
91-
if (finished) {
92-
onIndexChangeRef.current(index);
93-
pendingIndexRef.current = undefined;
94-
}
95-
});
85+
if (animationEnabled) {
86+
Animated.parallel([
87+
timing(panX, {
88+
...transitionConfig,
89+
toValue: offset,
90+
useNativeDriver: false,
91+
}),
92+
]).start(({ finished }) => {
93+
if (finished) {
94+
onIndexChangeRef.current(index);
95+
pendingIndexRef.current = undefined;
96+
}
97+
});
98+
} else {
99+
panX.setValue(offset);
100+
onIndexChangeRef.current(index);
101+
}
96102

97103
pendingIndexRef.current = index;
98104
},
99-
[panX]
105+
[animationEnabled, panX]
100106
);
101107

102108
React.useEffect(() => {

0 commit comments

Comments
 (0)