Hello,
we realized today that our app was targeting iOS 14, and changed it to iOS 13.
We found out we are not able to use StateObject
on iOS 13, and some problems arose. This is what we have:
AlertState.swift
final class CardState: ObservableObject {
static let shared = CardState()
@Published var shouldShowCard = false
private init() {}
// Some other methods and variables
}
Then, we use it like this:
ContentView.swift
struct ContentView: View {
@StateObject var cardState = CardState.shared
var body: some View {
ZStack(alignment: .center) {
if cardState.shouldShowCard {
Card()
}
}
}
}
Card.swift
struct Card: View {
@StateObject var cardState = CardState.shared
var body: some View {
// View
}
}
AlertState
holds more data, such as the text we show in the card. The card can be triggered from any screen of the app.
So, we targeted iOS 13 and replaced StateObject
with ObservedObject
, but then it stopped animating when the card gets hidden by switching shouldShowCard
to false
, the View just disappears.
What should we use in order to achieve what we used to have when using StateObject
? We are a bit lost and tried everything we found.
Thanks in advance.