-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
171 lines (153 loc) · 5.09 KB
/
Copy pathApp.js
File metadata and controls
171 lines (153 loc) · 5.09 KB
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
import FlatScreen from './screens/FlatScreen';
import StopwatchScreen from './screens/StopwatchScreen';
import RoundScreen from './screens/RoundScreen';
import HomeScreen from './screens/HomeScreen';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {useState, useEffect} from 'react'
import {View, StyleSheet, Button, Pressable, Image} from 'react-native'
import AsyncStorage from '@react-native-async-storage/async-storage';
const defaultTimer = require('./components/Constants/DefaultTimer')
const defaultStopwatch = require('./components/Constants/DefaultStopwatch')
import * as TaskManager from 'expo-task-manager';
export default function App() {
const [showTimers, setShowTimers] = useState(false)
const [isDarkMode, setIsDarkMode] = useState(false)
// TaskManager.defineTask('background-fetch', async () => {
// const now = Date.now();
// console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`);
// // Be sure to return the successful result type!
// return BackgroundFetch.BackgroundFetchResult.NewData;
// });
useEffect(() => {
console.log('app use effect')
_asyncSetData(defaultTimer, 'timersArray')
_asyncSetData(defaultStopwatch, 'stopwatchArray')
}, [])
const _asyncSetData = async (array, dataKey) => {
// const currentData = await _asyncGetData('timersArray')
// const newArray = [...currentData, {...item, index: index}]
try {
await AsyncStorage.setItem(
dataKey,
//timersArray
JSON.stringify(array)
// JSON.stringify(timersArray)
);
} catch (error) {
console.log(error)
}
};
const _asyncGetData = async (dataKey) => {
try {
const value = await AsyncStorage.getItem(dataKey);
if (value !== null) {
// console.log("this value from get" , JSON.parse(value));
return JSON.parse(value)
}else{
return null
}
} catch (error) {
console.log(error)
};
}
return (
<View style = {isDarkMode ? {...styles.homeScreen, backgroundColor: 'black'}: {...styles.homeScreen, backgroundColor: 'white'}}>
<View style = {styles.headerButtons} >
<View style = {styles.toggles}>
<Pressable
style = {showTimers ?styles.toggleButtons : {...styles.toggleButtons, backgroundColor: 'rgb(255,149,0)'}}
onPress={() => setShowTimers(false)}>
<Image
style = {{height: 30, width: 30, marginRight: 7}}
source = {require('./Images/stopwatch.png')} />
</Pressable>
<Pressable
style = {showTimers ?{...styles.toggleButtons, backgroundColor: 'rgb(255,149,0)'} : styles.toggleButtons}
onPress={() => setShowTimers(true)}>
<Image
style = {{height: 30, width: 30}}
source = {require('./Images/sand-clock.png')} />
</Pressable>
</View>
<View style = {styles.darkModeContainer}>
<Pressable style = {styles.darkModeButton}
onPress = {() => {setIsDarkMode(!isDarkMode)}} >
<Image
style = {{height: 40, width: 40}}
source = {isDarkMode ? require('./Images/crescent-moon.png') : require('./Images/moon-icon.png')}/>
</Pressable>
</View>
{/*
<Button
title = "dark mode"
onPress={() => {setIsDarkMode(!isDarkMode)}}/> */}
</View>
{/*
<StopwatchScreen
asyncSetData = {_asyncSetData}
asyncGetData = {_asyncGetData}
isDarkMode = {isDarkMode}
isVisibleNow = {showTimers}/>
<FlatScreen
asyncSetData = {_asyncSetData}
asyncGetData = {_asyncGetData}
isDarkMode = {isDarkMode}
isVisibleNow = {showTimers}/> */}
<StopwatchScreen
asyncSetData = {_asyncSetData}
asyncGetData = {_asyncGetData}
isDarkMode = {isDarkMode}
isVisibleNow = {showTimers}
toggle = {() => setShowTimers(false)}/>
{/*
{
showTimers
?
<FlatScreen
asyncSetData = {_asyncSetData}
asyncGetData = {_asyncGetData}
isDarkMode = {isDarkMode}
isVisibleNow = {showTimers}/>
:
<StopwatchScreen
asyncSetData = {_asyncSetData}
asyncGetData = {_asyncGetData}
isDarkMode = {isDarkMode}
isVisibleNow = {showTimers}/>
} */}
</View>
);
}
const styles = StyleSheet.create({
homeScreen: {
flex: 1,
//backgroundColor: 'red'
},
headerButtons: {
marginTop: 50,
flexDirection: 'row',
justifyContent: 'space-between'
},
toggles:{
width: 100,
flexDirection: 'row',
marginLeft: 5
// justifyContent: 'space-between'
},
toggleButtons: {
width: 50,
height: 50,
borderRadius: 30,
borderColor: 'black',
borderWidth: 3,
marginLeft: 20,
backgroundColor: 'white',
justifyContent: 'center',
alignItems: 'center'
},
darkModeContainer: {
// backgroundColor: 'white',
marginRight: 20
}
});