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

Fix navigation animations - don't animate replace visits #75

Merged
merged 1 commit into from
Dec 2, 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
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