Skip to content

Commit e2b6d55

Browse files
EQuimperjanicduplessis
authored andcommitted
feat(example): add spin demo for infinite rotation
Adds SpinDemo with two examples: - Infinite Z-axis rotation with loop: 'repeat' - Rotation + scale with loop: 'reverse'
1 parent 7d87f81 commit e2b6d55

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

example/src/demos/SpinDemo.tsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { useState } from 'react';
2+
import { View, StyleSheet } from 'react-native';
3+
import { EaseView } from 'react-native-ease';
4+
5+
import { Section } from '../components/Section';
6+
import { Button } from '../components/Button';
7+
8+
export function SpinDemo() {
9+
const [playing, setPlaying] = useState(false);
10+
const [playingWithScale, setPlayingWithScale] = useState(false);
11+
return (
12+
<>
13+
<Section title="Spin (Repeat Loop)">
14+
{playing && (
15+
<EaseView
16+
initialAnimate={{ rotate: 0 }}
17+
animate={{ rotate: 360 }}
18+
transition={{
19+
type: 'timing',
20+
duration: 1000,
21+
easing: 'linear',
22+
loop: 'repeat',
23+
}}
24+
style={styles.box}
25+
>
26+
<View style={styles.indicator} />
27+
</EaseView>
28+
)}
29+
<Button
30+
label={playing ? 'Stop' : 'Start'}
31+
onPress={() => setPlaying((p) => !p)}
32+
/>
33+
</Section>
34+
<Section title="Spin + Scale (Reverse Loop)">
35+
{playingWithScale && (
36+
<EaseView
37+
initialAnimate={{ rotate: 0, scale: 0.8 }}
38+
animate={{ rotate: 360, scale: 1.2 }}
39+
transition={{
40+
type: 'timing',
41+
duration: 1500,
42+
easing: 'easeInOut',
43+
loop: 'reverse',
44+
}}
45+
style={styles.box}
46+
>
47+
<View style={styles.indicator} />
48+
</EaseView>
49+
)}
50+
<Button
51+
label={playingWithScale ? 'Stop' : 'Start'}
52+
onPress={() => setPlayingWithScale((p) => !p)}
53+
/>
54+
</Section>
55+
</>
56+
);
57+
}
58+
59+
const styles = StyleSheet.create({
60+
box: {
61+
width: 80,
62+
height: 80,
63+
backgroundColor: '#4a90d9',
64+
borderRadius: 12,
65+
alignItems: 'center',
66+
justifyContent: 'flex-start',
67+
paddingTop: 8,
68+
},
69+
indicator: {
70+
width: 12,
71+
height: 12,
72+
borderRadius: 6,
73+
backgroundColor: '#fff',
74+
},
75+
});

example/src/demos/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { StyleReRenderDemo } from './StyleReRenderDemo';
2222
import { StyledCardDemo } from './StyledCardDemo';
2323
import { TransformOriginDemo } from './TransformOriginDemo';
2424
import { PerPropertyDemo } from './PerPropertyDemo';
25+
import { SpinDemo } from './SpinDemo';
2526
import { UniwindDemo } from './uniwind/UniwindDemo';
2627

2728
interface DemoEntry {
@@ -75,6 +76,7 @@ export const demos: Record<string, DemoEntry> = {
7576
title: 'Uniwind',
7677
section: 'Style',
7778
},
79+
'spin': { component: SpinDemo, title: 'Spin', section: 'Loop' },
7880
'pulse': { component: PulseDemo, title: 'Pulse', section: 'Loop' },
7981
'banner': { component: BannerDemo, title: 'Banner', section: 'Loop' },
8082
'interrupt': {

0 commit comments

Comments
 (0)