Skip to content

Commit

Permalink
refactor: make CropToolbarDelegate conform to Apple's naming conventi…
Browse files Browse the repository at this point in the history
…on (#231)
  • Loading branch information
guoyingtao authored Nov 13, 2022
1 parent 2734c54 commit 21604f0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Example/CustomizedCropToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ class CustomizedCropToolbar: UIView, CropToolbarProtocol {
}

@objc private func crop() {
cropToolbarDelegate?.didSelectCrop()
cropToolbarDelegate?.didSelectCrop(self)
}

@objc private func cancel() {
cropToolbarDelegate?.didSelectCancel()
cropToolbarDelegate?.didSelectCancel(self)
}

@objc private func showRatioList() {
cropToolbarDelegate?.didSelectSetRatio()
cropToolbarDelegate?.didSelectSetRatio(self)
}

private func createOptionButton(withTitle title: String?, andAction action: Selector) -> UIButton {
Expand Down
8 changes: 4 additions & 4 deletions Example/CustomizedCropToolbarWithoutList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ class CustomizedCropToolbarWithoutList: UIView, CropToolbarProtocol {
}

@objc private func crop() {
cropToolbarDelegate?.didSelectCrop()
cropToolbarDelegate?.didSelectCrop(self)
}

@objc private func cancel() {
cropToolbarDelegate?.didSelectCancel()
cropToolbarDelegate?.didSelectCancel(self)
}

@objc private func setPortraitRatio() {
cropToolbarDelegate?.didSelectRatio(ratio: 9 / 16)
cropToolbarDelegate?.didSelectRatio(self, ratio: 9 / 16)
}

@objc private func setLandscapeRatio() {
cropToolbarDelegate?.didSelectRatio(ratio: 16 / 9)
cropToolbarDelegate?.didSelectRatio(self, ratio: 16 / 9)
}

private func createOptionButton(withTitle title: String?, andAction action: Selector) -> UIButton {
Expand Down
6 changes: 3 additions & 3 deletions Example/MyNavigationCropToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class MyNavigationCropToolbar: UIView, CropToolbarProtocol {
}

@objc func crop() {
cropToolbarDelegate?.didSelectCrop()
cropToolbarDelegate?.didSelectCrop(self)
}

@objc func cancel() {
cropToolbarDelegate?.didSelectCancel()
cropToolbarDelegate?.didSelectCancel(self)
}

@objc func rotate() {
cropToolbarDelegate?.didSelectClockwiseRotate()
cropToolbarDelegate?.didSelectClockwiseRotate(self)
}
}
18 changes: 9 additions & 9 deletions Sources/Mantis/CropViewController/CropToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,39 +203,39 @@ public class CropToolbar: UIView, CropToolbarProtocol {
// Objc functions
extension CropToolbar {
@objc private func cancel() {
cropToolbarDelegate?.didSelectCancel()
cropToolbarDelegate?.didSelectCancel(self)
}

@objc private func setRatio() {
cropToolbarDelegate?.didSelectSetRatio()
cropToolbarDelegate?.didSelectSetRatio(self)
}

@objc private func reset(_ sender: Any) {
cropToolbarDelegate?.didSelectReset()
cropToolbarDelegate?.didSelectReset(self)
}

@objc private func counterClockwiseRotate(_ sender: Any) {
cropToolbarDelegate?.didSelectCounterClockwiseRotate()
cropToolbarDelegate?.didSelectCounterClockwiseRotate(self)
}

@objc private func clockwiseRotate(_ sender: Any) {
cropToolbarDelegate?.didSelectClockwiseRotate()
cropToolbarDelegate?.didSelectClockwiseRotate(self)
}

@objc private func alterCropper90Degree(_ sender: Any) {
cropToolbarDelegate?.didSelectAlterCropper90Degree()
cropToolbarDelegate?.didSelectAlterCropper90Degree(self)
}

@objc private func horizontallyFlip(_ sender: Any) {
cropToolbarDelegate?.didSelectHorizontallyFlip()
cropToolbarDelegate?.didSelectHorizontallyFlip(self)
}

@objc private func verticallyFlip(_ sender: Any) {
cropToolbarDelegate?.didSelectVerticallyFlip()
cropToolbarDelegate?.didSelectVerticallyFlip(self)
}

@objc private func crop(_ sender: Any) {
cropToolbarDelegate?.didSelectCrop()
cropToolbarDelegate?.didSelectCrop(self)
}
}

Expand Down
20 changes: 10 additions & 10 deletions Sources/Mantis/CropViewController/CropToolbarProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import UIKit
Inside Mantis, CropViewController implements all delegate methods
*/
public protocol CropToolbarDelegate: AnyObject {
func didSelectCancel()
func didSelectCrop()
func didSelectCounterClockwiseRotate()
func didSelectClockwiseRotate()
func didSelectReset()
func didSelectSetRatio()
func didSelectRatio(ratio: Double)
func didSelectAlterCropper90Degree()
func didSelectHorizontallyFlip()
func didSelectVerticallyFlip()
func didSelectCancel(_ cropToolbar: CropToolbarProtocol)
func didSelectCrop(_ cropToolbar: CropToolbarProtocol)
func didSelectCounterClockwiseRotate(_ cropToolbar: CropToolbarProtocol)
func didSelectClockwiseRotate(_ cropToolbar: CropToolbarProtocol)
func didSelectReset(_ cropToolbar: CropToolbarProtocol)
func didSelectSetRatio(_ cropToolbar: CropToolbarProtocol)
func didSelectRatio(_ cropToolbar: CropToolbarProtocol, ratio: Double)
func didSelectAlterCropper90Degree(_ cropToolbar: CropToolbarProtocol)
func didSelectHorizontallyFlip(_ cropToolbar: CropToolbarProtocol)
func didSelectVerticallyFlip(_ cropToolbar: CropToolbarProtocol)
}

public protocol CropToolbarIconProvider: AnyObject {
Expand Down
20 changes: 10 additions & 10 deletions Sources/Mantis/CropViewController/CropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,43 +525,43 @@ extension CropViewController: CropViewDelegate {
}

extension CropViewController: CropToolbarDelegate {
public func didSelectHorizontallyFlip() {
public func didSelectHorizontallyFlip(_ cropToolbar: CropToolbarProtocol) {
handleHorizontallyFlip()
}

public func didSelectVerticallyFlip() {
public func didSelectVerticallyFlip(_ cropToolbar: CropToolbarProtocol) {
handleVerticallyFlip()
}

public func didSelectCancel() {
public func didSelectCancel(_ cropToolbar: CropToolbarProtocol) {
handleCancel()
}

public func didSelectCrop() {
public func didSelectCrop(_ cropToolbar: CropToolbarProtocol) {
handleCrop()
}

public func didSelectCounterClockwiseRotate() {
public func didSelectCounterClockwiseRotate(_ cropToolbar: CropToolbarProtocol) {
handleRotate(rotateAngle: -CGFloat.pi / 2)
}

public func didSelectClockwiseRotate() {
public func didSelectClockwiseRotate(_ cropToolbar: CropToolbarProtocol) {
handleRotate(rotateAngle: CGFloat.pi / 2)
}

public func didSelectReset() {
public func didSelectReset(_ cropToolbar: CropToolbarProtocol) {
handleReset()
}

public func didSelectSetRatio() {
public func didSelectSetRatio(_ cropToolbar: CropToolbarProtocol) {
handleSetRatio()
}

public func didSelectRatio(ratio: Double) {
public func didSelectRatio(_ cropToolbar: CropToolbarProtocol, ratio: Double) {
setFixedRatio(ratio)
}

public func didSelectAlterCropper90Degree() {
public func didSelectAlterCropper90Degree(_ cropToolbar: CropToolbarProtocol) {
handleAlterCropper90Degree()
}
}
Expand Down

0 comments on commit 21604f0

Please sign in to comment.