Closed tgyuuAn closed 6 months ago
closed #3
1-1. BottomBarState๋ฅผ remember๋ก ์ ์ฅ ํด๋๋๋ค.
(์ด๋ฒ ํ๋ก์ ํธ์ ๊ฒฝ์ฐ AuthScreen์ด ์ฒซ ๋ฒ์งธ์ธ๋ฐ, BottomNavigation์ด ์๋ณด์ด๋ ๊ฒ์ผ๋ก ์์ํ๋ฏ๋ก false๋ก ์ค์ )
var bottomBarState by rememberSaveable { mutableStateOf(false) }
1-2. BottomNavigation์ AnimatedVisibility๋ก ๊ฐ์ธ์ค๋ค.
์ด๊ฑด ๋์ค์ https://github.com/tgyuuAn/Baekyoung-i/issues/9#issuecomment-1838824814 ๋ก ๋ง์ด๊ทธ๋ ์ด์ ๋์๋ค.
๋ฐ ๋ถ๋ถ ๋ด๋ ๋๊ณ ์ ๋ด๋ ๋๊ณ ..
์ฌ๊ธฐ์ visible = bottomBarState๋ฅผ ๋ฃ์ด์ค.
visible = bottomBarState
AnimatedVisibility( visible = bottomBarState, enter = slideInVertically(initialOffsetY = { it }), exit = slideOutVertically(targetOffsetY = { it }), content = { BottomNavigation( backgroundColor = BaekyoungTheme.colors.white, modifier = modifier ) { TopLevelDestination.entries.forEach { destination -> val isSelect = currentRoute == destination.route BottomNavigationItem( selected = isSelect, onClick = { onNavigateToDestination(destination) }, icon = { destination.selectedIcon }, selectedContentColor = BaekyoungTheme.colors.blueFF, unselectedContentColor = BaekyoungTheme.colors.gray95, label = { Text( text = stringResource(id = destination.titleTextId), style = BaekyoungTheme.typography.labelNormal, color = if (isSelect) BaekyoungTheme.colors.blueFF else BaekyoungTheme.colors.gray95 ) } ) } } } )
์ ๋๋ฉ์ด์ ์์ ์ ์ ์ฌ๋ฐ๋ ์ ๋๋ฉ์ด์ ์ด ๋ง๋๋ผ. ๋์ค์ ๊ณต๋ถํด์ผ๊ฒ ๋ค.
์๋ ์ฒ๋ผ ๊ฐ ๋ชจ๋ ํน์ ํจํค์ง์
navigation์ด๋ผ๋ ํจํค์ง๋ฅผ ๋ง๋ค์ด์,
MainNavigation (app ๋ชจ๋ ํน์ MainActivity) ์์ ํด๋น ๋ค๋น๊ฒ์ด์ ๊ทธ๋ํ์ ์ ๊ทผํ ์ ์๋๋ก
NavGraphBuilder.authScreen() ์ฒ๋ผ ํ์ฅ ํจ์๋ฅผ ๋ง๋ค์ด์ค๋ค.
NavGraphBuilder.authScreen()
์ด ๋, ํด๋น ๋ชจ๋ ํน์ ํจํค์ง๋ก ํฅํ ์ ์๊ฒ ํ๋ navigateToAuth() ๋ ํด๋น ๋ชจ๋ ํน์ ํจํค์ง์์ ์ ๊ณตํ๋ค.
navigateToAuth()
ํด๋น ํจ์์์ ๋ฐ๋ก AuthScreen()์ ๋์์ค ์๋ ์์ง๋ง,
AuthScreen()
AuthRoute()๋ผ๋ ๋ํ ํจ์๋ฅผ ๋ง๋ค์ด์, ํด๋น ๋ค๋น๊ฒ์ด์ ๋ด๋ถ์ ๋์์ค ํ๋ฉด์ ์ฝ๊ฒ ๊ฐ์ ๋ผ์ธ ์ ์๋๋ก ํ๋ค. (์ด๊ฑด ์ ํ์ฌํญ์ด๋ค.)
AuthRoute()
const val authNavigationRoute = "auth_route" fun NavController.navigateToAuth(navOptions: NavOptions?) { this.navigate(authNavigationRoute, navOptions) } fun NavGraphBuilder.authScreen() { composable(route = authNavigationRoute) { AuthRoute() } } @Composable internal fun AuthRoute() { var id by remember { mutableStateOf("") } var password by remember { mutableStateOf("") } val idChanged: (String) -> Unit = { textValue -> id = textValue } val passwordChanged: (String) -> Unit = { textValue -> password = textValue } AuthScreen( id = id, password = password, idChanged = idChanged, passwordChanged = passwordChanged, ) }
์ฐธ๊ณ :
NowInAndroid Github
Best Practices for Compose Navigation in Multi-Module Project
1. ๐ ๊ด๋ จ๋ ์ด์ ๋ฐ ์๊ฐ
closed #3
2. ๐ฅ๋ณ๊ฒฝ๋ ์
3. ๐ธ ์คํฌ๋ฆฐ์ท(์ ํ)
4. ๐ก์๊ฒ๋ ํน์ ๊ถ๊ธํ ์ฌํญ๋ค
1. ๐๏ธ BottomNavigation VIsibiliy ๋ก์ง
1-1. BottomBarState๋ฅผ remember๋ก ์ ์ฅ ํด๋๋๋ค.
(์ด๋ฒ ํ๋ก์ ํธ์ ๊ฒฝ์ฐ AuthScreen์ด ์ฒซ ๋ฒ์งธ์ธ๋ฐ, BottomNavigation์ด ์๋ณด์ด๋ ๊ฒ์ผ๋ก ์์ํ๋ฏ๋ก false๋ก ์ค์ )
1-2. BottomNavigation์ AnimatedVisibility๋ก ๊ฐ์ธ์ค๋ค.
์ด๊ฑด ๋์ค์ https://github.com/tgyuuAn/Baekyoung-i/issues/9#issuecomment-1838824814 ๋ก ๋ง์ด๊ทธ๋ ์ด์ ๋์๋ค.
๋ฐ ๋ถ๋ถ ๋ด๋ ๋๊ณ ์ ๋ด๋ ๋๊ณ ..
์ฌ๊ธฐ์
visible = bottomBarState
๋ฅผ ๋ฃ์ด์ค.์ ๋๋ฉ์ด์ ์์ ์ ์ ์ฌ๋ฐ๋ ์ ๋๋ฉ์ด์ ์ด ๋ง๋๋ผ. ๋์ค์ ๊ณต๋ถํด์ผ๊ฒ ๋ค.
2. ๐ ๋ค์ค Package ํน์ ๋ค์ค Module์์ Navigation ๊ด๋ฆฌ๋ฐฉ๋ฒ.
์๋ ์ฒ๋ผ ๊ฐ ๋ชจ๋ ํน์ ํจํค์ง์
navigation์ด๋ผ๋ ํจํค์ง๋ฅผ ๋ง๋ค์ด์,
MainNavigation (app ๋ชจ๋ ํน์ MainActivity) ์์ ํด๋น ๋ค๋น๊ฒ์ด์ ๊ทธ๋ํ์ ์ ๊ทผํ ์ ์๋๋ก
NavGraphBuilder.authScreen()
์ฒ๋ผ ํ์ฅ ํจ์๋ฅผ ๋ง๋ค์ด์ค๋ค.์ด ๋, ํด๋น ๋ชจ๋ ํน์ ํจํค์ง๋ก ํฅํ ์ ์๊ฒ ํ๋
navigateToAuth()
๋ ํด๋น ๋ชจ๋ ํน์ ํจํค์ง์์ ์ ๊ณตํ๋ค.ํด๋น ํจ์์์ ๋ฐ๋ก
AuthScreen()
์ ๋์์ค ์๋ ์์ง๋ง,AuthRoute()
๋ผ๋ ๋ํ ํจ์๋ฅผ ๋ง๋ค์ด์, ํด๋น ๋ค๋น๊ฒ์ด์ ๋ด๋ถ์ ๋์์ค ํ๋ฉด์ ์ฝ๊ฒ ๊ฐ์ ๋ผ์ธ ์ ์๋๋ก ํ๋ค. (์ด๊ฑด ์ ํ์ฌํญ์ด๋ค.)์ฐธ๊ณ :
NowInAndroid Github
Best Practices for Compose Navigation in Multi-Module Project