iOS Widget - Trim not drawing

I am trying to make a circular progress bar for my widget, I am using this code to do so. On the base app content view, everything comes out how I want it to. But when I try the same view on my widget, Circle().trim seems to not allow a drawing to happen and the circle disappears completely.

I have seen a couple of posts about this on the forums. I am currently running on Xcode 12.3


Code Block
     ZStack{
      Color(red: 0, green: 0, blue: 0)
      ZStack {
        Circle()
          .rotation(.degrees(112))
          .trim(from:0.0, to: 0.87)
          .stroke(style: StrokeStyle(lineWidth: 8.0, lineCap: .round))
          .opacity(0.3)
          .foregroundColor(Color.gray)
          .frame(width: 120, height: 120, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
         
        Circle()
          .rotation(.degrees(112))
          .trim(from:0.0, to: 0.2)
          .stroke(style: StrokeStyle(lineWidth: 8.0, lineCap: .round, lineJoin: .round))
          .foregroundColor(Color.white)
          .frame(width: 120, height: 120, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
           
         
      }
      .padding()
  }

Answered by Claude31 in 655396022
Sorry, I did test on app, not on widget.
I tested in widget code, Xcode 12.3, iOS 14.3 simulator: it works OK.

What do you get exactly ? No circle ? Only one ?
Could you show the complete widget code ?
I tested your code with Xcode 12.3, in simulator.

No issue, I see the 2 circles, grey and white.

Is your app only doing this drawing or are there other parts of code you didn't show ?
Accepted Answer
Sorry, I did test on app, not on widget.
I tested in widget code, Xcode 12.3, iOS 14.3 simulator: it works OK.

What do you get exactly ? No circle ? Only one ?
Could you show the complete widget code ?
I am using the default widget code, only modifying the Entry view body as seen here. Here is exactly what happens @claude31

http://bit ly/3egWddg

I may be missing something but why is this solved?

I have not been able to get trim to work on my project in a widget so started a new project, added a widget, confirmed it compiled and showed the default time text, I copied the code above and ran again and there is no circle trim to be seen.

I'm seeing two things.

The code ".rotation(.degrees(112))" seems to break the view but ".rotationEffect(Angle(degrees: 112.0))" does not...but I can not say that a rotation occurs because any trim less than 0 to 1 hides the entire stroke. So I see a full circle if I leave trim out, or do trim 0 to 1, but any value less than 1 hides the entire stroke.

Running XCode 12.3 iOS simulator 14.3.
Have you tried running it on a real device rather than Simulator or SwiftUI Preview?

I had a similar problem, not with trim, but with opacity Any opacity value less than 1.0 hides the view in Simulator and SwiftUI Preview. But it worked fine on real device.
Thank you RahulRS...it does work on a device, just not on simulator. Also confirmed the simulator bug persists to XCode 12.4 since I had started the update prior to seeing the reply to test on device.
Still not fixed in Xcode 12.5 beta 2 (12E5234g)

I have filed feedback regarding this. FB8986928

I have the same oriblem. Using trim on my Shape inside a widget does not work.

iOS Widget - Trim not drawing
 
 
Q