Skip to content

Commit 83528c7

Browse files
authored
Merge pull request #75 from hotwired/navigation-animations
Fix navigation animations - don't animate `replace` visits
2 parents 83a61c5 + f2376fb commit 83528c7

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

demo/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<style name="Widget.MyTheme.BottomSheet.Modal" parent="Widget.MaterialComponents.BottomSheet.Modal">
1717
<item name="shapeAppearanceOverlay">?shapeAppearanceLargeComponent</item>
1818
<item name="behavior_draggable">true</item>
19-
<item name="behavior_peekHeight">600dp</item>
19+
<item name="behavior_peekHeight">400dp</item>
2020
<item name="backgroundTint">?colorSurface</item>
2121
</style>
2222

navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestination.kt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import dev.hotwire.core.bridge.BridgeDestination
1111
import dev.hotwire.core.config.Hotwire
1212
import dev.hotwire.core.turbo.config.PathConfigurationProperties
1313
import dev.hotwire.core.turbo.config.context
14+
import dev.hotwire.core.turbo.config.presentation
15+
import dev.hotwire.core.turbo.nav.Presentation
1416
import dev.hotwire.core.turbo.nav.PresentationContext
1517
import dev.hotwire.core.turbo.visit.VisitAction
1618
import dev.hotwire.navigation.R
@@ -136,24 +138,38 @@ interface HotwireDestination : BridgeDestination {
136138
action: VisitAction
137139
): NavOptions {
138140
val modal = newPathProperties.context == PresentationContext.MODAL
139-
val replace = action == VisitAction.REPLACE
141+
val clearAll = newPathProperties.presentation == Presentation.CLEAR_ALL
142+
val animate = action != VisitAction.REPLACE &&
143+
newPathProperties.presentation != Presentation.REPLACE &&
144+
newPathProperties.presentation != Presentation.REPLACE_ROOT
140145

141146
return if (modal) {
142147
navOptions {
143148
anim {
144-
enter = if (replace) 0 else R.anim.enter_slide_in_bottom
149+
enter = if (animate) R.anim.enter_slide_in_bottom else 0
145150
exit = R.anim.exit_slide_out_bottom
146151
popEnter = R.anim.enter_slide_in_bottom
147152
popExit = R.anim.exit_slide_out_bottom
148153
}
149154
}
150155
} else {
151-
navOptions {
152-
anim {
153-
enter = if (replace) 0 else R.anim.enter_slide_in_right
154-
exit = R.anim.exit_slide_out_left
155-
popEnter = R.anim.enter_slide_in_left
156-
popExit = R.anim.exit_slide_out_right
156+
if (clearAll) {
157+
navOptions {
158+
anim {
159+
enter = R.anim.exit_slide_out_left
160+
exit = R.anim.exit_slide_out_right
161+
popEnter = R.anim.enter_slide_in_left
162+
popExit = R.anim.enter_slide_in_right
163+
}
164+
}
165+
} else {
166+
navOptions {
167+
anim {
168+
enter = if (animate) R.anim.enter_slide_in_right else 0
169+
exit = R.anim.exit_slide_out_left
170+
popEnter = R.anim.enter_slide_in_left
171+
popExit = R.anim.exit_slide_out_right
172+
}
157173
}
158174
}
159175
}

0 commit comments

Comments
 (0)