Skip to content

Commit 836f224

Browse files
committed
docs: add anim-tab-bar.gif
1 parent 88effd4 commit 836f224

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ English | [简体中文](./README.zh-CN.md)
6666
<a href="./example/src/rotate-in-out/index.tsx">
6767
<img src="assets/rotate-in-out.gif" width="300"/>
6868
</a>
69+
<a href="./example/src/anim-tab-bar/index.tsx">
70+
<img src="assets/anim-tab-bar.gif" width="300"/>
71+
</a>
6972
</p>
7073

7174
## Table of contents

README.zh-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
<a href="./example/src/rotate-in-out/index.tsx">
6767
<img src="assets/rotate-in-out.gif" width="300"/>
6868
</a>
69+
<a href="./example/src/anim-tab-bar/index.tsx">
70+
<img src="assets/anim-tab-bar.gif" width="300"/>
71+
</a>
6972
</p>
7073

7174
## 目录

assets/anim-tab-bar.gif

272 KB
Loading

example/src/anim-tab-bar/index.tsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import * as React from 'react';
2+
import { Dimensions } from 'react-native';
3+
import { Extrapolate, interpolate } from 'react-native-reanimated';
4+
import Carousel from 'react-native-reanimated-carousel';
5+
import { View, Text } from 'react-native-ui-lib';
6+
import type { TAnimationStyle } from '../../../src/layouts/BaseLayout';
7+
import { ElementsText } from '../constants';
8+
import { useToggleButton } from '../hooks/useToggleButton';
9+
10+
const window = Dimensions.get('window');
11+
const PAGE_WIDTH = 40;
12+
const PAGE_HEIGHT = 40;
13+
14+
function Index() {
15+
const AutoPLay = useToggleButton({
16+
defaultValue: false,
17+
buttonTitle: ElementsText.AUTOPLAY,
18+
});
19+
20+
const animationStyle: TAnimationStyle = React.useCallback(
21+
(value: number) => {
22+
'worklet';
23+
24+
const translateX = interpolate(
25+
value,
26+
[-1, 0, 1],
27+
[-PAGE_WIDTH, 0, PAGE_WIDTH]
28+
);
29+
30+
const opacity = interpolate(
31+
value,
32+
[-1, 0, 1],
33+
[0.5, 1, 0.5],
34+
Extrapolate.CLAMP
35+
);
36+
37+
const scale = interpolate(
38+
value,
39+
[-1, 0, 1],
40+
[0.8, 1.4, 0.8],
41+
Extrapolate.CLAMP
42+
);
43+
44+
return {
45+
transform: [{ translateX }, { scale }],
46+
opacity,
47+
};
48+
},
49+
[]
50+
);
51+
52+
return (
53+
<View style={{ flex: 1 }}>
54+
<Carousel
55+
loop={false}
56+
style={{
57+
width: window.width,
58+
justifyContent: 'center',
59+
alignItems: 'center',
60+
paddingVertical: 110,
61+
}}
62+
width={PAGE_WIDTH}
63+
height={PAGE_HEIGHT}
64+
data={['周一', '周二', '周三', '周四', '周五', '周六', '周日']}
65+
renderItem={({ item }) => {
66+
return (
67+
<View center height={'100%'}>
68+
<Text color={'#26292E'}>{item}</Text>
69+
</View>
70+
);
71+
}}
72+
autoPlay={AutoPLay.status}
73+
customAnimation={animationStyle}
74+
/>
75+
{AutoPLay.button}
76+
</View>
77+
);
78+
}
79+
80+
export default Index;

example/src/home/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const CustomAnimations: Array<Record<'name', keyof RootStackParamList>> = [
3838
{
3939
name: 'RotateScaleFadeInOut',
4040
},
41+
{
42+
name: 'AnimTabBar',
43+
},
4144
];
4245

4346
const OtherPage: Array<Record<'name', keyof RootStackParamList>> = [

example/src/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import PauseAdvancedParallaxComponent from './pause-advanced-parallax';
1919
import ScaleFadeInOutComponent from './scale-fade-in-out';
2020
import RotateInOutComponent from './rotate-in-out';
2121
import RotateScaleFadeInOutComponent from './rotate-scale-fade-in-out';
22+
import AnimTabBarComponent from './anim-tab-bar';
2223

2324
const Stack = createNativeStackNavigator<RootStackParamList>();
2425

@@ -27,12 +28,14 @@ export type RootStackParamList = {
2728
Normal: undefined;
2829
Parallax: undefined;
2930
Stack: undefined;
31+
3032
Complex: undefined;
3133
AdvancedParallax: undefined;
3234
PauseAdvancedParallax: undefined;
3335
ScaleFadeInOut: undefined;
3436
RotateInOut: undefined;
3537
RotateScaleFadeInOut: undefined;
38+
AnimTabBar: undefined;
3639

3740
SnapCarouselComplex: undefined;
3841
SnapCarouselLoop: undefined;
@@ -89,6 +92,10 @@ function App() {
8992
name="RotateScaleFadeInOut"
9093
component={RotateScaleFadeInOutComponent}
9194
/>
95+
<Stack.Screen
96+
name="AnimTabBar"
97+
component={AnimTabBarComponent}
98+
/>
9299

93100
<Stack.Screen
94101
name="SnapCarouselComplex"

0 commit comments

Comments
 (0)