-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
243 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/spoony/spoony/presentation/explore/ExploreScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.spoony.spoony.presentation.explore | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.sp | ||
|
||
@Composable | ||
fun ExploreScreen() { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
Text( | ||
text = "Explore Screen", | ||
fontSize = 50.sp | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/spoony/spoony/presentation/main/MainNavigator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.spoony.spoony.presentation.main | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.navigation.NavDestination | ||
import androidx.navigation.NavDestination.Companion.hasRoute | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.currentBackStackEntryAsState | ||
import androidx.navigation.compose.rememberNavController | ||
import androidx.navigation.navOptions | ||
import com.spoony.spoony.core.navigation.Route | ||
import com.spoony.spoony.presentation.explore.navigation.navigateExplore | ||
import com.spoony.spoony.presentation.map.navigaion.Map | ||
import com.spoony.spoony.presentation.map.navigaion.navigateMap | ||
import com.spoony.spoony.presentation.register.navigation.navigateRegister | ||
|
||
class MainNavigator( | ||
val navController: NavHostController | ||
) { | ||
private val currentDestination: NavDestination? | ||
@Composable get() = navController | ||
.currentBackStackEntryAsState().value?.destination | ||
|
||
val startDestination = Map | ||
|
||
val currentTab: MainTab? | ||
@Composable get() = MainTab.find { tab -> | ||
currentDestination?.hasRoute(tab::class) == true | ||
} | ||
|
||
fun navigate(tab: MainTab) { | ||
val navOptions = navOptions { | ||
navController.currentDestination?.route?.let { | ||
popUpTo(it) { | ||
inclusive = true | ||
saveState = true | ||
} | ||
} | ||
launchSingleTop = true | ||
restoreState = true | ||
} | ||
|
||
when (tab) { | ||
MainTab.MAP -> navController.navigateMap(navOptions) | ||
MainTab.REGISTER -> navController.navigateRegister(navOptions) | ||
MainTab.EXPLORE -> navController.navigateExplore(navOptions) | ||
} | ||
} | ||
|
||
@Composable | ||
fun shouldShowBottomBar() = MainTab.contains { | ||
currentDestination?.hasRoute(it::class) == true | ||
} && (currentTab?.showBottomSheet ?: true) | ||
|
||
inline fun isCurrentDestination(destination: NavDestination): Boolean { | ||
return navController.currentDestination == destination | ||
} | ||
|
||
inline fun <reified T : Route> NavHostController.isCurrentDestination() = | ||
currentDestination?.hasRoute<T>() == true | ||
} | ||
|
||
@Composable | ||
fun rememberMainNavigator( | ||
navController: NavHostController = rememberNavController() | ||
): MainNavigator = remember(navController) { | ||
MainNavigator(navController) | ||
} |
76 changes: 76 additions & 0 deletions
76
app/src/main/java/com/spoony/spoony/presentation/main/MainScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.spoony.spoony.presentation.main | ||
|
||
import android.app.Activity | ||
import androidx.activity.compose.BackHandler | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableLongStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.navigation.compose.NavHost | ||
import com.spoony.spoony.presentation.explore.navigation.exploreNavGraph | ||
import com.spoony.spoony.presentation.main.component.MainBottomBar | ||
import com.spoony.spoony.presentation.map.navigaion.mapNavGraph | ||
import com.spoony.spoony.presentation.register.navigation.registerNavGraph | ||
import kotlinx.collections.immutable.toPersistentList | ||
|
||
@Composable | ||
fun MainScreen( | ||
navigator: MainNavigator = rememberMainNavigator() | ||
) { | ||
val context = LocalContext.current | ||
|
||
var backPressedTime by remember { | ||
mutableLongStateOf(0L) | ||
} | ||
|
||
BackHandler(enabled = true) { | ||
if (System.currentTimeMillis() - backPressedTime <= 2000L) { | ||
(context as Activity).finish() | ||
} else { | ||
// TODO: 스낵바 자리 | ||
} | ||
backPressedTime = System.currentTimeMillis() | ||
} | ||
|
||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
Scaffold( | ||
bottomBar = { | ||
MainBottomBar( | ||
visible = navigator.shouldShowBottomBar(), | ||
tabs = MainTab.entries.toPersistentList(), | ||
currentTab = navigator.currentTab, | ||
onTabSelected = { | ||
navigator.navigate(it) | ||
} | ||
) | ||
} | ||
) { innerPadding -> | ||
NavHost( | ||
navController = navigator.navController, | ||
startDestination = navigator.startDestination | ||
) { | ||
mapNavGraph() | ||
|
||
exploreNavGraph( | ||
paddingValues = innerPadding | ||
) | ||
|
||
registerNavGraph( | ||
paddingValues = innerPadding | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/spoony/spoony/presentation/map/MapScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.spoony.spoony.presentation.map | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.sp | ||
|
||
@Composable | ||
fun MapScreen() { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
Text( | ||
text = "Map Screen", | ||
fontSize = 50.sp | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/spoony/spoony/presentation/register/RegisterScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.spoony.spoony.presentation.register | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.sp | ||
|
||
@Composable | ||
fun RegisterScreen() { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
Text( | ||
text = "Register Screen", | ||
fontSize = 50.sp | ||
) | ||
} | ||
} |
Oops, something went wrong.