-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
88 lines (75 loc) · 2.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, {useRef, useState} from 'react';
import {Button, Text, useWindowDimensions, View, Animated} from 'react-native';
import Video from 'react-native-video'
function App() {
const { width, height } = useWindowDimensions()
const fadeAnim = useRef(new Animated.Value(1)).current
function fadeIn() {
Animated.timing(fadeAnim, {
toValue: 1,
duration: 500,
useNativeDriver: true
}).start()
}
function fadeOut() {
Animated.timing(fadeAnim, {
toValue: 0, // Fully transparent
duration: 500,
useNativeDriver: true,
}).start()
}
const player = useRef<Video>(null)
const isPortrait = height > width
const videos = [require('./videos/flower-valley.mp4'), require('./videos/manhattan.mp4'), require('./videos/tiger.mp4')]
const [currentVideo, setCurrentVideo] = useState(videos[0])
const [paused, setPaused] = useState(true)
if (isPortrait) {
return <Text style={{ color: 'red' }}>Please change orientation to landscape</Text>
}
function changeVideo(newVideo: any) {
if (paused) {
setCurrentVideo(newVideo)
setPaused(false)
fadeOut()
}
}
return (
<View style={{
position: 'relative',
width: '100%',
height: '100%'
}}>
<Video
style={{ width: '100%', height: '100%' }}
resizeMode='cover'
source={currentVideo}
ref={player}
paused={paused}
onLoad={() => {
if (paused) {
player.current?.seek(0)
}
}}
onEnd={() => {
setPaused(true)
player.current?.seek(0)
fadeIn()
}}
/>
<Animated.View style={{
gap: 10,
flexDirection: 'row',
justifyContent: 'space-evenly',
marginTop: 'auto',
bottom: 0,
marginBottom: 32,
opacity: fadeAnim
}}>
<Button title="EST" onPress={() => changeVideo(videos[0])} />
<Button title="RUS" onPress={() => changeVideo(videos[1])} />
<Button title="ENG" onPress={() => changeVideo(videos[2])} />
</Animated.View>
</View>
)
}
export default App;