#1 ๊ฐ์
#1-1 Scaffold์ bottomBar
Nutri Capture ํ๋ก ํธ์๋ - Scaffold
#1 ๊ฐ์#1-1 ์ฒซ ์ฝ ๋จ๊ธฐ๋ฌด์๋ถํฐ ์์ ๋์ผํ ์ง ๊ฐ์ด ์กํ์ง ์๋๋ค. ํ๋กํ ํ์ดํ์ ํ๋ฒ ๋ ํด์ผ ํ๋? ์ํํธ์จ์ด ๋ชจ๋ธ๋ง์ด๋ผ๋ ๊ฑด ๋ญ์ง... ์ด๊ฑธ ๋จผ์ ๊ณต๋ถํด์ผํ ๊น? ... ์ฌ๋ฌ ์๋ฌธ์ด ๋ ๋ค. ๊ทธ
kenel.tistory.com
์ด์ ๊ฒ์๊ธ์์ Scaffold๋ฅผ ๋ง๋ค์๋ค. ํด๋น Scaffold์๋ ๋๋ถ๋ถ ์ฑ์ ์ ํ์ ์ธ ๊ตฌ์กฐ๋ก์ ํฌํจ๋๋ NavigationBar๋ฅผ ๋ฃ์ ๊ฒ์ด๋ค. ๊ทธ๋ฌ๊ธฐ ์ํด์ ๋จผ์ , NavHost๋ถํฐ ๋ง๋ค์ด๋ ํ์๊ฐ ์๋ค.
#1-2 NavHost ๊ตฌํ
[Android] Jetpack Compose - Navigation ๊ธฐ์ด
#1 ๊ฐ์#1-1 ์ ํต์ ์ธ ์๋๋ก์ด๋ ํ๋ก์ ํธ์์์ Navigation [Android] Navigation - ๊ธฐ์ด#1 ์ด์ ๊ธ [Android] Navigation - ํ๊ฒฝ ์ค์ #1 Navigation#1-1 ์กํฐ๋นํฐ ๋ฐ ํ๋๊ทธ๋จผํธ ๊ตฌ์ฑ์ ํธ๋ ๋์์ฆ ์๋๋ก์ด๋ ๊ฐ๋ฐ
kenel.tistory.com
์ ๊ฒ์๊ธ์ ๊ธฐ๋ฐํ์ฌ #2์ ์ฝ๋๋ฅผ ์์ฑํ๋ค.
#1-3 Destination ๊ตฌ์ฑ
1. NutrientInputScreen: ์ฌ์ฉ์๊ฐ ๋จน์ ์์์ ๋ํด ๊ธฐ๋กํ๋ ํ๋ฉด
2. StatisticsScreen: ์ง๊ธ๊น์ง ๊ธฐ๋กํ ์๋จ์ ๋ํ ํต๊ณ ํ๋ฉด
3. UserInfoScreen: ์ฌ์ฉ์ ์์ฒด์ ๋ํ ์ ๋ณด ํ๋ฉด
NavHost ๋ฐ NavigationBar๊ฐ ๋ณด์ ํ Destination์ 3๊ฐ์ง๋ก ์์ ํ๋ค. ๋์ค์ ๋ณ๊ฒฝ๋ ๊ฐ๋ฅ์ฑ๋ ์์ง๋ง, ํ์ฌ ์์ ์์ ๊ตฌํํ ๊ฒ์ด๋ผ๊ณ ์์๋๋ ํ๋ฉด์ด๋ค.
#2 ์ฝ๋
#2-1 ๋ชจ๋ ์์ค build.gradle.kt ๋ฐ lib.versions.toml ์์
plugins {
...
}
android {
...
}
dependencies {
...
// Navigation
implementation(libs.androidx.navigation.runtime.ktx)
implementation(libs.androidx.navigation.compose)
}
Jetpack Compose์ ๋ค๋น๊ฒ์ด์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ค.
[versions]
...
navigationRuntimeKtx = "2.8.1"
[libraries]
...
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationRuntimeKtx" }
androidx-navigation-runtime-ktx = { module = "androidx.navigation:navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" }
[plugins]
...
build.gradle์ ์ถ๊ฐํ๋ ๊ตฌ๋ฌธ์ ์๋๋ก์ด๋ ์ปดํ์ผ๋ฌ๊ฐ ํด์ํ ์ ์๋๋ก lib.versions.toml๋ ์์ ํ๋ค.
#2-2 Destination์ฉ @Composable 3๊ฐ ์์ฑ
// in NutrientInputScreen.kt
@Composable
fun NutrientInputScreen(
scope: CoroutineScope,
snackbarHostState: SnackbarHostState
) {
Column(
modifier = Modifier.fillMaxSize()
) {
SampleContent(
text = "NutrientInputScreen",
modifier = Modifier
.fillMaxSize()
.background(Color.LightGray),
scope = scope,
snackbarHostState = snackbarHostState
)
}
}
// in StatisticsScreen.kt
@Composable
fun StatisticsScreen(
scope: CoroutineScope,
snackbarHostState: SnackbarHostState
) {
Column(
modifier = Modifier.fillMaxSize()
) {
SampleContent(
text = "StatisticsScreen",
modifier = Modifier
.fillMaxSize()
.background(Color.LightGray),
scope = scope,
snackbarHostState = snackbarHostState
)
}
}
// in UserInfoScreen.kt
@Composable
fun UserInfoScreen(
scope: CoroutineScope,
snackbarHostState: SnackbarHostState
) {
Column(
modifier = Modifier.fillMaxSize()
) {
SampleContent(
text = "UserInfoScreen",
modifier = Modifier
.fillMaxSize()
.background(Color.LightGray),
scope = scope,
snackbarHostState = snackbarHostState
)
}
}
3๊ฐ์ ์ปดํฌ์ ๋ธ ํจ์๋ฅผ ๊ฐ๊ฐ ๋ณ๋์ ํ์ผ๋ก ๋ง๋ค์ด๋์๋ค. SampleContent()๋ MainActivity.kt์ ์ ์ํด๋์๋ ์ปดํฌ์ ๋ธ ํจ์๋ค.
#2-3 NavHost ํด๋์ค ๊ตฌํ ๋ฐ Scaffold์ content ์์ญ์ ๋๊ธฐ
...
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
NutricapturenewTheme {
// Navigation ๊ด๋ฆฌ์ ์ฃผ์ฒด
val navController = rememberNavController()
// Snackbar๋ฅผ ์ํ CoroutineScope์ State
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
Scaffold(
...
) { innerPadding ->
NavHost(
navController = navController,
startDestination = "nutrientInputScreen",
modifier = Modifier.padding(innerPadding)
) {
composable(route = "nutrientInputScreen") {
NutrientInputScreen(
scope = scope,
snackbarHostState = snackbarHostState
)
}
composable(route = "statisticsScreen") {
StatisticsScreen(
scope = scope,
snackbarHostState = snackbarHostState
)
}
composable(route = "userInfoScreen") {
UserInfoScreen(
scope = scope,
snackbarHostState = snackbarHostState
)
}
}
}
}
}
}
}
@Composable
fun SampleContent( ... ) { ... }
content ์์ญ์ ์๋ SampleContent()๋ฅผ ์ ๊ฑฐํ๊ณ , ๊ทธ ๋์ NavHost()๋ฅผ ์์น์์ผฐ๋ค. NavHost๊ฐ innerPadding์ ๊ณ ๋ คํ๊ฒ ๋์๊ณ , 3๊ฐ์ Destination์ ๊ฐ๊ฐ์ CoroutineScope ๋ฐ SnackbarHostState๋ฅผ ์ ๋ฌ(์์ฑ์ ์ฃผ์
)ํ๋ค.
#3 ์์ฝ
Destination์ฉ ์ปดํฌ์ ๋ธ ํจ์๋ฅผ 3๊ฐ์ NavHost๋ฅผ ๋ง๋ค์๋ค.
#4 ์์ฑ๋ ์ฑ
#4-1 ์คํฌ๋ฆฐ์ท
๊ฐ์ด๋ฐ์ ์๋ ๋ฒํผ์ ํ
์คํธ๋ง ์ ์ธํ๊ณ ์ด์ ๊ฒ์๊ธ๊ณผ ๋์ผํ ์คํฌ๋ฆฐ์ท์ด ๋์จ๋ค. ๋ด๋ถ ๊ตฌ์กฐ๋ง ๋ณํ ๊ฒ์ด๋ค.
#4-2 ์ด ๊ฒ์๊ธ ์์ ์ Commit
GitHub - Kanmanemone/nutri-capture-new
Contribute to Kanmanemone/nutri-capture-new development by creating an account on GitHub.
github.com
#4-3 ๋ณธ ํ๋ก์ ํธ์ ๊ฐ์ฅ ์ต์ Commit
GitHub - Kanmanemone/nutri-capture-new
Contribute to Kanmanemone/nutri-capture-new development by creating an account on GitHub.
github.com
'๊ฐ๋ฐ ์ผ์ง ๐ป > Nutri Capture' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Nutri Capture ๋ฐฉํฅ์ฑ - ๊ณ ์ ์ธ์ง๊ฐ๊ฐ, ์ UI ์ค์ผ์น (4) | 2024.10.03 |
---|---|
Nutri Capture ํ๋ก ํธ์๋ - NavigationBar (1) | 2024.09.28 |
Nutri Capture ํ๋ก ํธ์๋ - Scaffold (0) | 2024.09.25 |
Nutri Capture ๋ฐฉํฅ์ฑ - ์ด์๋จ๋ ์ฑ์ด ๋๋ ค๋ฉด (0) | 2024.09.22 |
Nutri Capture ๋ฐฉํฅ์ฑ - UI ์ค์ผ์น (0) | 2023.12.23 |