Skip to content

Commit

Permalink
Renamed NavStackDuplicateContentStrategy to StackDuplicateContentStra…
Browse files Browse the repository at this point in the history
…tegy
  • Loading branch information
chRyNaN committed Feb 27, 2022
1 parent d77e032 commit adf27c2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package com.chrynan.navigation.compose

import androidx.compose.runtime.Composable
import kotlinx.coroutines.flow.Flow
import com.chrynan.navigation.NavStackDuplicateContentStrategy
import com.chrynan.navigation.StackDuplicateContentStrategy
import com.chrynan.navigation.Navigator

@ExperimentalNavigationApi
Expand All @@ -29,7 +29,7 @@ interface ComposeNavigatorByContent<Key> : ComposeNavigator<Key> {
@Composable
fun goTo(
key: Key,
strategy: NavStackDuplicateContentStrategy,
strategy: StackDuplicateContentStrategy,
content: @Composable ComposeNavigationContentScope<Key>.() -> Unit
)

Expand All @@ -41,14 +41,14 @@ interface ComposeNavigatorByContent<Key> : ComposeNavigator<Key> {
@ExperimentalNavigationApi
@Composable
fun <Key> ComposeNavigatorByContent<Key>.goTo(key: Key, content: @Composable ComposeNavigationContentScope<Key>.() -> Unit) =
goTo(key = key, strategy = NavStackDuplicateContentStrategy.CLEAR_STACK, content = content)
goTo(key = key, strategy = StackDuplicateContentStrategy.CLEAR_STACK, content = content)

@ExperimentalNavigationApi
interface ComposeNavigatorByKey<Key> : ComposeNavigator<Key> {

fun goTo(
key: Key,
strategy: NavStackDuplicateContentStrategy
strategy: StackDuplicateContentStrategy
)

companion object
Expand All @@ -58,7 +58,7 @@ interface ComposeNavigatorByKey<Key> : ComposeNavigator<Key> {
@Suppress("unused")
@ExperimentalNavigationApi
fun <Key> ComposeNavigatorByKey<Key>.goTo(key: Key) =
goTo(key = key, strategy = NavStackDuplicateContentStrategy.CLEAR_STACK)
goTo(key = key, strategy = StackDuplicateContentStrategy.CLEAR_STACK)

@ExperimentalNavigationApi
interface ComposeStackNavigator<Key> : ComposeNavigator<Key> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.chrynan.navigation.compose

import androidx.compose.runtime.Composable
import com.chrynan.presentation.ViewModel
import com.chrynan.navigation.NavStackDuplicateContentStrategy
import com.chrynan.navigation.StackDuplicateContentStrategy
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filterNotNull
Expand Down Expand Up @@ -58,7 +58,7 @@ class ComposeNavigatorByContentViewModel<Context, Key> internal constructor(
@Composable
override fun goTo(
key: Key,
strategy: NavStackDuplicateContentStrategy,
strategy: StackDuplicateContentStrategy,
content: @Composable ComposeNavigationContentScope<Key>.() -> Unit
) {
val currentScope = this.currentContext
Expand All @@ -67,7 +67,7 @@ class ComposeNavigatorByContentViewModel<Context, Key> internal constructor(
// If we are already displaying this key on the current scoped stack, then return.
if (key == currentKeyStack.lastOrNull()) return

if (strategy == NavStackDuplicateContentStrategy.CLEAR_STACK && contents.containsKey(key)) {
if (strategy == StackDuplicateContentStrategy.CLEAR_STACK && contents.containsKey(key)) {
// Go Back to the content with the provided key using the updated content
var lastKey = currentKeyStack.lastOrNull()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.chrynan.navigation.compose

import androidx.compose.runtime.Composable
import com.chrynan.presentation.ViewModel
import com.chrynan.navigation.NavStackDuplicateContentStrategy
import com.chrynan.navigation.StackDuplicateContentStrategy
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filterNotNull
Expand Down Expand Up @@ -43,14 +43,14 @@ abstract class BaseComposeNavigatorByKeyViewModel<Context, Key, NavigationScope

private val scopedKeyStack = mutableMapOf(initialContext to mutableListOf(initialKey))

override fun goTo(key: Key, strategy: NavStackDuplicateContentStrategy) {
override fun goTo(key: Key, strategy: StackDuplicateContentStrategy) {
val currentScope = this.currentContext
val currentKeyStack = scopedKeyStack[currentScope] ?: mutableListOf()

// If we are already displaying this key on the current scoped stack, then return.
if (key == currentKeyStack.lastOrNull()) return

if (strategy == NavStackDuplicateContentStrategy.CLEAR_STACK && currentKeyStack.contains(key)) {
if (strategy == StackDuplicateContentStrategy.CLEAR_STACK && currentKeyStack.contains(key)) {
// Go Back to the content with the provided key using the updated content
var lastKey = currentKeyStack.lastOrNull()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.chrynan.navigation

@Suppress("unused")
enum class NavStackDuplicateContentStrategy {
enum class StackDuplicateContentStrategy {

CLEAR_STACK,
ADD_TO_STACK;
Expand Down

0 comments on commit adf27c2

Please sign in to comment.