🍔 핵심 내용
🥑 Rooms(채팅 방 목록)와 Room(채팅 화면)을 꾸며 보자.
🍔 코드 리뷰
🥑 LoggedInNav.js
...
<Stack.Screen
name="Messages"
options={{ headerShown: false }}
component={MessagesNav}
/>
MessageNav 추가
🥑 MessagesNav.js
import React from "react";
import { Ionicons } from "@expo/vector-icons";
import { createStackNavigator } from "@react-navigation/stack";
import Room from "../screens/Room";
import Rooms from "../screens/Rooms";
const Stack = createStackNavigator();
export default function MessagesNav() {
return (
<Stack.Navigator
screenOptions={{
headerTintColor: "white",
headerBackTitleVisible: false,
headerStyle: {
borderBottomColor: "rgba(255, 255, 255, 0.3)",
shadowColor: "rgba(255, 255, 255, 0.3)",
backgroundColor: "black",
},
}}
>
<Stack.Screen
name="Rooms"
options={{
headerBackImage: ({ tintColor }) => (
<Ionicons color={tintColor} name="close" size={28} />
),
}}
component={Rooms}
/>
<Stack.Screen name="Room" component={Room} />
</Stack.Navigator>
);
}
1) Rooms 스택과, Room 스택을 만들었다.
🥑 Rooms.js
import { gql, useQuery } from "@apollo/client";
import React from "react";
import { FlatList, View } from "react-native";
import styled from "styled-components/native";
import RoomItem from "../components/rooms/RoomItem";
import ScreenLayout from "../components/ScreenLayout";
import { ROOM_FRAGMENT } from "../fragments";
import useMe from "../hooks/useMe";
const SEE_ROOMS_QUERY = gql`
query seeRooms {
seeRooms {
...RoomParts
}
}
${ROOM_FRAGMENT}
`;
export default function Rooms() {
const { data, loading } = useQuery(SEE_ROOMS_QUERY);
const renderItem = ({ item: room }) => <RoomItem {...room} />;
return (
<ScreenLayout loading={loading}>
<FlatList
ItemSeparatorComponent={
<View
style={{
width: "100%",
height: 1,
backgroundColor: "rgba(255, 255, 255, 0.2)",
}}
></View>
}
style={{ width: "100%" }}
data={data?.seeRooms}
keyExtractor={(room) => "" + room.id}
renderItem={renderItem}
/>
</ScreenLayout>
);
}
'코딩강의 > 인스타그램클론(expo-노마드코더)' 카테고리의 다른 글
DEPLOYMENT (0) | 2021.08.01 |
---|---|
Upload Photo (0) | 2021.07.22 |
LIKES, SEARCH AND PHOTO 화면 (0) | 2021.07.20 |
FEED (0) | 2021.07.07 |
AUTHENTICATION (0) | 2021.06.28 |