-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
156 lines (146 loc) · 3.85 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
import { StatusBar } from 'expo-status-bar';
import { useEffect, useState } from 'react';
import { ActivityIndicator, Image, SafeAreaView, StyleSheet, Switch, Text, TouchableOpacity, View } from 'react-native';
import LogoWhite from './assets/logo-black.png'
import LogoDark from './assets/logo-white.png'
export default function App() {
const [isLoading, setIsLoading] = useState(false);
const [data, setData] = useState([]);
const [isDark, setIsDark] = useState(false)
const toggleSwitch = () => setIsDark(previousState => !previousState);
const getBibleVerse = async () => {
try {
setIsLoading(true)
const response = await fetch('https://labs.bible.org/api/?passage=random&type=json&formatting=plain');
const json = await response.json()
setData(json)
} catch (error) {
console.log(error)
} finally {
setIsLoading(false)
}
}
const NextBtn = () => {
return (
<TouchableOpacity style={!isDark ? styles.nextBtnLight : styles.nextBtnDark} onPress={getBibleVerse}>
<Text style={!isDark ? styles.nextBtnLightTxt : styles.nextBtnDarkTxt}>Next</Text>
</TouchableOpacity>
)
}
useEffect(() => {
getBibleVerse()
}, [])
return (
<SafeAreaView style={isDark ? styles.containerDark : styles.containerLight}>
{isLoading ? (
<ActivityIndicator size='large' />
) : (
<>
<View style={styles.toggleBtn}>
<Switch
trackColor={{false: '#767577', true: '#767577'}}
thumbColor={isDark ? '#f4f3f4' : '#f4f3f4'}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={isDark}
/>
<Text style={isDark ? {color:'#fff'} : {color:'#000'}}>{isDark ? 'Dark Mode': 'Light Mode'}</Text>
</View>
<View style={styles.content}>
<Image style={styles.logo} source={isDark ? LogoDark : LogoWhite} resizeMode='contain' />
<Text style={!isDark ? styles.titleLight : styles.titleDark}>
{data[0]?.bookname} {data[0]?.chapter}:{data[0]?.verse}
</Text>
<Text style={!isDark ? styles.bodyLight : styles.bodyDark}>{data[0]?.text}</Text>
<NextBtn />
</View>
</>
)}
<StatusBar style="auto" />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
containerLight: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
paddingHorizontal: 20,
},
containerDark: {
flex: 1,
backgroundColor: '#0b0b0b',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
paddingHorizontal: 20
},
content: {
flex: 1,
alignItems: 'center',
},
titleLight: {
color: '#000',
fontSize: 25,
paddingBottom: 20,
borderBottomColor: '#000',
borderBottomWidth: 2
},
titleDark: {
color: '#fff',
fontSize: 25,
paddingBottom: 20,
borderBottomColor: '#fff',
borderBottomWidth: 2
},
bodyLight: {
color: '#000',
fontSize: 25,
fontWeight: '300',
padding: 10,
borderRadius: 10,
textAlign: 'center',
paddingVertical: 20
},
bodyDark: {
color: '#fff',
fontSize: 25,
fontWeight: '300',
padding: 10,
borderRadius: 10,
textAlign: 'center',
paddingVertical: 20
},
toggleBtn: {
position: 'absolute',
marginTop: 30,
top: 0,
right: 0,
marginEnd: 20
},
logo: {
width: 100,
},
nextBtnLight : {
paddingHorizontal: 30,
paddingVertical: 10,
borderRadius: 10,
borderColor: '#000',
borderWidth: 1
},
nextBtnDark : {
paddingHorizontal: 30,
paddingVertical: 10,
borderRadius: 10,
borderColor: '#fff',
borderWidth: 1,
},
nextBtnLightTxt: {
color: '#000'
},
nextBtnDarkTxt: {
color: '#fff'
}
});