Skip to content

Commit

Permalink
#3 added navigation routing
Browse files Browse the repository at this point in the history
  • Loading branch information
nastix123 committed Jul 14, 2024
1 parent dc503d7 commit 2469af7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 23 deletions.
32 changes: 9 additions & 23 deletions android/app/src/main/java/by/eapp/musicroom/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,30 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.rememberNavController
import by.eapp.musicroom.navigation.NavHostController
import by.eapp.musicroom.screens.test.TestScreen
import by.eapp.musicroom.screens.test.TestViewModel
import by.eapp.musicroom.ui.theme.MusicRoomTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
MusicRoomTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Greeting(
name = "Android",
modifier = Modifier.padding(innerPadding)
)
}
}
val navController = rememberNavController()
NavHostController(navController = navController)
}
}
}

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

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
MusicRoomTheme {
Greeting("Android")
}
}
59 changes: 59 additions & 0 deletions android/app/src/main/java/by/eapp/musicroom/navigation/NavHost.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package by.eapp.musicroom.navigation


import RegistrationScreen
import androidx.compose.animation.AnimatedContentScope

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import by.eapp.musicroom.screens.login.LoginScreen

@Composable
fun NavHostController(
navController: NavHostController,
) {
NavHost(
navController = navController,
startDestination = Screens.RegistrationScreen.route
) {
composable(
route = Screens.RegistrationScreen.route,
enterTransition = {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Left,
animationSpec = tween(
durationMillis = 500,
easing = LinearOutSlowInEasing
)
)
},

) {
RegistrationScreen(navController = navController)
}
composable(
route = Screens.LoginScreen.route,
enterTransition = {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Right,
animationSpec = tween(
durationMillis = 500,
easing = LinearOutSlowInEasing
)
)
},

) {
LoginScreen(navController = navController)
}
composable(route = Screens.MainScreen.route) {
// MainScreen(navController = navController)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package by.eapp.musicroom.navigation

sealed class Screens(
val route: String
) {
data object RegistrationScreen: Screens("registration")
data object LoginScreen: Screens("login")
data object MainScreen: Screens("main")
}

0 comments on commit 2469af7

Please sign in to comment.