I have a SwiftUI
Form
with a custom chart view (not Swift Charts). A long press toggles to a different type of chart. These charts use the .transition(.slide)
modifier. In iOS 15 these transitioned as expected on a long press, but in iOS 16 they do not.
Persisted state property (an enum):
@AppStorage("chartType") var chartType: ChartType = .chartA
The Form
part of the body
property:
Form {
// Other sections
Section {
switch chartType {
case .chartA:
ChartViewA()
.transition(.slide)
case .chartB:
ChartViewB()
.transition(.slide)
}
.onLongPressGesture {
if chartType == .chartA {
withAnimation {
summaryChartType = .chartB
}
} else {
withAnimation {
summaryChartType = .chartA
}
}
}
Unfortunately adding animation modifiers like .animation(.spring(), value: chartType)
makes no difference.
I would be grateful for advice on why this might have worked in iOS 15 but not in iOS 16, and what I could do to restore animation here.