-
Notifications
You must be signed in to change notification settings - Fork 18
Description
I am using the this library for an animated gradient background in my app. It works fine.
However, my app is in Swift and so I am using UIHostingController
to display the FluidGradient
:
import SwiftUI
import FluidGradient
let childView = UIHostingController(rootView: GradientView2())
addChild(childView)
view.addSubview(childView.view)
childView.view.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
childView.didMove(toParent: self)
struct GradientView2: View {
var body: some View {
FluidGradient(blobs: [.red, .orange, .pink],
highlights: [.yellow, .orange, .purple],
speed: 0.2,
blur: 0.75)
.background(.tertiary)
.edgesIgnoringSafeArea(.all)
}
}
The GitHub page of FluidGradient
notes the following:
While it's easy to create the blob shapes in SwiftUI, animation in
SwiftUI is still performed on the CPU. This means that your app will
probably consume double-digit CPU percentages and be noted as a "high"
energy consumer in Activity Monitor.We use CALayer instead because it offloads all the work to the
WindowServer, making your app have a zero performance impact despite
running the gradient animation at full screen refresh rate.
And they show that the FluidGradient
doesn't cause ""high" energy consumer in Activity Monitor.".
However, in my app, Xcode is warning me of "HIGH" energy impact even though CPU usage is at 0%:
How can I prevent this? Does UIHostingController
have high energy impact side effect?
Note that my app doesn't have anything else. Only this FluidGradient
.