-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added onComplete callback to Router.navigate
- Loading branch information
Showing
16 changed files
with
362 additions
and
227 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
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
17 changes: 17 additions & 0 deletions
17
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/RouterStackExt.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,17 @@ | ||
package com.arkivanov.decompose.router | ||
|
||
internal val <C : Any> RouterStack<C, *>.configurationBackStack: List<C> | ||
get() = | ||
object : AbstractList<C>() { | ||
override val size: Int get() = backStack.size | ||
|
||
override fun get(index: Int): C = backStack[index].configuration | ||
} | ||
|
||
internal val <C : Any> RouterStack<C, *>.configurationStack: List<C> | ||
get() = | ||
object : AbstractList<C>() { | ||
override val size: Int get() = backStack.size + 1 | ||
|
||
override fun get(index: Int): C = (backStack.getOrNull(index) ?: active).configuration | ||
} |
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
54 changes: 54 additions & 0 deletions
54
decompose/src/commonTest/kotlin/com/arkivanov/decompose/router/RouterPopTest.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,54 @@ | ||
package com.arkivanov.decompose.router | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
@Suppress("TestFunctionName") | ||
class RouterPopTest { | ||
|
||
@Test | ||
fun GIVEN_stack_size_2_WHEN_pop_THEN_popped() { | ||
val router = TestRouter(listOf(Config.A, Config.B)) | ||
|
||
router.pop() | ||
|
||
assertEquals(listOf(Config.A), router.stack) | ||
} | ||
|
||
@Test | ||
fun GIVEN_stack_size_2_WHEN_pop_THEN_onComplete_success() { | ||
val router = TestRouter(listOf(Config.A, Config.B)) | ||
var isSuccess = false | ||
|
||
router.pop { isSuccess = it } | ||
|
||
assertTrue(isSuccess) | ||
} | ||
|
||
@Test | ||
fun GIVEN_stack_size_1_WHEN_pop_THEN_not_popped() { | ||
val router = TestRouter(listOf(Config.A)) | ||
|
||
router.pop() | ||
|
||
assertEquals(listOf(Config.A), router.stack) | ||
} | ||
|
||
|
||
@Test | ||
fun GIVEN_stack_size_1_WHEN_pop_THEN_onComplete_not_success() { | ||
val router = TestRouter(listOf(Config.A)) | ||
var isSuccess = true | ||
|
||
router.pop { isSuccess = it } | ||
|
||
assertFalse(isSuccess) | ||
} | ||
|
||
private sealed class Config { | ||
object A : Config() | ||
object B : Config() | ||
} | ||
} |
Oops, something went wrong.