Skip to content

Commit

Permalink
fix: iOS 14 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
laosb committed Aug 10, 2023
1 parent 9ff5299 commit b42b532
Showing 1 changed file with 57 additions and 41 deletions.
98 changes: 57 additions & 41 deletions Sources/CropImage/DefaultControlsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,70 @@ public struct DefaultControlsView: View {
@Binding var rotation: Angle
var crop: () async -> Void

var rotateButton: some View {
Button {
let roundedAngle = Angle.degrees((rotation.degrees / 90).rounded() * 90)
withAnimation {
rotation = roundedAngle + .degrees(90)
}
} label: {
Label("Rotate", systemImage: "rotate.right")
.font(.title2)
.foregroundColor(.accentColor)
.labelStyle(.iconOnly)
.padding(.horizontal, 6)
.padding(.vertical, 3)
.background(
RoundedRectangle(cornerRadius: 5, style: .continuous)
.fill(.background)
)
}
.buttonStyle(.plain)
.padding()
}

var resetButton: some View {
Button("Reset") {
withAnimation {
offset = .zero
scale = 1
rotation = .zero
}
}
}

var cropButton: some View {
Button { Task {
await crop()
} } label: {
Label("Crop", systemImage: "checkmark.circle.fill")
.font(.title2)
.foregroundColor(.accentColor)
.labelStyle(.iconOnly)
.padding(1)
.background(
Circle().fill(.background)
)
}
.buttonStyle(.plain)
.padding()
}

public var body: some View {
VStack {
Spacer()
HStack {
Button {
let roundedAngle = Angle.degrees((rotation.degrees / 90).rounded() * 90)
withAnimation {
rotation = roundedAngle + .degrees(90)
}
} label: {
Label("Rotate", systemImage: "rotate.right")
.font(.title2)
.foregroundColor(.accentColor)
.labelStyle(.iconOnly)
.padding(.horizontal, 6)
.padding(.vertical, 3)
.background(
RoundedRectangle(cornerRadius: 5, style: .continuous)
.fill(.background)
)
}
.buttonStyle(.plain)
.padding()
rotateButton
Spacer()
Button("Reset") {
withAnimation {
offset = .zero
scale = 1
rotation = .zero
}
if #available(iOS 15.0, macOS 13.0, *) {
resetButton
.buttonStyle(.bordered)
.buttonBorderShape(.roundedRectangle)
} else {
resetButton
}
.buttonStyle(.bordered)
.buttonBorderShape(.roundedRectangle)
Spacer()
Button { Task {
await crop()
} } label: {
Label("Crop", systemImage: "checkmark.circle.fill")
.font(.title2)
.foregroundColor(.accentColor)
.labelStyle(.iconOnly)
.padding(1)
.background(
Circle().fill(.background)
)
}
.buttonStyle(.plain)
.padding()
cropButton
}
}
}
Expand Down

0 comments on commit b42b532

Please sign in to comment.