forked from ReactiveKoding/Custom-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
220 lines (185 loc) · 5.55 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { StatusBar } from 'expo-status-bar';
import React, { useRef, useState } from 'react';
import { Animated, Image, SafeAreaView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import profile from './assets/profile.png';
// Tab ICons...
import home from './assets/home.png';
import search from './assets/search.png';
import notifications from './assets/bell.png';
import settings from './assets/settings.png';
import logout from './assets/logout.png';
// Menu
import menu from './assets/menu.png';
import close from './assets/close.png';
// Photo
import photo from './assets/photo.jpg';
export default function App() {
const [currentTab, setCurrentTab] = useState("Home");
// To get the curretn Status of menu ...
const [showMenu, setShowMenu] = useState(false);
// Animated Properties...
const offsetValue = useRef(new Animated.Value(0)).current;
// Scale Intially must be One...
const scaleValue = useRef(new Animated.Value(1)).current;
const closeButtonOffset = useRef(new Animated.Value(0)).current;
return (
<SafeAreaView style={styles.container}>
<View style={{ justifyContent: 'flex-start', padding: 15 }}>
<Image source={profile} style={{
width: 60,
height: 60,
borderRadius: 10,
marginTop: 8
}}></Image>
<Text style={{
fontSize: 20,
fontWeight: 'bold',
color: 'white',
marginTop: 20
}}>Jenna Ezarik</Text>
<TouchableOpacity>
<Text style={{
marginTop: 6,
color: 'white'
}}>View Profile</Text>
</TouchableOpacity>
<View style={{ flexGrow: 1, marginTop: 50 }}>
{
// Tab Bar Buttons....
}
{TabButton(currentTab, setCurrentTab, "Home", home)}
{TabButton(currentTab, setCurrentTab, "Search", search)}
{TabButton(currentTab, setCurrentTab, "Notifications", notifications)}
{TabButton(currentTab, setCurrentTab, "Settings", settings)}
</View>
<View>
{TabButton(currentTab, setCurrentTab, "LogOut", logout)}
</View>
</View>
{
// Over lay View...
}
<Animated.View style={{
flexGrow: 1,
backgroundColor: 'white',
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
paddingHorizontal: 15,
paddingVertical: 20,
borderRadius: showMenu ? 15 : 0,
// Transforming View...
transform: [
{ scale: scaleValue },
{ translateX: offsetValue }
]
}}>
{
// Menu Button...
}
<Animated.View style={{
transform: [{
translateY: closeButtonOffset
}]
}}>
<TouchableOpacity onPress={() => {
// Do Actions Here....
// Scaling the view...
Animated.timing(scaleValue, {
toValue: showMenu ? 1 : 0.88,
duration: 300,
useNativeDriver: true
})
.start()
Animated.timing(offsetValue, {
// YOur Random Value...
toValue: showMenu ? 0 : 230,
duration: 300,
useNativeDriver: true
})
.start()
Animated.timing(closeButtonOffset, {
// YOur Random Value...
toValue: !showMenu ? -30 : 0,
duration: 300,
useNativeDriver: true
})
.start()
setShowMenu(!showMenu);
}}>
<Image source={showMenu ? close : menu} style={{
width: 20,
height: 20,
tintColor: 'black',
marginTop: 40,
}}></Image>
</TouchableOpacity>
<Text style={{
fontSize: 30,
fontWeight: 'bold',
color: 'black',
paddingTop: 20
}}>{currentTab}</Text>
<Image source={photo} style={{
width: '100%',
height: 300,
borderRadius: 15,
marginTop: 25
}}></Image>
<Text style={{
fontSize: 20,
fontWeight: 'bold'
, paddingTop: 15,
paddingBottom: 5
}}>Jenna Ezarik</Text>
<Text style={{
}}>Techie, YouTuber, PS Lover, Apple Sheep's Sister</Text>
</Animated.View>
</Animated.View>
</SafeAreaView>
);
}
// For multiple Buttons...
const TabButton = (currentTab, setCurrentTab, title, image) => {
return (
<TouchableOpacity onPress={() => {
if (title == "LogOut") {
// Do your Stuff...
} else {
setCurrentTab(title)
}
}}>
<View style={{
flexDirection: "row",
alignItems: 'center',
paddingVertical: 8,
backgroundColor: currentTab == title ? 'white' : 'transparent',
paddingLeft: 13,
paddingRight: 35,
borderRadius: 8,
marginTop: 15
}}>
<Image source={image} style={{
width: 25, height: 25,
tintColor: currentTab == title ? "#5359D1" : "white"
}}></Image>
<Text style={{
fontSize: 15,
fontWeight: 'bold',
paddingLeft: 15,
color: currentTab == title ? "#5359D1" : "white"
}}>{title}</Text>
</View>
</TouchableOpacity>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#5359D1',
alignItems: 'flex-start',
justifyContent: 'flex-start',
},
});