feature profile
deskripsi: - drawer & alert - screen baru: edit profile, update photo, update background, create portofolio
This commit is contained in:
9
app/(application)/portofolio/[id].tsx
Normal file
9
app/(application)/portofolio/[id].tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Text, View } from "react-native";
|
||||||
|
|
||||||
|
export default function Portofolio() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Text>Portofolio</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
11
app/(application)/portofolio/create/[id].tsx
Normal file
11
app/(application)/portofolio/create/[id].tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Text, View } from "react-native";
|
||||||
|
import { useLocalSearchParams } from "expo-router";
|
||||||
|
|
||||||
|
export default function PortofolioCreate() {
|
||||||
|
const { id } = useLocalSearchParams();
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Text>Portofolio Create {id}</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,25 +1,51 @@
|
|||||||
|
|
||||||
|
import { IMenuDrawerItem } from "@/components/_Interface/types";
|
||||||
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
||||||
import { AccentColor, MainColor } from "@/constants/color-palet";
|
import AlertCustom from "@/components/Alert/AlertCustom";
|
||||||
|
import DrawerCustom from "@/components/Drawer/DrawerCustom";
|
||||||
|
import { MainColor } from "@/constants/color-palet";
|
||||||
|
import { DRAWER_HEIGHT } from "@/constants/constans-value";
|
||||||
|
import Profile_MenuDrawerSection from "@/screens/Profile/menuDrawerSection";
|
||||||
import { Styles } from "@/styles/global-styles";
|
import { Styles } from "@/styles/global-styles";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import React, { useRef, useState } from "react";
|
import React, { useRef, useState } from "react";
|
||||||
import {
|
import { Animated, Text, TouchableOpacity } from "react-native";
|
||||||
Alert,
|
|
||||||
Animated,
|
|
||||||
PanResponder,
|
|
||||||
StyleSheet,
|
|
||||||
Text,
|
|
||||||
TouchableOpacity,
|
|
||||||
View,
|
|
||||||
} from "react-native";
|
|
||||||
|
|
||||||
const DRAWER_HEIGHT = 300; // tinggi drawer
|
|
||||||
export default function Profile() {
|
export default function Profile() {
|
||||||
const { id } = useLocalSearchParams();
|
const { id } = useLocalSearchParams();
|
||||||
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
||||||
const [showLogoutAlert, setShowLogoutAlert] = useState(false);
|
const [showLogoutAlert, setShowLogoutAlert] = useState(false);
|
||||||
|
|
||||||
|
const drawerItems: IMenuDrawerItem[] = [
|
||||||
|
{
|
||||||
|
icon: "create",
|
||||||
|
label: "Edit profile",
|
||||||
|
path: "/(application)/profile/edit",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "camera",
|
||||||
|
label: "Ubah foto profile",
|
||||||
|
path: `/(application)/profile/update-photo/${id}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "image",
|
||||||
|
label: "Ubah latar belakang",
|
||||||
|
path: `/(application)/profile/update-background/${id}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "add-circle",
|
||||||
|
label: "Tambah portofolio",
|
||||||
|
path: `/(application)/portofolio/create/${id}`,
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// icon: "settings",
|
||||||
|
// label: "Dashboard Admin",
|
||||||
|
// path: `/(application)/profile/dashboard-admin`,
|
||||||
|
// },
|
||||||
|
{ icon: "log-out", label: "Keluar", color: "red", path: "" },
|
||||||
|
];
|
||||||
|
|
||||||
// Animasi menggunakan translateY (lebih kompatibel)
|
// Animasi menggunakan translateY (lebih kompatibel)
|
||||||
const drawerAnim = useRef(new Animated.Value(DRAWER_HEIGHT)).current; // mulai di luar bawah layar
|
const drawerAnim = useRef(new Animated.Value(DRAWER_HEIGHT)).current; // mulai di luar bawah layar
|
||||||
|
|
||||||
@@ -42,35 +68,16 @@ export default function Profile() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const panResponder = useRef(
|
const handleLogout = () => {
|
||||||
PanResponder.create({
|
console.log("User logout");
|
||||||
onMoveShouldSetPanResponder: (_, gestureState) => {
|
router.replace("/");
|
||||||
return gestureState.dy > 10; // gesek ke bawah
|
setShowLogoutAlert(false);
|
||||||
},
|
};
|
||||||
onPanResponderMove: (_, gestureState) => {
|
|
||||||
const offset = gestureState.dy;
|
|
||||||
if (offset >= 0 && offset <= DRAWER_HEIGHT) {
|
|
||||||
drawerAnim.setValue(offset); // batasi hingga max 500
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onPanResponderRelease: (_, gestureState) => {
|
|
||||||
if (gestureState.dy > 200) {
|
|
||||||
// Tutup drawer sepenuhnya jika gesek lebih dari 200
|
|
||||||
closeDrawer();
|
|
||||||
} else {
|
|
||||||
// Reset ke posisi awal jika gesek kurang
|
|
||||||
Animated.spring(drawerAnim, {
|
|
||||||
toValue: 0,
|
|
||||||
useNativeDriver: true,
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).current;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ViewWrapper>
|
<ViewWrapper>
|
||||||
|
{/* Header */}
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
title: "Profile",
|
title: "Profile",
|
||||||
@@ -96,212 +103,29 @@ export default function Profile() {
|
|||||||
<Text style={Styles.textLabel}>Profile {id}</Text>
|
<Text style={Styles.textLabel}>Profile {id}</Text>
|
||||||
</ViewWrapper>
|
</ViewWrapper>
|
||||||
|
|
||||||
{/* Overlay Gelap */}
|
{/* Drawer Komponen Eksternal */}
|
||||||
{isDrawerOpen && (
|
<DrawerCustom
|
||||||
<View
|
height={350}
|
||||||
style={[
|
isVisible={isDrawerOpen}
|
||||||
stylesDrawer.overlay,
|
drawerAnim={drawerAnim}
|
||||||
{ opacity: isDrawerOpen ? 0.6 : 0 }, // tampilkan overlay hanya saat drawer terbuka
|
closeDrawer={closeDrawer}
|
||||||
]}
|
>
|
||||||
pointerEvents={isDrawerOpen ? "auto" : "none"}
|
<Profile_MenuDrawerSection
|
||||||
>
|
drawerItems={drawerItems}
|
||||||
<TouchableOpacity onPress={closeDrawer} />
|
setShowLogoutAlert={setShowLogoutAlert}
|
||||||
</View>
|
/>
|
||||||
)}
|
</DrawerCustom>
|
||||||
|
|
||||||
{/* Custom Bottom Drawer */}
|
{/* Alert Komponen Eksternal */}
|
||||||
{isDrawerOpen && (
|
<AlertCustom
|
||||||
<Animated.View
|
isVisible={showLogoutAlert}
|
||||||
style={[
|
onLeftPress={() => setShowLogoutAlert(false)}
|
||||||
stylesDrawer.drawer,
|
onRightPress={handleLogout}
|
||||||
{ transform: [{ translateY: drawerAnim }] },
|
title="Apakah anda yakin ingin keluar?"
|
||||||
]}
|
textLeft="Batal"
|
||||||
{...panResponder.panHandlers}
|
textRight="Keluar"
|
||||||
>
|
colorRight={MainColor.red}
|
||||||
<View
|
/>
|
||||||
style={[
|
|
||||||
stylesDrawer.headerBar,
|
|
||||||
{ backgroundColor: MainColor.white },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TouchableOpacity
|
|
||||||
style={stylesDrawer.menuItem}
|
|
||||||
onPress={() => {
|
|
||||||
alert("Pilihan 1 diklik");
|
|
||||||
closeDrawer();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Text>Menu Item 1</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
<TouchableOpacity
|
|
||||||
style={stylesDrawer.menuItem}
|
|
||||||
onPress={() => {
|
|
||||||
alert("Pilihan 2 diklik");
|
|
||||||
closeDrawer();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Text>Menu Item 2</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
<TouchableOpacity
|
|
||||||
style={stylesDrawer.menuItem}
|
|
||||||
onPress={() => setShowLogoutAlert(true)}
|
|
||||||
>
|
|
||||||
<Text style={{ color: "red" }}>Logout Custom</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
<TouchableOpacity
|
|
||||||
style={stylesDrawer.menuItem}
|
|
||||||
onPress={() =>
|
|
||||||
Alert.alert(
|
|
||||||
"Konfirmasi Logout",
|
|
||||||
"Apakah Anda sudah yakin?",
|
|
||||||
[
|
|
||||||
{
|
|
||||||
text: "Batal",
|
|
||||||
onPress: () => console.log("Batal logout"),
|
|
||||||
style: "cancel",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: "Ya",
|
|
||||||
onPress: () => {
|
|
||||||
console.log("Logout dipilih");
|
|
||||||
// Di sini Anda bisa tambahkan fungsi logout seperti clear token, redirect, dll
|
|
||||||
closeDrawer();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{ cancelable: true }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Text style={{ color: "red" }}>Keluar</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</Animated.View>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{showLogoutAlert && (
|
|
||||||
<View style={styles.alertOverlay}>
|
|
||||||
<View style={styles.alertBox}>
|
|
||||||
<Text style={styles.alertTitle}>Konfirmasi Logout</Text>
|
|
||||||
<Text style={styles.alertMessage}>Apakah Anda sudah yakin?</Text>
|
|
||||||
<View style={styles.alertButtons}>
|
|
||||||
<TouchableOpacity
|
|
||||||
style={[styles.alertButton, styles.cancelButton]}
|
|
||||||
onPress={() => setShowLogoutAlert(false)}
|
|
||||||
>
|
|
||||||
<Text style={styles.buttonText}>Batal</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
<TouchableOpacity
|
|
||||||
style={[styles.alertButton, styles.confirmButton]}
|
|
||||||
onPress={() => {
|
|
||||||
console.log("Logout dipilih");
|
|
||||||
setShowLogoutAlert(false);
|
|
||||||
closeDrawer();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Text style={styles.buttonText}>Ya</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const stylesDrawer = StyleSheet.create({
|
|
||||||
overlay: {
|
|
||||||
position: "absolute",
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
backgroundColor: "black",
|
|
||||||
opacity: 0.4,
|
|
||||||
},
|
|
||||||
drawer: {
|
|
||||||
position: "absolute",
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
height: DRAWER_HEIGHT,
|
|
||||||
backgroundColor: AccentColor.darkblue,
|
|
||||||
borderTopLeftRadius: 20,
|
|
||||||
borderTopRightRadius: 20,
|
|
||||||
padding: 20,
|
|
||||||
shadowColor: "#000",
|
|
||||||
shadowOffset: { width: 0, height: -2 },
|
|
||||||
shadowOpacity: 0.2,
|
|
||||||
elevation: 5,
|
|
||||||
},
|
|
||||||
headerBar: {
|
|
||||||
width: 40,
|
|
||||||
height: 5,
|
|
||||||
backgroundColor: MainColor.white,
|
|
||||||
borderRadius: 5,
|
|
||||||
alignSelf: "center",
|
|
||||||
marginVertical: 10,
|
|
||||||
},
|
|
||||||
menuItem: {
|
|
||||||
padding: 15,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
alertOverlay: {
|
|
||||||
position: "absolute",
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
backgroundColor: "rgba(0,0,0,0.5)",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
zIndex: 999,
|
|
||||||
},
|
|
||||||
alertBox: {
|
|
||||||
width: "80%",
|
|
||||||
backgroundColor: "white",
|
|
||||||
borderRadius: 10,
|
|
||||||
padding: 20,
|
|
||||||
alignItems: "center",
|
|
||||||
shadowColor: "#000",
|
|
||||||
shadowOffset: { width: 0, height: 2 },
|
|
||||||
shadowOpacity: 0.25,
|
|
||||||
elevation: 5,
|
|
||||||
},
|
|
||||||
alertTitle: {
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: "bold",
|
|
||||||
marginBottom: 10,
|
|
||||||
},
|
|
||||||
alertMessage: {
|
|
||||||
textAlign: "center",
|
|
||||||
marginBottom: 20,
|
|
||||||
},
|
|
||||||
alertButtons: {
|
|
||||||
flexDirection: "row",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
width: "100%",
|
|
||||||
},
|
|
||||||
alertButton: {
|
|
||||||
flex: 1,
|
|
||||||
padding: 10,
|
|
||||||
borderRadius: 5,
|
|
||||||
marginHorizontal: 5,
|
|
||||||
alignItems: "center",
|
|
||||||
},
|
|
||||||
cancelButton: {
|
|
||||||
backgroundColor: "#ccc",
|
|
||||||
},
|
|
||||||
confirmButton: {
|
|
||||||
backgroundColor: "red",
|
|
||||||
},
|
|
||||||
buttonText: {
|
|
||||||
color: "white",
|
|
||||||
fontWeight: "bold",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|||||||
9
app/(application)/profile/edit.tsx
Normal file
9
app/(application)/profile/edit.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Text, View } from "react-native";
|
||||||
|
|
||||||
|
export default function ProfileEdit() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Text>Profile Edit</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
11
app/(application)/profile/update-background/[id].tsx
Normal file
11
app/(application)/profile/update-background/[id].tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Text, View } from "react-native";
|
||||||
|
import { useLocalSearchParams } from "expo-router";
|
||||||
|
|
||||||
|
export default function UpdatePhotoBackground() {
|
||||||
|
const { id } = useLocalSearchParams();
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Text>Update Photo Background {id}</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
11
app/(application)/profile/update-photo/[id].tsx
Normal file
11
app/(application)/profile/update-photo/[id].tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Text, View } from "react-native";
|
||||||
|
import { useLocalSearchParams } from "expo-router";
|
||||||
|
|
||||||
|
export default function UpdatePhotoProfile() {
|
||||||
|
const { id } = useLocalSearchParams();
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Text>Update Photo Profile {id}</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
127
components/Alert/AlertCustom.tsx
Normal file
127
components/Alert/AlertCustom.tsx
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
import { AccentColor, MainColor } from "@/constants/color-palet";
|
||||||
|
import { TEXT_SIZE_LARGE } from "@/constants/constans-value";
|
||||||
|
import React from "react";
|
||||||
|
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
|
||||||
|
|
||||||
|
interface AlertCustomProps {
|
||||||
|
isVisible: boolean;
|
||||||
|
onLeftPress: () => void;
|
||||||
|
onRightPress: () => void;
|
||||||
|
title?: string;
|
||||||
|
message?: string;
|
||||||
|
textLeft?: string;
|
||||||
|
textRight?: string;
|
||||||
|
colorLeft?: string;
|
||||||
|
colorRight?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AlertCustom({
|
||||||
|
isVisible,
|
||||||
|
onLeftPress,
|
||||||
|
onRightPress,
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
textLeft,
|
||||||
|
textRight,
|
||||||
|
colorLeft,
|
||||||
|
colorRight,
|
||||||
|
}: AlertCustomProps) {
|
||||||
|
if (!isVisible) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.overlay}>
|
||||||
|
<View style={styles.alertBox}>
|
||||||
|
{title && message ? (
|
||||||
|
<>
|
||||||
|
<Text style={styles.alertTitle}>{title}</Text>
|
||||||
|
<Text style={styles.alertMessage}>{message}</Text>
|
||||||
|
</>
|
||||||
|
) : title ? (
|
||||||
|
<Text style={styles.alertTitle}>{title}</Text>
|
||||||
|
) : (
|
||||||
|
<Text style={styles.alertMessage}>{message}</Text>
|
||||||
|
)}
|
||||||
|
<View style={styles.alertButtons}>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[
|
||||||
|
styles.alertButton,
|
||||||
|
colorLeft ? { backgroundColor: colorLeft } : styles.leftButton,
|
||||||
|
]}
|
||||||
|
onPress={onLeftPress}
|
||||||
|
>
|
||||||
|
<Text style={styles.buttonText}>{textLeft}</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[
|
||||||
|
styles.alertButton,
|
||||||
|
colorRight ? { backgroundColor: colorRight } : styles.rightButton,
|
||||||
|
]}
|
||||||
|
onPress={onRightPress}
|
||||||
|
>
|
||||||
|
<Text style={styles.buttonText}>{textRight}</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
overlay: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
backgroundColor: "rgba(0,0,0,0.5)",
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
zIndex: 999,
|
||||||
|
},
|
||||||
|
alertBox: {
|
||||||
|
width: "90%",
|
||||||
|
backgroundColor: MainColor.darkblue,
|
||||||
|
borderColor: AccentColor.blue,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderRadius: 10,
|
||||||
|
padding: 20,
|
||||||
|
alignItems: "center",
|
||||||
|
shadowColor: "#000",
|
||||||
|
shadowOffset: { width: 0, height: 2 },
|
||||||
|
shadowOpacity: 0.25,
|
||||||
|
elevation: 5,
|
||||||
|
},
|
||||||
|
alertTitle: {
|
||||||
|
fontSize: TEXT_SIZE_LARGE,
|
||||||
|
fontWeight: "bold",
|
||||||
|
marginBottom: 20,
|
||||||
|
color: MainColor.white,
|
||||||
|
},
|
||||||
|
alertMessage: {
|
||||||
|
textAlign: "center",
|
||||||
|
marginBottom: 20,
|
||||||
|
color: MainColor.white,
|
||||||
|
},
|
||||||
|
alertButtons: {
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
width: "100%",
|
||||||
|
},
|
||||||
|
alertButton: {
|
||||||
|
flex: 1,
|
||||||
|
padding: 10,
|
||||||
|
borderRadius: 5,
|
||||||
|
marginHorizontal: 5,
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
leftButton: {
|
||||||
|
backgroundColor: "gray",
|
||||||
|
},
|
||||||
|
rightButton: {
|
||||||
|
backgroundColor: MainColor.green,
|
||||||
|
},
|
||||||
|
buttonText: {
|
||||||
|
color: "white",
|
||||||
|
fontWeight: "bold",
|
||||||
|
},
|
||||||
|
});
|
||||||
150
components/Drawer/DrawerCustom.tsx
Normal file
150
components/Drawer/DrawerCustom.tsx
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import React, { useRef } from "react";
|
||||||
|
import {
|
||||||
|
Animated,
|
||||||
|
PanResponder,
|
||||||
|
StyleSheet,
|
||||||
|
View
|
||||||
|
} from "react-native";
|
||||||
|
|
||||||
|
import { AccentColor, MainColor } from "@/constants/color-palet";
|
||||||
|
import { DRAWER_HEIGHT } from "@/constants/constans-value";
|
||||||
|
|
||||||
|
interface DrawerCustomProps {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
height?: number;
|
||||||
|
isVisible: boolean;
|
||||||
|
drawerAnim: Animated.Value;
|
||||||
|
closeDrawer: () => void;
|
||||||
|
// openLogoutAlert: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DrawerCustom({
|
||||||
|
children,
|
||||||
|
height,
|
||||||
|
isVisible,
|
||||||
|
drawerAnim,
|
||||||
|
closeDrawer,
|
||||||
|
}: // openLogoutAlert,
|
||||||
|
DrawerCustomProps) {
|
||||||
|
const panResponder = useRef(
|
||||||
|
PanResponder.create({
|
||||||
|
onMoveShouldSetPanResponder: (_, gestureState) => {
|
||||||
|
return gestureState.dy > 10; // gesek ke bawah
|
||||||
|
},
|
||||||
|
onPanResponderMove: (_, gestureState) => {
|
||||||
|
const offset = gestureState.dy;
|
||||||
|
if (offset >= 0 && offset <= DRAWER_HEIGHT) {
|
||||||
|
drawerAnim.setValue(offset);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onPanResponderRelease: (_, gestureState) => {
|
||||||
|
if (gestureState.dy > 200) {
|
||||||
|
closeDrawer();
|
||||||
|
} else {
|
||||||
|
Animated.spring(drawerAnim, {
|
||||||
|
toValue: 0,
|
||||||
|
useNativeDriver: true,
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).current;
|
||||||
|
|
||||||
|
if (!isVisible) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* Overlay Gelap */}
|
||||||
|
<View
|
||||||
|
style={styles.overlay}
|
||||||
|
pointerEvents="auto"
|
||||||
|
onTouchStart={closeDrawer}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Custom Bottom Drawer */}
|
||||||
|
<Animated.View
|
||||||
|
style={[
|
||||||
|
styles.drawer,
|
||||||
|
{
|
||||||
|
height: height || DRAWER_HEIGHT,
|
||||||
|
transform: [{ translateY: drawerAnim }],
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
{...panResponder.panHandlers}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={[styles.headerBar, { backgroundColor: MainColor.white }]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{children}
|
||||||
|
|
||||||
|
{/* <TouchableOpacity
|
||||||
|
style={styles.menuItem}
|
||||||
|
onPress={() => {
|
||||||
|
alert("Pilihan 1 diklik");
|
||||||
|
closeDrawer();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text>Menu Item 1</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
|
||||||
|
<TouchableOpacity
|
||||||
|
style={styles.menuItem}
|
||||||
|
onPress={() => {
|
||||||
|
alert("Pilihan 2 diklik");
|
||||||
|
closeDrawer();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text>Menu Item 2</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
|
||||||
|
|
||||||
|
<TouchableOpacity
|
||||||
|
style={styles.menuItem}
|
||||||
|
onPress={() => alert("Logout via Alert bawaan")}
|
||||||
|
>
|
||||||
|
<Text style={{ color: "red" }}>Keluar</Text>
|
||||||
|
</TouchableOpacity> */}
|
||||||
|
</Animated.View>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
overlay: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
backgroundColor: "black",
|
||||||
|
opacity: 0.6,
|
||||||
|
zIndex: 998,
|
||||||
|
},
|
||||||
|
drawer: {
|
||||||
|
position: "absolute",
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
backgroundColor: AccentColor.darkblue,
|
||||||
|
borderTopLeftRadius: 20,
|
||||||
|
borderTopRightRadius: 20,
|
||||||
|
padding: 20,
|
||||||
|
shadowColor: "#000",
|
||||||
|
shadowOffset: { width: 0, height: -2 },
|
||||||
|
shadowOpacity: 0.2,
|
||||||
|
elevation: 5,
|
||||||
|
zIndex: 999,
|
||||||
|
},
|
||||||
|
headerBar: {
|
||||||
|
width: 40,
|
||||||
|
height: 5,
|
||||||
|
backgroundColor: MainColor.white,
|
||||||
|
borderRadius: 5,
|
||||||
|
alignSelf: "center",
|
||||||
|
marginVertical: 10,
|
||||||
|
},
|
||||||
|
menuItem: {
|
||||||
|
padding: 15,
|
||||||
|
},
|
||||||
|
});
|
||||||
57
components/Drawer/MenuDrawerDynamicGird.tsx
Normal file
57
components/Drawer/MenuDrawerDynamicGird.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import { AccentColor, MainColor } from "@/constants/color-palet";
|
||||||
|
import { ICON_SIZE_MEDIUM, TEXT_SIZE_SMALL } from "@/constants/constans-value";
|
||||||
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
|
import { View, TouchableOpacity, Text, StyleSheet } from "react-native";
|
||||||
|
|
||||||
|
const MenuDrawerDynamicGrid = ({ data, columns = 3, onPressItem }: any) => {
|
||||||
|
const numColumns = columns;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
{data.map((item: any, index: any) => (
|
||||||
|
<TouchableOpacity
|
||||||
|
key={index}
|
||||||
|
style={[styles.itemContainer, { flexBasis: `${100 / numColumns}%` }]}
|
||||||
|
onPress={() => onPressItem?.(item)}
|
||||||
|
>
|
||||||
|
<View style={styles.iconContainer}>
|
||||||
|
<Ionicons
|
||||||
|
name={item.icon}
|
||||||
|
size={ICON_SIZE_MEDIUM}
|
||||||
|
color={item.color || MainColor.white}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<Text style={styles.label}>{item.label}</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MenuDrawerDynamicGrid;
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flexDirection: "row",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
padding: 0,
|
||||||
|
},
|
||||||
|
itemContainer: {
|
||||||
|
padding: 10,
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
iconContainer: {
|
||||||
|
width: 56,
|
||||||
|
height: 56,
|
||||||
|
borderRadius: 28,
|
||||||
|
backgroundColor: AccentColor.blue,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
marginTop: 10,
|
||||||
|
fontSize: TEXT_SIZE_SMALL,
|
||||||
|
textAlign: "center",
|
||||||
|
color: MainColor.white,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Href } from "expo-router";
|
import { Href } from "expo-router";
|
||||||
|
|
||||||
export { ICustomTab, ITabs };
|
export { ICustomTab, ITabs, IMenuDrawerItem };
|
||||||
|
|
||||||
interface ICustomTab {
|
interface ICustomTab {
|
||||||
icon: string;
|
icon: string;
|
||||||
@@ -18,3 +18,10 @@ interface ITabs {
|
|||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IMenuDrawerItem {
|
||||||
|
icon: string;
|
||||||
|
label: string;
|
||||||
|
path?: string;
|
||||||
|
color?: string;
|
||||||
|
}
|
||||||
|
|||||||
15
constants/constans-value.ts
Normal file
15
constants/constans-value.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export {
|
||||||
|
TEXT_SIZE_SMALL,
|
||||||
|
TEXT_SIZE_MEDIUM,
|
||||||
|
TEXT_SIZE_LARGE,
|
||||||
|
ICON_SIZE_SMALL,
|
||||||
|
ICON_SIZE_MEDIUM,
|
||||||
|
DRAWER_HEIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
|
const TEXT_SIZE_SMALL = 12;
|
||||||
|
const TEXT_SIZE_MEDIUM = 14;
|
||||||
|
const TEXT_SIZE_LARGE = 16;
|
||||||
|
const ICON_SIZE_SMALL = 20;
|
||||||
|
const ICON_SIZE_MEDIUM = 24;
|
||||||
|
const DRAWER_HEIGHT = 500; // tinggi drawer5
|
||||||
1
eas.build.android
Normal file
1
eas.build.android
Normal file
@@ -0,0 +1 @@
|
|||||||
|
eas build --profile preview
|
||||||
7
eas.json
7
eas.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"cli": {
|
"cli": {
|
||||||
"version": ">= 16.12.0",
|
"version": ">= 16.10.0",
|
||||||
"appVersionSource": "remote"
|
"appVersionSource": "remote"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
@@ -9,7 +9,10 @@
|
|||||||
"distribution": "internal"
|
"distribution": "internal"
|
||||||
},
|
},
|
||||||
"preview": {
|
"preview": {
|
||||||
"distribution": "internal"
|
"distribution": "internal",
|
||||||
|
"android": {
|
||||||
|
"buildType": "apk"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"production": {
|
"production": {
|
||||||
"autoIncrement": true
|
"autoIncrement": true
|
||||||
|
|||||||
31
screens/Profile/menuDrawerSection.tsx
Normal file
31
screens/Profile/menuDrawerSection.tsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { IMenuDrawerItem } from "@/components/_Interface/types";
|
||||||
|
import MenuDrawerDynamicGrid from "@/components/Drawer/MenuDrawerDynamicGird";
|
||||||
|
import { router } from "expo-router";
|
||||||
|
|
||||||
|
export default function Profile_MenuDrawerSection({
|
||||||
|
drawerItems,
|
||||||
|
setShowLogoutAlert,
|
||||||
|
}: {
|
||||||
|
drawerItems: IMenuDrawerItem[];
|
||||||
|
setShowLogoutAlert: (value: boolean) => void;
|
||||||
|
}) {
|
||||||
|
const handlePress = (item: IMenuDrawerItem) => {
|
||||||
|
if (item.label === "Keluar") {
|
||||||
|
// console.log("Logout clicked");
|
||||||
|
setShowLogoutAlert(true);
|
||||||
|
} else {
|
||||||
|
router.push(item.path as any);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* Menu Items */}
|
||||||
|
<MenuDrawerDynamicGrid
|
||||||
|
data={drawerItems}
|
||||||
|
columns={4} // Ubah ke 2 jika ingin 2 kolom per baris
|
||||||
|
onPressItem={handlePress}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user