Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anim replace root #304

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading