I am blurring a View depending on the Scene Phase. I also added withAnimation { ... }, however, the Blur-Transition happens without any Animation. Check out my Code:
@main struct ExampleApp: App {
@Environment(\.scenePhase) var scenePhase
@State private var blurRadius: CGFloat = 0
var body: some Scene {
WindowGroup {
RootView()
.blur(radius: blurRadius)
.onChange(of: scenePhase, perform: { value in
switch value {
case .active : withAnimation { blurRadius = 0 }
case .inactive: withAnimation { blurRadius = 15 }
@unknown default: print("Unknown")
}
})
}
}
}
Does anyone have an Idea why the Blur-Status changes without any Animation?
Thank you for your help.
Although this behavior doesn't seem to work correctly as the root node inside an App, it does seem to work if you move the blur and animation inside the View:
struct RootView: View {
@Environment(\.scenePhase) var scenePhase
@State var blurRadius : CGFloat = 0
var body: some View {
Text("Hello, world!")
.blur(radius: blurRadius)
.onChange(of: scenePhase, perform: { value in
switch value {
case .active : withAnimation { blurRadius = 0 }
case .inactive: withAnimation { blurRadius = 15 }
@unknown default: print("Unknown")
}
})
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With