Post

Replies

Boosts

Views

Activity

Reply to Xcode 16 Beta: Animatable + non isolated protocol requirement errors.
Interestingly enough, you can get animatableData to work if you mark the computed variable as nonisolated. Xcode will fail at previewing the result, but a live run shows it working.. struct ContentView: View { static let bigAngle = 60.0 static let smallAngle = 10.0 @State var angle = Self.bigAngle var body: some View { MyShape(angle: angle) .foregroundStyle(.tint) .frame(width: 300, height: 200) .animation(.smooth(duration: 1.0), value: angle) .onTapGesture { angle = angle == Self.bigAngle ? Self.smallAngle : Self.bigAngle } } } struct MyShape: Shape { init(angle: Double) { self.angle = angle } var angle: Double nonisolated var animatableData: Double { get {angle} set {angle = newValue } } func path(in rect: CGRect) -> Path { Path { path in path.move(to: CGPoint(x: 0, y: 0)) // top left path.addLine(to: CGPoint(x: max(0,rect.width - rect.height*tan(angle * .pi/180)), y: 0)) // top right (or top left if the angle is large enough) path.addLine(to: CGPoint(x: rect.width, y: rect.height)) //bottom right path.addLine(to: CGPoint(x: 0, y: rect.height)) // bottom left path.closeSubpath() // Close (back to top left) } } }
Jul ’24