-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
158 lines (141 loc) · 3.93 KB
/
App.js
File metadata and controls
158 lines (141 loc) · 3.93 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
import React, { useState, useEffect } from "react";
import { View, Text, StyleSheet, TouchableOpacity, Linking } from "react-native";
import * as Font from "expo-font";
import * as ScreenOrientation from "expo-screen-orientation";
const DigitalClock = () => {
const [time, setTime] = useState(new Date());
const [fontLoaded, setFontLoaded] = useState(false);
const [orientation, setOrientation] = useState("portrait");
const [hour, setHour] = useState(time.getHours() % 12 || 12);
const [ampm, setAmpm] = useState(time.getHours() < 12 ? "aM" : "pM");
useEffect(() => {
async function loadFont() {
await Font.loadAsync({
"DigitalDismay": require("./assets/fonts/DigitalDismay.otf"),
});
setFontLoaded(true);
}
loadFont();
}, []);
useEffect(() => {
const interval = setInterval(() => {
setTime(new Date());
setHour(time.getHours() % 12 || 12)
setAmpm(time.getHours() < 12 ? 'aM' : 'pM')
}, 1000);
return () => clearInterval(interval);
}, []);
// Detect orientation changes
useEffect(() => {
async function getOrientation() {
const orientationInfo = await ScreenOrientation.getOrientationAsync();
if (
orientationInfo === ScreenOrientation.Orientation.LANDSCAPE_LEFT ||
orientationInfo === ScreenOrientation.Orientation.LANDSCAPE_RIGHT
) {
setOrientation("landscape");
} else {
setOrientation("portrait");
}
}
getOrientation();
// Listen for orientation changes
const subscription = ScreenOrientation.addOrientationChangeListener(
(event) => {
const newOrientation = event.orientationInfo.orientation;
if (
newOrientation === ScreenOrientation.Orientation.LANDSCAPE_LEFT ||
newOrientation === ScreenOrientation.Orientation.LANDSCAPE_RIGHT
) {
setOrientation("landscape");
} else {
setOrientation("portrait");
}
}
);
return () => ScreenOrientation.removeOrientationChangeListener(subscription);
}, []);
if (!fontLoaded) {
return <Text style={styles.loadingText}>Loading Font...</Text>;
}
const openWebsite = () => {
Linking.openURL("https://www.github.com/Faizal661");
};
return (
<View
style={[
styles.container,
orientation === "landscape" ? styles.landscapeContainer : {},
]}
>
<View>
<Text
style={[
styles.clockText,
orientation === "landscape" ? styles.landscapeText : styles.protraitText, styles.portraitContainer
]}
>
{hour.toString().padStart(2, "0")}:
{time.getMinutes().toString().padStart(2, "0")}:
{time.getSeconds().toString().padStart(2, "0")}
<Text style={styles.ampm}>{ampm}</Text>
</Text>
</View>
<TouchableOpacity onPress={openWebsite}>
<View style={styles.container2}>
<Text style={styles.loadingText}>Developed By </Text>
<Text style={styles.linkText}>Faizal661</Text>
</View>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#000",
},
container2: {
flexDirection: "row",
marginBottom: 60,
},
portraitContainer: {
marginLeft: 60,
paddingBottom: 50
},
protraitText: {
fontSize: 160,
width: 200,
lineHeight: 160,
},
clockText: {
fontSize: 110,
color: "#e1e1e1",
fontFamily: "DigitalDismay",
lineHeight: 120,
paddingBottom: 20,
},
landscapeText: {
lineHeight: 450,
fontSize: 230,
},
linkText: {
fontSize: 16,
color: "#767676",
fontWeight: "bold",
textDecorationLine: "underline",
},
loadingText: {
fontSize: 16,
color: "#b2b2b2",
},
ampm: {
fontSize: 30,
color: "#b2b2b2",
}
});
export default function App() {
return <DigitalClock />;
}