avatar
Published on

TIL๐Ÿ“š ์•ฑ๊ฐœ๋ฐœ ์Šคํ„ฐ๋”” - 3 week

Authors
  • avatar
    Name
    Haneul
    Twitter

TIL๐Ÿ“š ์•ฑ๊ฐœ๋ฐœ ์Šคํ„ฐ๋”” - 3 week

React Navigation ๐Ÿ”ฅ

react native ์•ฑ์˜ ๋„ค๋น„๊ฒŒ์ด์…˜ ๊ธฐ๋Šฅ๊ณผ ํžˆ์Šคํ† ๋ฆฌ๋ฅผ ๊ฐ„๋‹จํžˆ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

์„ค์น˜

yarn add @react-navigation/native
yarn add @react-navigation/stack

expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view

Stack Navigator ๐Ÿ“‘

์Šคํƒ ๋„ค๋น„๊ฒŒ์ด์…˜์€ ์ปดํฌ๋„ŒํŠธ์— ํŽ˜์ด์ง€ ๊ธฐ๋Šฅ์„ ๋ถ€์—ฌํ•ด์ฃผ๊ณ  ์ปดํฌ๋„ŒํŠธ์—์„œ ์ปดํฌ๋„ŒํŠธ๋กœ ์ด๋™, ์ฆ‰ ํŽ˜์ด์ง€ ์ด๋™์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ด์ค€๋‹ค.

<Stack.Navigator
            screenOptions={{
                headerStyle: {
                    backgroundColor: "black",
                    borderBottomColor: "black",
                    shadowColor: "black",
                    height:100
                },
                //ํ—ค๋”์˜ ํ…์ŠคํŠธ๋ฅผ ์™ผ์ชพ์— ๋‘˜์ง€ ๊ฐ€์šด๋ฐ์— ๋‘˜์ง€๋ฅผ ๊ฒฐ์ •
                headerTintColor: "#fff",
                headerBackTitleVisible: false
            }}
        >

            {/* name์— ํ•ด๋‹น ํ•˜๋Š” ๋ถ€๋ถ„์ด ํŽ˜์ด์ง€์˜ ํƒ€์ดํ‹€์ด ๋ฉ๋‹ˆ๋‹ค.*/}
            <Stack.Screen name="MainPage" component={MainPage}/>
            <Stack.Screen name="DetailPage" component={DetailPage}/>
        </Stack.Navigator>

ํŽ˜์ด์ง€ ์ด๋™

//ํ•ด๋‹น ํŽ˜์ด์ง€์˜ ์ œ๋ชฉ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Œ
navigation.setOptions({
   title:'๋‚˜๋งŒ์˜ ๊ฟ€ํŒ'
})

//Stack.screen์—์„œ name ์†์„ฑ์œผ๋กœ ์ •ํ•ด์ค€ ์ด๋ฆ„์„ ์ง€์ •ํ•ด์ฃผ๋ฉด ํ•ด๋‹น ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๋Š” ํ•จ์ˆ˜
navigation.navigate("DetailPage")

//name ์†์„ฑ์„ ์ „๋‹ฌํ•ด์ฃผ๊ณ , ๋‘ ๋ฒˆ์งธ ์ธ์ž๋กœ ๋”•์…”๋„ˆ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•ด์ฃผ๋ฉด, Detail ํŽ˜์ด์ง€์—์„œ
//๋‘๋ฒˆ์งธ ์ธ์ž๋กœ ์ „๋‹ฌ๋œ ๋”•์…”๋„ˆ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ route ๋”•์…”๋„ˆ๋ฆฌ๋กœ ๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ์Œ
navigation.navigate("DetailPage",{
  title: title
})

๊ณต์œ ํ•˜๊ธฐ (Share Contents) ๐Ÿ‘‰

import { Share } from 'react-native';

Share.share({
            message:`${tip.title} \n\n ${tip.desc} \n\n ${tip.image}`,
        });

์„ค์น˜

expo install expo-linking

์‚ฌ์šฉ

import * as Linking from 'expo-linking';

Linking.openURL("https://spartacodingclub.kr")

์ƒ๋‹จ status bar

์„ค์น˜

expo install expo-status-bar

์‚ฌ์šฉ

import { StatusBar } from 'expo-status-bar';

<StatusBar style="black" />

TIL โœ…

๋ฆฌ์•กํŠธ ๋„ค์ดํ‹ฐ๋ธŒ์—์„œ ํŽ˜์ด์ง€ ์ „ํ™˜์— ์‚ฌ์šฉ๋˜๋Š” ๋ฆฌ์•กํŠธ ๋„ค๋น„๊ฒŒ์ด์…˜์„ ํ•™์Šตํ–ˆ๋‹ค. ํŠนํžˆ ์Šคํƒ ๋„ค๋น„๊ฒŒ์ดํ„ฐ๋ฅผ ์ด์šฉํ•ด ํŽ˜์ด์ง€ ์ด๋™์„ ๊ตฌํ˜„ํ–ˆ๊ณ , ์ด ์™ธ์—๋„ ํƒญ ๋„ค๋น„๊ฒŒ์ดํ„ฐ๋„ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค.

expo์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ ์ค‘, ์™ธ๋ถ€ ๋งํฌ ์—ฐ๊ฒฐ, ์ƒ๋‹จ status bar๋ฅผ ์ปจํŠธ๋กคํ•  ์ˆ˜ ์žˆ๋‹ค. RN์—์„œ ์ œ๊ณตํ•˜๋Š” share ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€!

๋ณดํ†ต expo๋กœ ๊ฐœ๋ฐœํ•˜๋ฉด ํŽธํ•˜์ง€๋งŒ ios/android๋ฅผ ๋”ฐ๋กœ ์„ค์ •ํ•˜๊ธฐ ์–ด๋ ต๊ธฐ ๋•Œ๋ฌธ์— ์ปค์Šคํ…€ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋ ค๋ฉด react native cli๋กœ ์„ค์น˜ํ•˜๋ฉด ๋œ๋‹ค.


์ฐธ๊ณ  : ์ŠคํŒŒ๋ฅดํƒ€ ์ฝ”๋”ฉํด๋Ÿฝ, React Naitve, React Navigation, Expo API, Expo status bar