-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
179 lines (170 loc) · 4.24 KB
/
App.js
File metadata and controls
179 lines (170 loc) · 4.24 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
172
173
174
175
176
177
import React, { useState, useRef } from 'react';
import {
Animated,
StatusBar,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
export default App;
function App(){
const [cardColor, setCardColor] = useState("#6A1B4D");
const [darkMode, setDarkMode] = useState(false); // State for light/dark mode
const cardScale = useRef(new Animated.Value(1)).current; // Card scale animation
const buttonScale = useRef(new Animated.Value(1)).current; // Button scale animation
const generateColor = () => {
const hexRange = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += hexRange[Math.floor(Math.random() * 16)];
}
setCardColor(color);
// Trigger card animation
Animated.sequence([
Animated.timing(cardScale, {
toValue: 1.1, // Increase scale
duration: 75,
useNativeDriver: true,
}),
Animated.timing(cardScale, {
toValue: 1, // Reset to original scale
duration: 100,
useNativeDriver: true,
}),
]).start();
// Trigger button animation
Animated.sequence([
Animated.timing(buttonScale, {
toValue: 0.9, // Shrink button slightly
duration: 150,
useNativeDriver: true,
}),
Animated.timing(buttonScale, {
toValue: 1, // Reset to original scale
duration: 150,
useNativeDriver: true,
}),
]).start();
};
const toggleTheme = () => {
setDarkMode((prevMode) => !prevMode);
};
return (
<>
<StatusBar
backgroundColor={darkMode ? "#1E1E1E" : "#bcf6f7"}
barStyle={darkMode ? "light-content" : "dark-content"}
/>
<View
style={[
styles.container,
{ backgroundColor: darkMode ? "#1E1E1E" : "#bcf6f7" },
]}
>
<TouchableOpacity onPress={toggleTheme} style={styles.themeToggleBtn}>
<Text style={styles.themeToggleText}>
{darkMode ? " 🌞 " : " 🌚 "}
</Text>
</TouchableOpacity>
<Text
style={[styles.title, { color: darkMode ? "#FFF" : "#333" }]}
>
Background Changer🎨
</Text>
<Animated.View
style={[
styles.card,
{ backgroundColor: cardColor, transform: [{ scale: cardScale }] },
]}
>
<Text style={styles.cardText}>I'm a colorful card!</Text>
</Animated.View>
<TouchableOpacity onPress={generateColor}>
<Animated.View
style={[
styles.actionBtn,
{
transform: [{ scale: buttonScale }],
backgroundColor: darkMode ? "#444" : "#00b4c5",
},
]}
>
<Text
style={[
styles.actionBtnTxt,
{ color: darkMode ? "#FFF" : "#000" },
]}
>
Press Me
</Text>
</Animated.View>
</TouchableOpacity>
</View>
</>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
padding: 20,
},
title: {
fontSize: 28,
fontWeight: "bold",
marginBottom: 20,
},
card: {
width: 300,
height: 450,
borderRadius: 12,
elevation: 60,
shadowColor: "#000",
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.3,
shadowRadius: 4,
alignItems: "center",
justifyContent: "center",
marginBottom: 30,
},
cardText: {
fontSize: 28,
color: "#fff",
fontWeight: "bold",
fontStyle:"italic"
},
actionBtn: {
backgroundColor: '#6200ea',
width: 90,
height: 50,
borderRadius: 10, // Makes the button circular
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.3,
shadowRadius: 3,
elevation: 5,
},
actionBtnTxt: {
fontSize: 14,
fontWeight: 600,
textTransform: "uppercase",
},
themeToggleBtn: {
position: "absolute",
top: 60,
right: 20,
padding: 10,
backgroundColor: 'transparent',
// borderRadius: 8,
elevation: 4,
},
themeToggleText: {
fontSize: 25,
fontWeight: "bold",
color: "#000",
},
});