Skip to content

Commit 88effd4

Browse files
committed
docs: add rotate-in-out.gif
1 parent 399b04c commit 88effd4

File tree

6 files changed

+102
-1
lines changed

6 files changed

+102
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ English | [简体中文](./README.zh-CN.md)
6363
<a href="./example/src/rotate-scale-fade-in-out/index.tsx">
6464
<img src="assets/rotate-scale-fade-in-out.gif" width="300"/>
6565
</a>
66+
<a href="./example/src/rotate-in-out/index.tsx">
67+
<img src="assets/rotate-in-out.gif" width="300"/>
68+
</a>
6669
</p>
6770

6871
## Table of contents

README.zh-CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
</a>
4949
</p>
5050

51-
5251
> 现在你可以和我们一起来制作酷炫的动画了! 非常简单! [[详情]](./docs/custom-animation.zh-CN.md)
5352
5453
<p align="center">
@@ -64,6 +63,9 @@
6463
<a href="./example/src/rotate-scale-fade-in-out/index.tsx">
6564
<img src="assets/rotate-scale-fade-in-out.gif" width="300"/>
6665
</a>
66+
<a href="./example/src/rotate-in-out/index.tsx">
67+
<img src="assets/rotate-in-out.gif" width="300"/>
68+
</a>
6769
</p>
6870

6971
## 目录

assets/rotate-in-out.gif

2.23 MB
Loading

example/src/home/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const LayoutsPage: Array<Record<'name', keyof RootStackParamList>> = [
2020
{
2121
name: 'Stack',
2222
},
23+
];
24+
25+
const CustomAnimations: Array<Record<'name', keyof RootStackParamList>> = [
2326
{
2427
name: 'AdvancedParallax',
2528
},
@@ -29,6 +32,9 @@ const LayoutsPage: Array<Record<'name', keyof RootStackParamList>> = [
2932
{
3033
name: 'ScaleFadeInOut',
3134
},
35+
{
36+
name: 'RotateInOut',
37+
},
3238
{
3339
name: 'RotateScaleFadeInOut',
3440
},
@@ -68,6 +74,21 @@ const Index = () => {
6874
</TouchableHighlight>
6975
);
7076
})}
77+
<View style={styles.section}>
78+
<Text style={styles.sectionText}>{'CustomAnimations'}</Text>
79+
</View>
80+
{CustomAnimations.map(({ name }, index) => {
81+
return (
82+
<TouchableHighlight
83+
key={index}
84+
onPress={() => navigation.navigate(name)}
85+
>
86+
<View style={styles.listItem}>
87+
<Text style={styles.text}>{name}</Text>
88+
</View>
89+
</TouchableHighlight>
90+
);
91+
})}
7192
<View style={styles.section}>
7293
<Text style={styles.sectionText}>{'Others'}</Text>
7394
</View>

example/src/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import SnapCarouselLoopComponent from './snap-carousel-loop';
1717
import AdvancedParallaxComponent from './advanced-parallax';
1818
import PauseAdvancedParallaxComponent from './pause-advanced-parallax';
1919
import ScaleFadeInOutComponent from './scale-fade-in-out';
20+
import RotateInOutComponent from './rotate-in-out';
2021
import RotateScaleFadeInOutComponent from './rotate-scale-fade-in-out';
2122

2223
const Stack = createNativeStackNavigator<RootStackParamList>();
@@ -30,6 +31,7 @@ export type RootStackParamList = {
3031
AdvancedParallax: undefined;
3132
PauseAdvancedParallax: undefined;
3233
ScaleFadeInOut: undefined;
34+
RotateInOut: undefined;
3335
RotateScaleFadeInOut: undefined;
3436

3537
SnapCarouselComplex: undefined;
@@ -79,6 +81,10 @@ function App() {
7981
name="ScaleFadeInOut"
8082
component={ScaleFadeInOutComponent}
8183
/>
84+
<Stack.Screen
85+
name="RotateInOut"
86+
component={RotateInOutComponent}
87+
/>
8288
<Stack.Screen
8389
name="RotateScaleFadeInOut"
8490
component={RotateScaleFadeInOutComponent}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import * as React from 'react';
2+
import { Dimensions, View } from 'react-native';
3+
import { interpolate } from 'react-native-reanimated';
4+
import Carousel from 'react-native-reanimated-carousel';
5+
import type { TAnimationStyle } from '../../../src/layouts/BaseLayout';
6+
import { SBItem } from '../components/SBItem';
7+
import { ElementsText } from '../constants';
8+
import { useToggleButton } from '../hooks/useToggleButton';
9+
10+
const window = Dimensions.get('window');
11+
const scale = 0.7;
12+
const PAGE_WIDTH = window.width * scale;
13+
const PAGE_HEIGHT = 240 * scale;
14+
15+
function Index() {
16+
const AutoPLay = useToggleButton({
17+
defaultValue: false,
18+
buttonTitle: ElementsText.AUTOPLAY,
19+
});
20+
21+
const animationStyle: TAnimationStyle = React.useCallback(
22+
(value: number) => {
23+
'worklet';
24+
25+
const zIndex = interpolate(value, [-1, 0, 1], [10, 20, 30]);
26+
const rotateZ = `${interpolate(
27+
value,
28+
[-1, 0, 1],
29+
[-45, 0, 45]
30+
)}deg`;
31+
const translateX = interpolate(
32+
value,
33+
[-1, 0, 1],
34+
[-window.width, 0, window.width]
35+
);
36+
37+
return {
38+
transform: [{ rotateZ }, { translateX }],
39+
zIndex,
40+
};
41+
},
42+
[]
43+
);
44+
45+
return (
46+
<View style={{ flex: 1 }}>
47+
<Carousel
48+
loop
49+
style={{
50+
width: window.width,
51+
height: 240,
52+
justifyContent: 'center',
53+
alignItems: 'center',
54+
}}
55+
width={PAGE_WIDTH}
56+
height={PAGE_HEIGHT}
57+
data={[...new Array(6).keys()]}
58+
renderItem={({ index }) => {
59+
return <SBItem key={index} index={index} />;
60+
}}
61+
autoPlay={AutoPLay.status}
62+
customAnimation={animationStyle}
63+
/>
64+
{AutoPLay.button}
65+
</View>
66+
);
67+
}
68+
69+
export default Index;

0 commit comments

Comments
 (0)