Skip to content

Commit

Permalink
Feat : app 모듈에 feature 모듈 네비게이션 그래프 바인딩
Browse files Browse the repository at this point in the history
  • Loading branch information
DongChyeon committed Mar 31, 2024
1 parent 0f35c3e commit 0cc8396
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 50 deletions.
6 changes: 6 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ android {

dependencies {
implementation(projects.core.designsystem)
implementation(projects.core.common)
implementation(projects.feature.home)
implementation(projects.feature.bookmark)
implementation(projects.feature.newsdetail)
implementation(projects.feature.setting)

implementation(libs.androidx.appcompat)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.ui.tooling.preview)
}
8 changes: 0 additions & 8 deletions app/src/main/java/com/dev/briefing/BreifingNavHost.kt

This file was deleted.

41 changes: 41 additions & 0 deletions app/src/main/java/com/dev/briefing/BriefingApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.dev.briefing

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarData
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun BriefingApp(
appState: BriefingAppState = rememberBriefingAppState()
) {
Scaffold(
snackbarHost = {
SnackbarHost(
hostState = appState.snackbarHostState,
snackbar = { data: SnackbarData ->
Snackbar(
modifier = Modifier.padding(
bottom = 30.dp,
start = 20.dp,
end = 20.dp
)
) {
Text(text = data.visuals.message)
}
}
)
},
content = { innerPadding ->
BriefingNavHost(
modifier = Modifier.padding(innerPadding),
appState = appState
)
}
)
}
40 changes: 40 additions & 0 deletions app/src/main/java/com/dev/briefing/BriefingAppState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.dev.briefing

import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@Composable
fun rememberBriefingAppState(
navController: NavHostController = rememberNavController(),
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() },
scope: CoroutineScope = rememberCoroutineScope()
): BriefingAppState {
return remember {
BriefingAppState(
navController,
snackbarHostState,
scope
)
}
}

@Stable
class BriefingAppState(
val navController: NavHostController,
val snackbarHostState: SnackbarHostState,
val scope: CoroutineScope
) {
fun showSnackBar(message: String) {
scope.launch {
snackbarHostState.showSnackbar(message)
}
}
}
35 changes: 35 additions & 0 deletions app/src/main/java/com/dev/briefing/BriefingNavHost.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.dev.briefing

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import store.newsbriefing.app.feature.bookmark.bookmarkScreen
import store.newsbriefing.app.feature.home.homeRoute
import store.newsbriefing.app.feature.home.homeScreen
import store.newsbriefing.app.feature.newsdetail.newsDetailScreen
import store.newsbriefing.app.feature.setting.settingScreen

@Composable
fun BriefingNavHost(
modifier: Modifier = Modifier,
appState: BriefingAppState
) {
NavHost(
modifier = modifier,
navController = appState.navController,
startDestination = homeRoute
) {
homeScreen(
showSnackbar = appState::showSnackBar
)
bookmarkScreen(
showSnackbar = appState::showSnackBar
)
newsDetailScreen(
showSnackbar = appState::showSnackBar
)
settingScreen(
showSnackbar = appState::showSnackBar
)
}
}
23 changes: 1 addition & 22 deletions app/src/main/java/com/dev/briefing/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,8 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
BriefingTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
BriefingApp()
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
BriefingTheme {
Greeting("Android")
}
}
1 change: 1 addition & 0 deletions feature/bookmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.briefing.android.library)
alias(libs.plugins.briefing.android.feature)
alias(libs.plugins.briefing.android.library.compose)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ fun NavController.navigateToBookmark() {
navigate(bookmarkRoute)
}

fun NavGraphBuilder.bookmarkScreen() {
fun NavGraphBuilder.bookmarkScreen(
showSnackbar: (String) -> Unit
) {
composable(
route = bookmarkRoute
) {
BookmarkRoute()
BookmarkRoute(
showSnackbar = showSnackbar
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package store.newsbriefing.app.feature.bookmark
import androidx.compose.runtime.Composable

@Composable
internal fun BookmarkRoute() {
BookmarkScreen()
internal fun BookmarkRoute(
showSnackbar: (String) -> Unit
) {
BookmarkScreen(
showSnackbar = showSnackbar
)
}

@Composable
internal fun BookmarkScreen() {
internal fun BookmarkScreen(
showSnackbar: (String) -> Unit
) {

}
1 change: 1 addition & 0 deletions feature/home/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.briefing.android.library)
alias(libs.plugins.briefing.android.feature)
alias(libs.plugins.briefing.android.library.compose)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ fun NavController.navigateToHome() {
navigate(homeRoute)
}

fun NavGraphBuilder.homeScreen() {
fun NavGraphBuilder.homeScreen(
showSnackbar: (String) -> Unit
) {
composable(
route = homeRoute
) {
HomeRoute()
HomeRoute(
showSnackbar = showSnackbar
)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package store.newsbriefing.app.feature.home

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.navigation.NavHostController

@Composable
internal fun HomeRoute() {
HomeScreen()
internal fun HomeRoute(
showSnackbar: (String) -> Unit
) {
HomeScreen(
showSnackbar = showSnackbar
)
}

@Composable
internal fun HomeScreen() {
internal fun HomeScreen(
showSnackbar: (String) -> Unit
) {

}
1 change: 1 addition & 0 deletions feature/newsdetail/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.briefing.android.library)
alias(libs.plugins.briefing.android.feature)
alias(libs.plugins.briefing.android.library.compose)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ fun NavController.navigateToNewsDetail() {
navigate(NewsDetailRoute)
}

fun NavGraphBuilder.newsDetailScreen() {
fun NavGraphBuilder.newsDetailScreen(
showSnackbar: (String) -> Unit
) {
composable(
route = NewsDetailRoute
) {
NewsDetailRoute()
NewsDetailRoute(
showSnackbar = showSnackbar
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package store.newsbriefing.app.feature.newsdetail
import androidx.compose.runtime.Composable

@Composable
internal fun NewsDetailRoute() {
NewsDetailScreen()
internal fun NewsDetailRoute(
showSnackbar: (String) -> Unit
) {
NewsDetailScreen(
showSnackbar = showSnackbar
)
}

@Composable
internal fun NewsDetailScreen() {
internal fun NewsDetailScreen(
showSnackbar: (String) -> Unit
) {

}
1 change: 1 addition & 0 deletions feature/setting/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.briefing.android.library)
alias(libs.plugins.briefing.android.feature)
alias(libs.plugins.briefing.android.library.compose)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ fun NavController.navigateToSetting() {
navigate(settingRoute)
}

fun NavGraphBuilder.settingScreen() {
fun NavGraphBuilder.settingScreen(
showSnackbar: (String) -> Unit
) {
composable(
route = settingRoute
) {
SettingRoute()
SettingRoute(
showSnackbar = showSnackbar
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package store.newsbriefing.app.feature.setting
import androidx.compose.runtime.Composable

@Composable
internal fun SettingRoute() {
SettingScreen()
internal fun SettingRoute(
showSnackbar: (String) -> Unit
) {
SettingScreen(
showSnackbar = showSnackbar
)
}

@Composable
internal fun SettingScreen() {
internal fun SettingScreen(
showSnackbar: (String) -> Unit
) {

}

0 comments on commit 0cc8396

Please sign in to comment.