I've been using an asymmetric transition which has been working flawlessly during the time of iOS 15. However, with the introduction of iOS 16 the transition no longer works as expected.
In short: In my app I'm using a paged tabview. When you swipe pages I want to insert/remove another view with an animation/transition, matching the page swipe direction.
Since it's much easier to describe the problem in code I've created an isolated case where my problem is repeatable, so you can see it for yourself.
import SwiftUI
class SharedStore: ObservableObject {
@Published var selectedPage: Int = 0 {
willSet {
if newValue > selectedPage {
self.pageDirection = .forward
} else {
self.pageDirection = .reverse
}
}
}
var pageDirection: UIPageViewController.NavigationDirection = .forward
}
struct ContentView: View {
@StateObject var sharedStore = SharedStore()
var body: some View {
VStack {
Text("Page \(sharedStore.selectedPage)")
.id(sharedStore.selectedPage)
.frame(maxWidth: UIScreen.main.bounds.width)
.animation(.easeInOut, value: sharedStore.selectedPage)
.transition(
.asymmetric(
insertion: .move(edge: sharedStore.pageDirection == .forward ? .trailing : .leading),
removal: .move(edge: sharedStore.pageDirection == .forward ? .leading : .trailing)
)
)
TabView(selection: $sharedStore.selectedPage) {
ForEach(0..<10, id:\.self) { index in
Text("Hello \(index)")
}
}
.tabViewStyle(.page)
}
.padding()
}
}
Run the above on a iOS 16 simulator. Swipe a couple of pages and then change direction. Notice that the transition of the top view gets weird. The view is removed and inserted from the same edge.
If you however run the same code on a iOS 15 simulator, you will see that the top view animation matches the page swipe direction nicely, even when you change direction.
My assumption is that something has changed with the asymmetric transitions in SwiftUI 4 / iOS 16, hence the title of the post. Or could it be something the published property and the willSet observer?
Note that I'm far from a professional iOS developer, so I'm also considering that this actually worked in iOS 15 by pure luck :)