-
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.
Merge pull request #84 from stslex/dev
refactor Navigation
- Loading branch information
Showing
42 changed files
with
273 additions
and
357 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
11 changes: 9 additions & 2 deletions
11
app/src/main/java/st/slex/csplashscreen/ui/InitialAppViewModel.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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package st.slex.csplashscreen.ui | ||
|
||
import androidx.lifecycle.ViewModel | ||
import st.slex.csplashscreen.core.navigation.Screen | ||
import st.slex.csplashscreen.core.navigation.navigator.NavigationTarget | ||
import st.slex.csplashscreen.core.navigation.navigator.Navigator | ||
import st.slex.csplashscreen.core.navigation.navigator.NavigatorOptions | ||
|
||
class InitialAppViewModel( | ||
private val navigator: Navigator | ||
) : ViewModel() { | ||
|
||
fun navigate(screen: NavigationTarget.Screen) { | ||
navigator.navigate(screen) | ||
fun navigate(screen: Screen) { | ||
navigator( | ||
NavigationTarget.Screen( | ||
screen = screen, | ||
options = NavigatorOptions(isSingleTop = true) | ||
), | ||
) | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
plugins { | ||
id("csplashscreen.android.library") | ||
alias(libs.plugins.convention.library) | ||
alias(libs.plugins.convention.library.compose) | ||
alias(libs.plugins.serialization) | ||
} | ||
|
||
dependencies { | ||
implementation(project(":core:core")) | ||
api(libs.androidx.compose.navigation) | ||
implementation(libs.kotlinx.serialization.json) | ||
} | ||
|
||
android.namespace = "st.slex.csplashscreen.core.navigation" |
34 changes: 0 additions & 34 deletions
34
core/navigation/src/main/java/st/slex/csplashscreen/core/navigation/AppArguments.kt
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
core/navigation/src/main/java/st/slex/csplashscreen/core/navigation/AppDestination.kt
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
core/navigation/src/main/java/st/slex/csplashscreen/core/navigation/Screen.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,40 @@ | ||
package st.slex.csplashscreen.core.navigation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Stable | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.toRoute | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@Stable | ||
sealed interface Screen { | ||
|
||
@Serializable | ||
data object Home : Screen | ||
|
||
@Serializable | ||
data class ImageDetailScreen(val imageId: String) : Screen | ||
|
||
@Serializable | ||
data class CollectionScreen(val collectionId: String) : Screen | ||
|
||
@Serializable | ||
data class SearchPhotosScreen(val query: String) : Screen | ||
|
||
@Serializable | ||
data class UserScreen(val username: String) : Screen | ||
|
||
@Serializable | ||
data object Favourite : Screen | ||
|
||
} | ||
|
||
inline fun <reified S : Screen> NavGraphBuilder.navScreen( | ||
noinline content: @Composable (S) -> Unit | ||
) { | ||
composable<S> { backStackEntry -> | ||
content(backStackEntry.toRoute()) | ||
} | ||
} |
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
Oops, something went wrong.