I came across an interesting issue today, that I am not able to figure out a sollution for. In essence I am working on a custom Tab View animation where existing and new views should slide out/in via transition, but depending on what new view is do so in a specific dirrections. i.e. say I have a 4 tabs in this order Home -> Account -> Settings
If user is on Home view and chooses Settings, Home view should slide to the left and Settings view should slide from right. Similarly if user is on Account view and chooses Home, Account view should slide to the right and Home view should slide in from left.
To acheive this, I created following component that wraps each Tab view
import SwiftUI
struct TabLayoutRoute<Content: View>: View {
@ViewBuilder let content: Content
private var isAnimateLeft: Bool {
TabRouterBloc.view.rawValue > TabRouterBloc.previousView.rawValue
}
var body: some View {
VStack {
content
}
.transition(
.asymmetric(
insertion: .move(edge: isAnimateLeft ? .trailing : .leading),
removal: .move(edge: isAnimateLeft ? .trailing : .leading)
)
)
}
}
This creates a boolean isAnimateLeft
that determines which move transition to apply based on observable value. I then wrap my views with this component and render them conditionally based on current TabRouterObservable.view
in a parent with animation. Everything seems to work, but with issues. It feels like transitions are not reacting to changes in observable state i.e. they just use what was provided originally and don't update.
Is there a way to ensure that these transitions use latest values from observable?