-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Navigation Components and Flow
- Loading branch information
Showing
36 changed files
with
721 additions
and
1,312 deletions.
There are no files selected for viewing
49 changes: 13 additions & 36 deletions
49
...tion-compose/src/androidMain/kotlin/com.chrynan.navigation.compose/AndroidNavContainer.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,49 +1,26 @@ | ||
package com.chrynan.navigation.compose | ||
|
||
import androidx.activity.compose.BackHandler | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.runtime.* | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.ui.Modifier | ||
import com.chrynan.navigation.ExperimentalNavigationApi | ||
import com.chrynan.navigation.NavigationContext | ||
import com.chrynan.navigation.NavigationDestination | ||
import com.chrynan.navigation.Navigator | ||
|
||
@Suppress("unused") | ||
@Composable | ||
@ExperimentalNavigationApi | ||
internal actual fun <Context, Key> InternalNavContainer( | ||
navigator: ComposeNavigatorByContentViewModel<Context, Key> | ||
fun <Destination : NavigationDestination, Context : NavigationContext<Destination>> NavContainer( | ||
navigator: Navigator<Destination, Context>, | ||
modifier: Modifier, | ||
content: @Composable ComposeNavigationScope.(context: Context, destination: Destination) -> Unit | ||
) { | ||
val contentKey = rememberSaveable(navigator.keySaver) { mutableStateOf(navigator.initialKey) } | ||
|
||
navigator.keyChanges.collectAsStateIn(state = contentKey) | ||
val context = navigator.state.currentContextAsState() | ||
val destination = navigator.state.currentDestinationAsState() | ||
|
||
val scope = object : ComposeNavigationContentScope<Context, Key> { | ||
|
||
override val navigator: ComposeNavigatorByContentViewModel<Context, Key> = navigator | ||
} | ||
|
||
Box { | ||
navigator.apply { | ||
scope.content(contentKey.value) | ||
} | ||
Box(modifier = modifier) { | ||
content(ComposeNavigationScope, context.value, destination.value) | ||
} | ||
|
||
BackHandler(enabled = navigator.canGoBack()) { navigator.goBack() } | ||
} | ||
|
||
@Composable | ||
@ExperimentalNavigationApi | ||
internal actual fun <Context, Key, NavigationScope : ComposeNavigationKeyScope<Context, Key>> InternalNavContainer( | ||
navigator: BaseComposeNavigatorByKeyViewModel<Context, Key, NavigationScope>, | ||
scope: NavigationScope | ||
) { | ||
val contentKey = rememberSaveable(navigator.keySaver) { mutableStateOf(navigator.initialKey) } | ||
|
||
navigator.keyChanges.collectAsStateIn(state = contentKey) | ||
|
||
Box { | ||
navigator.apply { | ||
scope.content(contentKey.value) | ||
} | ||
} | ||
|
||
BackHandler(enabled = navigator.canGoBack()) { navigator.goBack() } | ||
} |
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
46 changes: 0 additions & 46 deletions
46
.../src/commonMain/kotlin/com.chrynan.navigation.compose/ComposeNavigationIntentNavigator.kt
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
...on-compose/src/commonMain/kotlin/com.chrynan.navigation.compose/ComposeNavigationScope.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,36 +1,10 @@ | ||
package com.chrynan.navigation.compose | ||
|
||
import com.chrynan.navigation.ExperimentalNavigationApi | ||
import com.chrynan.navigation.NavigationIntent | ||
import com.chrynan.navigation.NavigationScope | ||
|
||
@ExperimentalNavigationApi | ||
interface ComposeNavigationScope : NavigationScope { | ||
|
||
companion object : ComposeNavigationScope | ||
} | ||
|
||
@ExperimentalNavigationApi | ||
interface ComposeNavigationKeyScope<Context, Key> : ComposeNavigationScope { | ||
|
||
val navigator: ComposeNavigatorByKey<Context, Key> | ||
|
||
companion object | ||
} | ||
|
||
@ExperimentalNavigationApi | ||
interface ComposeNavigationIntentScope<Context, Intent : NavigationIntent> : ComposeNavigationScope, | ||
ComposeNavigationKeyScope<Context, Intent> { | ||
|
||
override val navigator: ComposeNavigationIntentStackNavigatorByKey<Context, Intent> | ||
|
||
companion object | ||
} | ||
|
||
@ExperimentalNavigationApi | ||
interface ComposeNavigationContentScope<Context, Key> : ComposeNavigationScope { | ||
|
||
val navigator: ComposeNavigatorByContent<Context, Key> | ||
|
||
companion object | ||
} |
84 changes: 0 additions & 84 deletions
84
navigation-compose/src/commonMain/kotlin/com.chrynan.navigation.compose/ComposeNavigator.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.