๐ŸŽ‰ @akalli/navigation react-native navigation์„ ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค.

12649 ๋‹จ์–ด navigationreactnativereactjavascript
๊ฒฝ๋น„์›๊ณผ ๋„ˆ๋ฌด ๋งŽ์€ ๊ฒฝ๋กœ๋กœ ๋ณต์žกํ•œrouter ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐ ์ง€์น˜์…จ์Šต๋‹ˆ๊นŒ?

@akalli/navigation์€ ๊ฒฝ๋กœ ์ƒ์„ฑ, ์ธ์ฆ ํ๋ฆ„, ๋ฒˆ์—ญ ๋ฐ react-native ์•ฑ์šฉ ์„œ๋ž ๋ฉ”๋‰ด์™€ ๊ฐ™์€ ๊ฐ„๋‹จํ•œ ๊ฐœ์ฒด๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” NPM ํŒจํ‚ค์ง€์ž…๋‹ˆ๋‹ค.

์„ค์น˜


npm install @akalli/navigation react-native-svg @react-navigation/drawer @react-navigation/native @react-navigation/native-stack @react-navigation/stack @react-native-async-storage/async-storage

Disclaimer:
I know it looks a lot of installations, but most of them are @react-navigation stuff, it has async storage for translations and authentication, and react-native-svg for icons that are used in the drawer. Most of those probably you already use in your app.



๊ธฐ๋ณธ ์˜ˆ:




// Sample screens

export const Main = () => {
  return (
    <View style={styles.container}>
      <Text>I am the main another screen</Text>
    </View>
  );
};

export const Login = () => {
  return (
    <View style={styles.container}>
      <Text>I am the main another screen</Text>
    </View>
  );
};

export const AnotherScreen = () => {
  return (
    <View style={styles.container}>
      <Text>I am the main another screen</Text>
    </View>
  );
};

// Config base file

const routerConfig: IRouterProps = {
  appInitial: "Main", // Initial route
  screens: {
    MainScreens: {
      Main: Main,
    },
    AssistantScreens: {
      AnotherScreen: AnotherScreen,
    },
  },
};

// Router Provider
export default function App() {
  return <Router config={routerConfig} />;
}


๊ทธ๋ฆฌ๊ณ  ๊ทธ๊ฒŒ ๋‹ค์•ผ. ๊ทธ routerConfig๋งŒ ์žˆ์œผ๋ฉด ๋งˆ๋ฒ•์ฒ˜๋Ÿผ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•ฑ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ›„ํฌ



useNav - ๋‚ด๋น„๊ฒŒ์ด์…˜ ๊ธฐ๋Šฅ์„ ์œ„ํ•œ ๋‹จ์ถ•ํ‚ค.

const { navigate, routerState, routes, route, back, drawer } = useNav();


useDict - ๋ฒˆ์—ญ ๊ธฐ๋Šฅ์„ ์œ„ํ•ด ์ฃผ๋กœ ์‚ฌ์ „์— ์•ก์„ธ์Šคํ•˜์ง€๋งŒ ๋ฐฐํƒ€์ ์ด์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค.

const { lang, setLang, dict } = useDict("myModule");


useAuth - ์ธ์ฆ ํ—ฌํผ ๋ฐ ์ƒํƒœ.

This will only work if you wrap your app with



const {
  data: { tokens, user, isAuthenticated },
  actions: { setTokens, setUser, setIsAuthenticated, clearAuth },
} = useAuth();


๊ณ ๊ธ‰ ๋ชจ๋“œ



์ธ์ฆ ๋“ฑ์œผ๋กœ ๋” ๋ณต์žกํ•œ ๋ผ์šฐํŒ… ์†”๋ฃจ์…˜์„ ๊ด€๋ฆฌํ•˜๋ ค๋ฉด ๋จผ์ € ๋ผ์šฐํ„ฐ๋ฅผ AuthProvider๋กœ ๋ž˜ํ•‘ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ณ ๊ธ‰ ๊ตฌ์„ฑ ์˜ˆ:

const routerConfig: IRouterProps = {
  appInitialRoute: "Main", // Initial route
  authInitialRoute: "SignIn", // Auth initial route
  env: "prod", // authentication required to access app routes
  activeStack: "auth", // active stack, works only if not env = prod
  drawer: { // drawer props
    position: "left";
    bg: "#26a3c9",
    labelColor: "#e8d7cf",
    icons: {
      Main: MainScreenIcon,
      SignIn: SignScreenIcon,
      AnotherScreen: AnotherScreenIcon
    },
    CustomMenu: MyMenu // This option makes labelColor and icons be ignored because you have full control of the Menu component
  },
  defaultLanguage: 'es',
  dicts: { // dictionaries are the internationalization feature
    main: {
      en: {
        MY_TEXT: 'My text'
      },
      pt: {
        MY_TEXT: 'Meu texto'
      }
    }
  },
  bgs: { // background colors
    authStack: "#26a3c9",
    appStack: "#e8d7cf"
  },
  screens: {
    MainScreens: {
      Main: Main,
    },
    AssistantScreens: {
      AnotherScreen: AnotherScreen,
    },
    AuthScreens: {
      SignIn: SignIn,
    },
  },
};


์ด ํ”„๋กœ์ ํŠธ๋Š” ๋…๋ฆฝ์ ์ด์ง€๋งŒ npx์— ์‰ฝ๊ฒŒ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋Š” ํ›จ์”ฌ ๋” ํฐ ์—‘์Šคํฌ ํ…œํ”Œ๋ฆฟ ํŒจํ‚ค์ง€์˜ ์ผ๋ถ€์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

๋งŒ๋‚˜๋‹ค: @akalli/create-akalli-app

GitHub์˜ ๋ชจ๋“  ์˜คํ”ˆ ์†Œ์Šค์ž…๋‹ˆ๋‹ค. ์ฒดํฌ ์•„์›ƒํ•˜๊ณ  ์˜์‹ฌ์ด๋‚˜ ๋ฌธ์ œ๊ฐ€ ์žˆ์œผ๋ฉด ๋ฌธ์ œ๋ฅผ ๋งŒ๋“ค๊ฑฐ๋‚˜ ๋‚ด ์ด๋ฉ”์ผ[email protected]๋กœ ์—ฐ๋ฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋‘ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ฆ๊ฑฐ์šด ์ฝ”๋”ฉํ•˜์„ธ์š”.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ