Use open class func setAnimationsEnabled(_ enabled: Bool) for disabling animation for the whole app.
In your case, you just needed to disable animation during the fullscreen present and start again after the present.
Here is the possible solution
override func viewDidLoad() {
super.viewDidLoad()
configureBackgroundGradient()
UIView.setAnimationsEnabled(false) //<== Disable animation for whole app
addChild(contentView)
view.addSubview(contentView.view)
DispatchQueue.main.async {
UIView.setAnimationsEnabled(true) //<== Again enable animation for whole app
}
setupContraints()
}
You can also write this inside the ContentView instead of viewDidLoad
struct ContentView: View {
@State private var isPresent: Bool = false{
willSet {
UIView.setAnimationsEnabled(false) //<== Disable animation for whole app
} didSet {
DispatchQueue.main.async {
UIView.setAnimationsEnabled(true) //<== Again enable animation for whole app
}
}
}
var body: some View {
EmptyView().fullScreenCover(isPresented: $isPresent, content: {
FullScreenView.init()
})
.onAppear() {
isPresent = true
}
}
}
You can also use this extension.
extension View {
func withoutAnimation(_ work: @escaping () -> Void) {
UIView.setAnimationsEnabled(false) //<== Disable animation for whole app
work()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
UIView.setAnimationsEnabled(true) //<== Again enable animation for whole app
}
}
}
usage:
struct ContentView: View {
@State private var isPresent: Bool = false
var body: some View {
EmptyView().fullScreenCover(isPresented: $isPresent, content: {
FullScreenView.init()
})
.onAppear() {
withoutAnimation {
isPresent = true
}
}
}
}