-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
194 lines (182 loc) · 8.07 KB
/
App.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { SafeAreaView, Text, TouchableOpacity, View ,Dimensions} from 'react-native'
import React, { useEffect,useState } from 'react'
import {PauseCircleIcon, PlayCircleIcon, StopCircleIcon} from "react-native-heroicons/outline"
import { CountdownCircleTimer } from 'react-native-countdown-circle-timer'
import ScrollPicker from 'react-native-picker-scrollview';
import { formatTime, hours, minutes, pickerSelectStyles, seconds } from './Constants';
var Sound = require('react-native-sound');
Sound.setCategory('Playback');
const { width, height } = Dimensions.get('window');
const whoosh = new Sound('sound.mp3', Sound.MAIN_BUNDLE, (error) => {});
export default function App() {
const [play, setPlay] = useState(false)
const [start, setStart] = useState(false);
const [stopTime,setStopTime] = useState(false);
const [key, setKey] = useState(0);
const [duration, setDuration] = useState(0);
const[second,setSecond] = useState(0);
const[minute,setMinute] = useState(0);
const[hour,setHour] = useState(0);
const resetTimer = () => {
setPlay(false);
setKey(prevKey => prevKey + 1)
};
useEffect(() => {
resetTimer()
setDuration(second + (60 * minute) + (3600* hour));
}, [second,minute,hour])
const onStart = ()=>{
if(duration>0){
resetTimer();
setStart(true)
setPlay(true)
}
}
const onEnd = ()=>{
resetTimer();
setStart(false)
setPlay(false)
setDuration(0)
setHour(0)
setMinute(0)
setSecond(0)
}
const onMusicStart = ()=>{
whoosh.setPan(1);
whoosh.setVolume(1);
whoosh.setNumberOfLoops(-1);
whoosh.play();
setStopTime(true);
}
const onMusicEnd = ()=>{
whoosh.stop(() => {
});
onEnd();
setStopTime(false)
}
return (
<View className="flex-1 bg-black">
<SafeAreaView className="min-h-full">
<View className="items-center mt-20 w-full">
{ start &&
<CountdownCircleTimer
size={width*0.8}
isPlaying={play}
duration={duration}
colors={"#0563e8"}
trailColor={"#ffffff"}
trailStrokeWidth={3}
strokeWidth={8}
key={key}
onComplete={() =>onMusicStart()}
>
{({ remainingTime, elapsedTime }) =>(
<View className="items-center">
{ !stopTime &&
<Text className="font-bold text-5xl text-white">
{formatTime(remainingTime)}
</Text>
}
{
stopTime &&
<TouchableOpacity onPress={()=>onMusicEnd()}>
<View className="rounded-full shadow-sm shadow-slate-500 bg-sky-600 p-5">
<Text className="text-2xl text-white font-bold">Stop Time</Text>
</View>
</TouchableOpacity>
}
</View>
)}
</CountdownCircleTimer>
}
{ !start &&
<View className="flex-row text-white" style={{width:250}}>
<ScrollPicker
dataSource={hours}
selectedIndex={hour}
wrapperColor={'#000000'}
highlightColor={'#000000'}
itemHeight={50}
wrapperHeight={150}
renderItem={(data, index, isSelected) => {
return(
<View>
<Text className={(isSelected)?"text-white font-bold text-5xl":" text-sky-200 text-2xl text-center"}>{data}</Text>
</View>
)
}}
onValueChange={(data) => {
setHour(data)
}}
/>
<View className="flex-col justify-center">
<Text className="text-white text-5xl"> : </Text>
</View>
<ScrollPicker
dataSource={minutes}
selectedIndex={minute}
wrapperColor={'#000000'}
highlightColor={'#000000'}
itemHeight={50}
wrapperHeight={150}
renderItem={(data, index, isSelected) => {
return(
<View>
<Text className={(isSelected)?"text-white font-bold text-5xl":" text-sky-200 text-2xl text-center"}>{data}</Text>
</View>
)
}}
onValueChange={(data) => {
setMinute(data)
}}
/>
<View className="flex-col justify-center">
<Text className="text-white text-5xl"> : </Text>
</View>
<ScrollPicker
dataSource={seconds}
selectedIndex={second}
wrapperColor={'#000000'}
highlightColor={'#000000'}
itemHeight={50}
wrapperHeight={150}
renderItem={(data, index, isSelected) => {
return(
<View>
<Text className={(isSelected)?"text-white font-bold text-5xl":" text-sky-200 text-2xl text-center"}>{data}</Text>
</View>
)
}}
onValueChange={(data) => {
setSecond(data)
}}
/>
</View>
}
</View>
<View className="absolute bottom-0 flex-row justify-center right-0 left-0 pb-10">
{play && start &&
<TouchableOpacity onPress={()=>setPlay(false)}>
<PauseCircleIcon size={50} strokeWidth={1} color="white"/>
</TouchableOpacity>
}
{!play && start &&
<TouchableOpacity onPress={()=>setPlay(true)}>
<PlayCircleIcon size={50} strokeWidth={1} color="white"/>
</TouchableOpacity>
}
{start &&
<TouchableOpacity onPress={onEnd}>
<StopCircleIcon size={50} strokeWidth={1} color="white"/>
</TouchableOpacity>
}
{setStopTime && !start &&
<TouchableOpacity onPress={onStart}>
<PlayCircleIcon size={50} strokeWidth={1} color="white"/>
</TouchableOpacity>
}
</View>
</SafeAreaView>
</View>
)
}