Skip to content

Commit

Permalink
Merge pull request #75 from hotwired/navigation-animations
Browse files Browse the repository at this point in the history
Fix navigation animations - don't animate `replace` visits
  • Loading branch information
jayohms authored Dec 2, 2024
2 parents 83a61c5 + f2376fb commit 83528c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demo/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<style name="Widget.MyTheme.BottomSheet.Modal" parent="Widget.MaterialComponents.BottomSheet.Modal">
<item name="shapeAppearanceOverlay">?shapeAppearanceLargeComponent</item>
<item name="behavior_draggable">true</item>
<item name="behavior_peekHeight">600dp</item>
<item name="behavior_peekHeight">400dp</item>
<item name="backgroundTint">?colorSurface</item>
</style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import dev.hotwire.core.bridge.BridgeDestination
import dev.hotwire.core.config.Hotwire
import dev.hotwire.core.turbo.config.PathConfigurationProperties
import dev.hotwire.core.turbo.config.context
import dev.hotwire.core.turbo.config.presentation
import dev.hotwire.core.turbo.nav.Presentation
import dev.hotwire.core.turbo.nav.PresentationContext
import dev.hotwire.core.turbo.visit.VisitAction
import dev.hotwire.navigation.R
Expand Down Expand Up @@ -136,24 +138,38 @@ interface HotwireDestination : BridgeDestination {
action: VisitAction
): NavOptions {
val modal = newPathProperties.context == PresentationContext.MODAL
val replace = action == VisitAction.REPLACE
val clearAll = newPathProperties.presentation == Presentation.CLEAR_ALL
val animate = action != VisitAction.REPLACE &&
newPathProperties.presentation != Presentation.REPLACE &&
newPathProperties.presentation != Presentation.REPLACE_ROOT

return if (modal) {
navOptions {
anim {
enter = if (replace) 0 else R.anim.enter_slide_in_bottom
enter = if (animate) R.anim.enter_slide_in_bottom else 0
exit = R.anim.exit_slide_out_bottom
popEnter = R.anim.enter_slide_in_bottom
popExit = R.anim.exit_slide_out_bottom
}
}
} else {
navOptions {
anim {
enter = if (replace) 0 else R.anim.enter_slide_in_right
exit = R.anim.exit_slide_out_left
popEnter = R.anim.enter_slide_in_left
popExit = R.anim.exit_slide_out_right
if (clearAll) {
navOptions {
anim {
enter = R.anim.exit_slide_out_left
exit = R.anim.exit_slide_out_right
popEnter = R.anim.enter_slide_in_left
popExit = R.anim.enter_slide_in_right
}
}
} else {
navOptions {
anim {
enter = if (animate) R.anim.enter_slide_in_right else 0
exit = R.anim.exit_slide_out_left
popEnter = R.anim.enter_slide_in_left
popExit = R.anim.exit_slide_out_right
}
}
}
}
Expand Down

0 comments on commit 83528c7

Please sign in to comment.