๐ @akalli/navigation react-native navigation์ ์๊ฐํฉ๋๋ค.
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]๋ก ์ฐ๋ฝํ ์ ์์ต๋๋ค.
๋ชจ๋ ๊ฐ์ฌํฉ๋๋ค. ์ฆ๊ฑฐ์ด ์ฝ๋ฉํ์ธ์.
Reference
์ด ๋ฌธ์ ์ ๊ดํ์ฌ(๐ @akalli/navigation react-native navigation์ ์๊ฐํฉ๋๋ค.), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://dev.to/danilosilvadev/introducing-akallinavigation-react-native-navigation-made-easy-52n1ํ ์คํธ๋ฅผ ์์ ๋กญ๊ฒ ๊ณต์ ํ๊ฑฐ๋ ๋ณต์ฌํ ์ ์์ต๋๋ค.ํ์ง๋ง ์ด ๋ฌธ์์ URL์ ์ฐธ์กฐ URL๋ก ๋จ๊ฒจ ๋์ญ์์ค.
์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ ์ธ ๋ฐ๊ฒฌ์ ์ ๋ (Collection and Share based on the CC Protocol.)
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค