Skip to content

Commit feff1cf

Browse files
committed
Fix gradient picker infinite loop (for real this time)
1 parent 7ea878c commit feff1cf

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

Ice/Utilities/UI/Views/Pickers/CustomGradientPicker/CustomGradientPicker.swift

+23-22
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ struct CustomGradientPicker: View {
4242

4343
var body: some View {
4444
gradientView
45-
.clipShape(
46-
RoundedRectangle(
47-
cornerRadius: 4,
48-
style: .circular
49-
)
50-
)
45+
.clipShape(borderShape)
5146
.overlay {
5247
borderView
5348
}
@@ -74,6 +69,11 @@ struct CustomGradientPicker: View {
7469
.readWindow(window: $window)
7570
}
7671

72+
@ViewBuilder
73+
private var borderShape: some Shape {
74+
RoundedRectangle(cornerRadius: 4, style: .circular)
75+
}
76+
7777
@ViewBuilder
7878
private var gradientView: some View {
7979
if gradient.stops.isEmpty {
@@ -87,16 +87,13 @@ struct CustomGradientPicker: View {
8787

8888
@ViewBuilder
8989
private var borderView: some View {
90-
RoundedRectangle(
91-
cornerRadius: 4,
92-
style: .circular
93-
)
94-
.stroke()
95-
.overlay {
96-
centerTickMark
97-
}
98-
.foregroundStyle(.secondary.opacity(0.75))
99-
.blendMode(.softLight)
90+
borderShape
91+
.stroke()
92+
.overlay {
93+
centerTickMark
94+
}
95+
.foregroundStyle(.secondary.opacity(0.75))
96+
.blendMode(.softLight)
10097
}
10198

10299
@ViewBuilder
@@ -116,12 +113,7 @@ struct CustomGradientPicker: View {
116113
@ViewBuilder
117114
private func insertionReader(geometry: GeometryProxy) -> some View {
118115
Color.clear
119-
.contentShape(
120-
RoundedRectangle(
121-
cornerRadius: 4,
122-
style: .circular
123-
)
124-
)
116+
.contentShape(borderShape)
125117
.gesture(
126118
DragGesture(
127119
minimumDistance: 0,
@@ -250,6 +242,7 @@ private struct CustomGradientPickerHandle: View {
250242
@Binding var selectedStop: ColorStop?
251243
@Binding var zOrderedStops: [ColorStop]
252244
@Binding var cancellables: Set<AnyCancellable>
245+
@State private var canActivate = true
253246

254247
let index: Int
255248
let supportsOpacity: Bool
@@ -386,6 +379,10 @@ private struct CustomGradientPickerHandle: View {
386379
}
387380

388381
private func activate() {
382+
guard canActivate else {
383+
return
384+
}
385+
389386
deactivate()
390387

391388
NSColorPanel.shared.showsAlpha = supportsOpacity
@@ -405,6 +402,10 @@ private struct CustomGradientPickerHandle: View {
405402
.receive(on: DispatchQueue.main)
406403
.dropFirst()
407404
.sink { color in
405+
canActivate = false
406+
defer {
407+
canActivate = true
408+
}
408409
if stop?.color != color.cgColor {
409410
stop?.color = color.cgColor
410411
selectedStop = stop

0 commit comments

Comments
 (0)