-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
65 lines (61 loc) · 1.49 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, {useEffect, useRef} from 'react';
import {Button, StyleSheet, Text, View} from 'react-native';
import LottieView from 'lottie-react-native';
import AnimatedLottieView from "lottie-react-native";
const App = () => {
const lottieRef = useRef<AnimatedLottieView>();
const resetAnimation = () => {
if(lottieRef.current){
lottieRef.current.reset();
lottieRef.current.play();
}
}
useEffect(()=>{
if(lottieRef.current){
lottieRef.current.play();
}
},[lottieRef])
return (
<View style={styles.animationContainer}>
<LottieView
ref={lottieRef}
style={{
width: 400,
height: 400,
backgroundColor: '#eee',
}}
source={require('./assets/lottie_sample.json')}
/>
<View style={{
elevation: 1,
backgroundColor: 'rgba(255,0,0,0.5)',
padding: 10,
position: "absolute",
flex: 1
}}>
<Text style={{
color: "#fff",
fontWeight: "bold",
fontSize: 40
}}>
Hello World!
</Text>
</View>
<View style={styles.buttonContainer}>
<Button title="アニメーションを最初から再生する" onPress={resetAnimation}/>
</View>
</View>
);
}
export default App;
const styles = StyleSheet.create({
animationContainer: {
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
flex: 1,
},
buttonContainer: {
paddingTop: 20,
},
});