Post

Replies

Boosts

Views

Activity

Has the behavior of asymmetric transitions changed in SwiftUI 4 / iOS 16?
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 :)
3
3
3.0k
Sep ’22
Start and End date for a given week
Hi, I'm fairly new to Swift and I'm currently experimenting with an app based on EventKit data. In this app the user will select a week in the current year, like week 10. I need a way to find the start and end date for the selected week (Monday March 8 and Sunday March 14 for week 10 (at least in Sweden)) This will then be used as predicate when fetching events from the calendar. I'm also thinking that I would like the solution to take into account the users current calendar settings, like firstWeekday etc. I really can't seem to find a solution for this, anyone that can point me in the right direction? Thanks in advance!
0
0
560
Jan ’21