I finally found out was went wrong:
On my original version, I had
Circle()
.trim(from: 0, to: showFreespaceRing ? CGFloat(Double(freeDiskspace) / Double(totalDiskspace)) : 0)
.stroke(Color.green.opacity(0.7), style: StrokeStyle(lineWidth: 10, lineCap: .round))
.frame(width: circleDiam, height: circleDiam)
.animation(.easeIn(duration: 1))
.onAppear() {
showFreespaceRing = true
}
And now I have:
Circle()
.trim(from: 0, to: showFreespaceRing ? 0 : CGFloat(Double(freeDiskspace) / Double(totalDiskspace)))
.stroke(Color.green.opacity(0.7), style: StrokeStyle(lineWidth: 10, lineCap: .round))
.frame(width: circleDiam, height: circleDiam)
.animation(.easeIn(duration: 1), value: showFreespaceRing)
.onAppear() {
showFreespaceRing.toggle()
}
With this, the animation works again (somewhat - see video below, there is still one issue)....
The trick was to use .toggle()
inside the onAppear
method.
What definitively does not work is to have showFreespaceRing = true
inside the onAppear()
method (but rather showFreespaceRing.toggle()
instead !!!!!!!
And, of course, fulfilling iOS15's new value
inside animation
:
.animation(.easeIn(duration: 1), value: showFreespaceRing)
However, there is one annoyance, still, with the current solution:
THE ANIMATION IS NOT SMOOTH !!
See this video:
If you look carefully you can see that the animation is not smooth at all but rather flickering badly. (i.e. the ring-animation looks catastrophic, still). How can I get a smooth animation ??

=================================================
After 1 day of investigation, here is what I've found out:
THE ROOT CAUSE OF THE JITTER IN THE ANIMATION SEEMS TO BE THE .sheet
!!!!
Here is a complete example that jitters !
import SwiftUI
enum THSheetSelection: Hashable, Identifiable {
case trialSheet
var id: THSheetSelection { self }
}
struct ContentView: View {
@State private var sheetState: THSheetSelection?
var body: some View {
Text("Hello")
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(2000)) {
sheetState = .trialSheet
}
}
.sheet(item: $sheetState) { state in
switch state {
case .trialSheet:
SessionDiskspaceStatisticsView()
}
}
}
}
struct SessionDiskspaceStatisticsView: View {
@State private var neededDiskSpace: Int64 = 0
@State private var freeDiskspace: Int64 = 0
@State private var totalDiskspace: Int64 = 0
@State private var showFreespaceRing = false
let deviceIdiom = UIScreen.main.traitCollection.userInterfaceIdiom
var body: some View {
ZStack {
VStack(alignment: .center) {
Spacer().frame(height: 30)
ZStack {
HStack {
Spacer().frame(width: 50)
ZStack{
Circle()
.trim(from: 0, to: 1)
.stroke(Color.gray.opacity(0.2), lineWidth: 10)
.frame(width: 137.5, height: 137.5)
if neededDiskSpace < freeDiskspace {
Circle()
.trim(from: 0, to: showFreespaceRing ? 0 : CGFloat(Double(freeDiskspace) / Double(totalDiskspace)))
.stroke(Color.green.opacity(0.7), style: StrokeStyle(lineWidth: 10, lineCap: .round))
.frame(width: 137.5, height: 137.5)
.animation(.easeIn(duration: 1), value: showFreespaceRing)
.onAppear() {
showFreespaceRing.toggle()
}
.rotationEffect(.init(degrees: 90))
} else {
Text(LocalizedStringKey("NotEnoughSpaceKey"))
.font(.system(size: 16))
.fontWeight(.regular)
.foregroundColor(Color.red)
.frame(width: 137.5 - 10)
.multilineTextAlignment(.center)
.rotationEffect(.init(degrees: 90))
}
}
.rotationEffect(.init(degrees: -90))
Spacer()
}
}
Spacer().frame(height: 30)
}
}
.onAppear {
neededDiskSpace = 20000
freeDiskspace = 130000
totalDiskspace = 150000
}
}
}
Any idea on how to animate the circular-progressBar inside a .sheet
without Jitter ??????