Skip to content

Commit

Permalink
Merge pull request #304 from hotwired/anim_replace_root
Browse files Browse the repository at this point in the history
Anim replace root
  • Loading branch information
jayohms authored Feb 23, 2024
2 parents 8556f9d + 092da82 commit 19c3c9c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
9 changes: 9 additions & 0 deletions turbo/src/main/assets/json/test-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
"presentation": "clear_all"
}
},
{
"patterns": [
"/new-home"
],
"properties": {
"uri": "turbo://fragment/web/home",
"presentation": "replace_root"
}
},
{
"patterns": [
"/feature"
Expand Down
6 changes: 6 additions & 0 deletions turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ internal class TurboNavRule(
if (newPresentation == TurboNavPresentation.REPLACE_ROOT && newDestination != null) {
return navOptions {
popUpTo(controller.graph.id) { inclusive = true }
anim {
enter = navOptions.enterAnim
exit = navOptions.exitAnim
popEnter = navOptions.popEnterAnim
popExit = navOptions.popExitAnim
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() {
assertThat(json).isNotNull()

val config = load(json)
assertThat(config?.rules?.size).isEqualTo(9)
assertThat(config?.rules?.size).isEqualTo(10)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TurboPathConfigurationTest : BaseRepositoryTest() {

@Test
fun assetConfigurationIsLoaded() {
assertThat(pathConfiguration.rules.size).isEqualTo(9)
assertThat(pathConfiguration.rules.size).isEqualTo(10)
}

@Test
Expand Down
27 changes: 27 additions & 0 deletions turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TurboNavRuleTest {
private lateinit var pathConfiguration: TurboPathConfiguration

private val homeUrl = "https://hotwired.dev/home"
private val newHomeUrl = "https://hotwired.dev/new-home"
private val featureUrl = "https://hotwired.dev/feature"
private val newUrl = "https://hotwired.dev/feature/new"
private val editUrl = "https://hotwired.dev/feature/edit"
Expand Down Expand Up @@ -143,6 +144,32 @@ class TurboNavRuleTest {
assertThat(rule.newNavOptions).isEqualTo(navOptions)
}

@Test
fun `replace root when navigating in default context`() {
controller.navigate(webDestinationId, locationArgs(featureUrl))
val rule = getNavigatorRule(newHomeUrl)

// Current destination
assertThat(rule.previousLocation).isEqualTo(homeUrl)
assertThat(rule.currentLocation).isEqualTo(featureUrl)
assertThat(rule.currentPresentationContext).isEqualTo(TurboNavPresentationContext.DEFAULT)
assertThat(rule.isAtStartDestination).isFalse()

// New destination
assertThat(rule.newLocation).isEqualTo(newHomeUrl)
assertThat(rule.newPresentationContext).isEqualTo(TurboNavPresentationContext.DEFAULT)
assertThat(rule.newPresentation).isEqualTo(TurboNavPresentation.REPLACE_ROOT)
assertThat(rule.newQueryStringPresentation).isEqualTo(TurboNavQueryStringPresentation.DEFAULT)
assertThat(rule.newNavigationMode).isEqualTo(TurboNavMode.IN_CONTEXT)
assertThat(rule.newModalResult).isNull()
assertThat(rule.newDestinationUri).isEqualTo(webHomeUri)
assertThat(rule.newDestination).isNotNull()
assertThat(rule.newNavOptions.enterAnim).isEqualTo(navOptions.enterAnim)
assertThat(rule.newNavOptions.exitAnim).isEqualTo(navOptions.exitAnim)
assertThat(rule.newNavOptions.popEnterAnim).isEqualTo(navOptions.popEnterAnim)
assertThat(rule.newNavOptions.popExitAnim).isEqualTo(navOptions.popExitAnim)
}

@Test
fun `navigate back to feature from modal context`() {
controller.navigate(webDestinationId, locationArgs(featureUrl))
Expand Down

0 comments on commit 19c3c9c

Please sign in to comment.