Skip to content

Commit

Permalink
fix: 🐛 [bcp: 0] fix crashes on VisionOS caused by strokeBorder (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
shengxu7 committed Sep 27, 2023
1 parent 5cdd884 commit 44de9bd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ struct DataTableExample: View {
.rowAlignment(.baseline)
.showListView(true)
.frame(width: 343, height: 124)
.border(Color.gray, width: 1)
.disabled(true))

NavigationLink("Example 2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ struct HarveyBallMicroChart: View {
if fraction != nil && total != nil {
Spacer()
ZStack(alignment: .center) {
ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 360))
.strokeBorder(total!.color, lineWidth: radius)
Circle()
.fill(total!.color)
.frame(width: radius * 2, height: radius * 2)

ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: Double(fraction!.value) * 360 / Double(total!.value)))
.strokeBorder(fraction!.color, lineWidth: radius - depth)
ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: Double(fraction!.value) * 360 / Double(total!.value)), insetAmount: (radius - depth) / 2)
.stroke(fraction!.color, lineWidth: radius - depth)
.frame(width: (radius - depth) * 2, height: (radius - depth) * 2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ struct RadialMicroChart: View {
let depth = val > RadialMicroChart.maxDepth ? RadialMicroChart.maxDepth : (val < RadialMicroChart.minDepth ? RadialMicroChart.minDepth : val)

return ZStack {
ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 360))
.strokeBorder(total!.color, lineWidth: depth)
ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: ratio * 360))
.strokeBorder(percentage!.color, lineWidth: depth)
ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 360), insetAmount: depth / 2)
.stroke(total!.color, lineWidth: depth)
ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: ratio * 360), insetAmount: depth / 2)
.stroke(percentage!.color, lineWidth: depth)
}.frame(width: radius * 2, height: radius * 2, alignment: .topLeading)
}
}
Expand Down
27 changes: 11 additions & 16 deletions Sources/FioriCharts/Common/Views/ArcShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ struct ArcShape: InsettableShape {
let rotationAdjustment = Angle.degrees(90)
let modifiedStart = self.startAngle - rotationAdjustment
let modifiedEnd = self.endAngle - rotationAdjustment

let radius = min(rect.size.width, rect.size.height) / 2 - self.insetAmount
var path = Path()

path.addArc(center: CGPoint(x: rect.midX, y: rect.midY), radius: rect.width / 2 - self.insetAmount, startAngle: modifiedStart, endAngle: modifiedEnd, clockwise: !self.clockwise)
path.addArc(center: CGPoint(x: rect.midX, y: rect.midY), radius: radius, startAngle: modifiedStart, endAngle: modifiedEnd, clockwise: !self.clockwise)

return path
}
Expand All @@ -29,28 +29,23 @@ struct ArcShape: InsettableShape {
struct ArcShape_Previews: PreviewProvider {
static var previews: some View {
Group {
ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 90))
.strokeBorder(Color.red)
ArcShape(startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 90), insetAmount: 0.5)
.stroke(Color.red, lineWidth: 1)
.frame(width: 200, height: 200)
.previewLayout(.sizeThatFits)

ArcShape(startAngle: Angle(degrees: 20), endAngle: Angle(degrees: 360))
.strokeBorder(Color.red, lineWidth: 40)
ArcShape(startAngle: Angle(degrees: 20), endAngle: Angle(degrees: 360), insetAmount: 20)
.stroke(Color.red, lineWidth: 40)
.frame(width: 200, height: 200)
.previewLayout(.sizeThatFits)

// ArcShape(startAngle: Angle(degrees: 20), endAngle: Angle(degrees: 360))
// .stroke(Color.red, lineWidth: 40)
// .frame(width: 200, height: 200)
// .previewLayout(.sizeThatFits)

ArcShape(startAngle: Angle(degrees: 20), endAngle: Angle(degrees: 270), clockwise: false)
.strokeBorder(Color.red, lineWidth: 100)

ArcShape(startAngle: Angle(degrees: 20), endAngle: Angle(degrees: 270), clockwise: false, insetAmount: 50)
.stroke(Color.red, lineWidth: 100)
.frame(width: 200, height: 200)
.previewLayout(.sizeThatFits)

ArcShape(startAngle: Angle(degrees: 20), endAngle: Angle(degrees: 21))
.strokeBorder(Color.red, lineWidth: 40)
ArcShape(startAngle: Angle(degrees: 20), endAngle: Angle(degrees: 21), insetAmount: 20)
.stroke(Color.red, lineWidth: 40)
.frame(width: 200, height: 200)
.previewLayout(.sizeThatFits)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ extension DimensionSelector {
.padding(insets)
.font(getSegmentAttributes()?.font)
.foregroundColor(getSegmentAttributes()?.textColor)
.background(RoundedRectangle(cornerRadius: cornerRadius, style: .continuous).strokeBorder(getSegmentAttributes()!.borderColor!, lineWidth: getSegmentAttributes()!.borderWidth!, antialiased: true))
.background(
RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
.inset(by: getSegmentAttributes()!.borderWidth! / 2.0)
.stroke(getSegmentAttributes()!.borderColor!, lineWidth: getSegmentAttributes()!.borderWidth!)
)
.background(RoundedRectangle(cornerRadius: cornerRadius, style: .continuous).fill(getSegmentAttributes()!.backgroundColor!))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public extension AvatarList {
.clipShape(Capsule())
.overlay {
Capsule()
.strokeBorder(borderColor, lineWidth: borderWidth)
.inset(by: borderWidth / 2.0)
.stroke(borderColor, lineWidth: borderWidth)
}
} else {
avatar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public extension FootnoteIconList {
Group {
if isCircular {
Capsule()
.strokeBorder(Color.preferredColor(.separator), lineWidth: 0.33)
.inset(by: 0.33 / 2.0)
.stroke(Color.preferredColor(.separator), lineWidth: 0.33)
} else {
Rectangle()
.strokeBorder(Color.preferredColor(.separator), lineWidth: 0.33)
.inset(by: 0.33 / 2.0)
.stroke(Color.preferredColor(.separator), lineWidth: 0.33)
}
}
}
Expand Down

0 comments on commit 44de9bd

Please sign in to comment.