Skip to content

Commit 42d6cad

Browse files
committed
docs: add pause-advanced-parallax.git
1 parent cc4ad46 commit 42d6cad

File tree

10 files changed

+136
-2
lines changed

10 files changed

+136
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ example/ios/Pods
4343
# node.js
4444
#
4545
node_modules/
46+
scripts/gif-works-directory/*
4647
npm-debug.log
4748
yarn-debug.log
4849
yarn-error.log

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ English | [简体中文](./README.zh-CN.md)
5454
<a href="./example/src/advanced-parallax/index.tsx">
5555
<img src="assets/advanced-parallax.gif" width="300"/>
5656
</a>
57+
<a href="./example/src/pause-advanced-parallax/index.tsx">
58+
<img src="assets/pause-advanced-parallax.gif" width="300"/>
59+
</a>
5760
<a href="./example/src/scale-fade-in-out/index.tsx">
5861
<img src="assets/scale-fade-in-out.gif" width="300"/>
5962
</a>

README.zh-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
<a href="./example/src/advanced-parallax/index.tsx">
5656
<img src="assets/advanced-parallax.gif" width="300"/>
5757
</a>
58+
<a href="./example/src/pause-advanced-parallax/index.tsx">
59+
<img src="assets/pause-advanced-parallax.gif" width="300"/>
60+
</a>
5861
<a href="./example/src/scale-fade-in-out/index.tsx">
5962
<img src="assets/scale-fade-in-out.gif" width="300"/>
6063
</a>

assets/advanced-parallax.gif

-1010 KB
Loading

assets/pause-advanced-parallax.gif

2.03 MB
Loading

example/src/home/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const LayoutsPage: Array<Record<'name', keyof RootStackParamList>> = [
2323
{
2424
name: 'AdvancedParallax',
2525
},
26+
{
27+
name: 'PauseAdvancedParallax',
28+
},
2629
{
2730
name: 'ScaleFadeInOut',
2831
},

example/src/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import ComplexComponent from './complex';
1515
import SnapCarouselComplexComponent from './snap-carousel-complex';
1616
import SnapCarouselLoopComponent from './snap-carousel-loop';
1717
import AdvancedParallaxComponent from './advanced-parallax';
18+
import PauseAdvancedParallaxComponent from './pause-advanced-parallax';
1819
import ScaleFadeInOutComponent from './scale-fade-in-out';
1920

2021
const Stack = createNativeStackNavigator<RootStackParamList>();
@@ -26,6 +27,7 @@ export type RootStackParamList = {
2627
Stack: undefined;
2728
Complex: undefined;
2829
AdvancedParallax: undefined;
30+
PauseAdvancedParallax: undefined;
2931
ScaleFadeInOut: undefined;
3032

3133
SnapCarouselComplex: undefined;
@@ -67,6 +69,10 @@ function App() {
6769
name="AdvancedParallax"
6870
component={AdvancedParallaxComponent}
6971
/>
72+
<Stack.Screen
73+
name="PauseAdvancedParallax"
74+
component={PauseAdvancedParallaxComponent}
75+
/>
7076
<Stack.Screen
7177
name="ScaleFadeInOut"
7278
component={ScaleFadeInOutComponent}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import * as React from 'react';
2+
import { Dimensions, View } from 'react-native';
3+
import Animated, {
4+
interpolate,
5+
interpolateColor,
6+
useAnimatedStyle,
7+
} from 'react-native-reanimated';
8+
import Carousel from '../../../src/index';
9+
import type { TAnimationStyle } from '../../../src/layouts/BaseLayout';
10+
import { SBItem } from '../components/SBItem';
11+
import SButton from '../components/SButton';
12+
13+
const window = Dimensions.get('window');
14+
const PAGE_WIDTH = window.width;
15+
16+
function Index() {
17+
const [isAutoPlay, setIsAutoPlay] = React.useState(false);
18+
const animationStyle: TAnimationStyle = React.useCallback(
19+
(value: number) => {
20+
'worklet';
21+
22+
const zIndex = interpolate(value, [-1, 0, 1], [-1000, 0, 1000]);
23+
const translateX = interpolate(
24+
value,
25+
[-1, 0, 1],
26+
[0, 0, PAGE_WIDTH]
27+
);
28+
29+
return {
30+
transform: [{ translateX }],
31+
zIndex,
32+
};
33+
},
34+
[]
35+
);
36+
37+
return (
38+
<View style={{ flex: 1 }}>
39+
<Carousel
40+
loop={true}
41+
autoPlay={isAutoPlay}
42+
style={{ width: PAGE_WIDTH, height: 240 }}
43+
width={PAGE_WIDTH}
44+
data={[...new Array(6).keys()]}
45+
renderItem={({ index, animationValue }) => {
46+
return (
47+
<CustomItem
48+
key={index}
49+
index={index}
50+
animationValue={animationValue}
51+
/>
52+
);
53+
}}
54+
customAnimation={animationStyle}
55+
/>
56+
<SButton
57+
onPress={() => {
58+
setIsAutoPlay(!isAutoPlay);
59+
}}
60+
>
61+
AutoPlay:{`${isAutoPlay}`}
62+
</SButton>
63+
</View>
64+
);
65+
}
66+
67+
interface ItemProps {
68+
index: number;
69+
animationValue: Animated.SharedValue<number>;
70+
}
71+
const CustomItem: React.FC<ItemProps> = ({ index, animationValue }) => {
72+
const maskStyle = useAnimatedStyle(() => {
73+
const backgroundColor = interpolateColor(
74+
animationValue.value,
75+
[-1, 0, 1],
76+
['#000000dd', 'transparent', '#000000dd']
77+
);
78+
79+
return {
80+
backgroundColor,
81+
};
82+
}, [animationValue]);
83+
84+
return (
85+
<View style={{ flex: 1 }}>
86+
<SBItem key={index} index={index} style={{ borderRadius: 0 }} />
87+
<Animated.View
88+
pointerEvents="none"
89+
style={[
90+
{
91+
position: 'absolute',
92+
top: 0,
93+
left: 0,
94+
right: 0,
95+
bottom: 0,
96+
},
97+
maskStyle,
98+
]}
99+
/>
100+
</View>
101+
);
102+
};
103+
104+
export default Index;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"!**/__mocks__"
2323
],
2424
"scripts": {
25-
"git": "node scripts/makegif.js ",
25+
"gif": "node scripts/makegif.js ./scripts/gif-works-directory",
2626
"test": "jest",
2727
"typescript": "tsc --noEmit",
2828
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",

scripts/makegif.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const options = {
66
resize: '441:235',
77
colors: 255,
88
fps: 60,
9+
speed: 0.5,
910
};
1011

1112
async function convertFile(input) {
@@ -46,6 +47,13 @@ async function main() {
4647
*/
4748
const [_p] = process.argv.slice(2);
4849
const sourceFilePath = path.resolve(_p);
50+
const isExists = fs.existsSync(sourceFilePath);
51+
52+
if (!isExists) {
53+
console.log('目标目录不存在');
54+
return;
55+
}
56+
4957
const sourceFileInfo = fs.statSync(sourceFilePath);
5058

5159
if (sourceFileInfo.isFile()) {
@@ -64,7 +72,13 @@ async function main() {
6472
await convertFile(filePath);
6573
} catch (e) {}
6674
}
75+
76+
console.log('任务结束');
6777
}
6878
}
6979

70-
main();
80+
try {
81+
main();
82+
} catch (e) {
83+
console.log(e);
84+
}

0 commit comments

Comments
 (0)