saya ingin menggabungkan koding 1 ke koding ke 2 mohon dapat dibantu, koding 1 import…
- User
saya ingin menggabungkan koding 1 ke koding ke 2 mohon dapat dibantu, koding 1 import React, { useRef, useState } from "react"; import { Animated, Image, SafeAreaView, StyleSheet, Text, TouchableOpacity, View, } from "react-native"; import profile from "../assets/icon/profile.png"; // Tab ICons... import notifications from "../assets/icon/bell.png"; import home from "../assets/icon/home.png"; import logout from "../assets/icon/logout.png"; import search from "../assets/icon/search.png"; import settings from "../assets/icon/settings.png"; // Menu import close from "../assets/icon/close.png"; import menu from "../assets/icon/menu.png";
// Photo import photo from "../assets/images/home/profile.jpg";
export default function DrawerScreen() { const [currentTab, setCurrentTab] = useState("Hi, Dimas Bagus Arya"); // 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 ( <View style={{ justifyContent: "flex-start", padding: 15 }}> <Image source={profile} style={{ width: 60, height: 60, borderRadius: 10, marginTop: 8, }} >
<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: -50, 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, }, ], }} > <View style={{ flexDirection: "row", justifyContent: "space-between", marginTop: 10, paddingLeft: 5, }} > <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: 22, fontWeight: "regular", color: "black", paddingTop: 80, }} > {currentTab} </Text> <Image source={photo} style={{ width: 52, height: 52, borderRadius: 50, marginTop: 70, }} ></Image> </View> <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> - Assistant
Untuk menggabungkan kedua kode yang ada, Anda bisa menggunakan komponen DrawerScreen dari koding 1, di dalam HomeScreen dari koding 2. Pertama, kita akan mengimpor
import DrawerScreen from './path/to/DrawerScreen'dan meletakkannya di dalamHomeScreen. Berikut ini adalah cara yang benar untuk menggabungkan kedua kode tersebut:import React from "react"; import { Image, ImageBackground, SafeAreaView, ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View, } from "react-native"; import DrawerScreen from './path/to/DrawerScreen'; // (...) const HomeScreen = ({ navigation }) => { const theme = useTheme(); return ( <SafeAreaView style={{ flex: 1, backgroundColor: "#22242C" }}> <DrawerScreen /> {/* Rest of the HomeScreen code */} </SafeAreaView> ); }; // (...)Namun, penggabungan ini mungkin tidak akan berfungsi dengan baik karena menggabungkan dua tata letak yang berbeda. Jadi, Anda mungkin perlu mengatur ulang beberapa elemen atau mengubah logika komponen Anda.
Selain itu, saya sarankan untuk menjelajahi Navigation Library seperti . Ini memungkinkan Anda untuk membuat navigasi yang lebih kompleks dan lebih mudah diatur antara tampilan Anda, seperti menggunakan DrawerNavigator atau createStackNavigator.