Skip to content

Commit

Permalink
feat: Add cropAuxiliaryIndicatorStyle in CropViewConfig for the issue #…
Browse files Browse the repository at this point in the history
…366 (#367)

Support transparent style for CropAuxiliaryIndicatorView
  • Loading branch information
guoyingtao committed Jan 13, 2024
1 parent ecc3075 commit 4f7e842
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
34 changes: 28 additions & 6 deletions Sources/Mantis/CropView/CropAuxiliaryIndicatorView.swift
Expand Up @@ -22,6 +22,7 @@ final class CropAuxiliaryIndicatorView: UIView, CropAuxiliaryIndicatorViewProtoc
private var gridMainColor = UIColor.white
private var gridSecondaryColor = UIColor.lightGray
private var disableCropBoxDeformation = false
private var style: CropAuxiliaryIndicatorStyleType = .normal

var cropBoxHotAreaUnit: CGFloat = 42

Expand All @@ -48,12 +49,16 @@ final class CropAuxiliaryIndicatorView: UIView, CropAuxiliaryIndicatorViewProtoc
}
}

init(frame: CGRect, cropBoxHotAreaUnit: CGFloat, disableCropBoxDeformation: Bool = false) {
init(frame: CGRect,
cropBoxHotAreaUnit: CGFloat,
disableCropBoxDeformation: Bool = false,
style: CropAuxiliaryIndicatorStyleType = .normal) {
super.init(frame: frame)
clipsToBounds = false
backgroundColor = .clear
self.cropBoxHotAreaUnit = cropBoxHotAreaUnit
self.disableCropBoxDeformation = disableCropBoxDeformation
self.style = style
setup()
}

Expand All @@ -65,7 +70,11 @@ final class CropAuxiliaryIndicatorView: UIView, CropAuxiliaryIndicatorViewProtoc
private func createNewLine() -> UIView {
let view = UIView()
view.frame = .zero
view.backgroundColor = .white
if style == .normal {
view.backgroundColor = .white
} else {
view.backgroundColor = .clear
}
addSubview(view)
return view
}
Expand All @@ -74,7 +83,14 @@ final class CropAuxiliaryIndicatorView: UIView, CropAuxiliaryIndicatorViewProtoc
borderLine = createNewLine()
borderLine.layer.backgroundColor = UIColor.clear.cgColor
borderLine.layer.borderWidth = borderThickness
borderLine.layer.borderColor = boarderNormalColor.cgColor

if style == .normal {
borderLine.layer.borderColor = boarderNormalColor.cgColor
hintLine.backgroundColor = boarderHintColor
} else {
borderLine.layer.borderColor = UIColor.clear.cgColor
hintLine.backgroundColor = .clear
}

for _ in 0..<8 {
cornerHandles.append(createNewLine())
Expand All @@ -84,8 +100,6 @@ final class CropAuxiliaryIndicatorView: UIView, CropAuxiliaryIndicatorViewProtoc
edgeLineHandles.append(createNewLine())
}

hintLine.backgroundColor = boarderHintColor

setupAccessibilityHelperViews()
}

Expand All @@ -109,6 +123,10 @@ final class CropAuxiliaryIndicatorView: UIView, CropAuxiliaryIndicatorViewProtoc
}

override func draw(_ rect: CGRect) {
if style == .transparent {
return
}

if !gridHidden {
let indicatorLineNumber = gridLineNumberType.getIndicatorLineNumber()

Expand Down Expand Up @@ -158,7 +176,11 @@ final class CropAuxiliaryIndicatorView: UIView, CropAuxiliaryIndicatorViewProtoc
height: bounds.height + 2 * borderThickness)
borderLine.layer.backgroundColor = UIColor.clear.cgColor
borderLine.layer.borderWidth = borderThickness
borderLine.layer.borderColor = boarderNormalColor.cgColor
if style == .normal {
borderLine.layer.borderColor = boarderNormalColor.cgColor
} else {
borderLine.layer.borderColor = UIColor.clear.cgColor
}
}

private func layoutCornerHandles() {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Mantis/CropViewConfig.swift
Expand Up @@ -31,6 +31,8 @@ public struct CropViewConfig {

public var cropMaskVisualEffectType: CropMaskVisualEffectType = .blurDark

public var cropAuxiliaryIndicatorStyle: CropAuxiliaryIndicatorStyleType = .normal

public var presetTransformationType: PresetTransformationType = .none

public var minimumZoomScale: CGFloat = 1 {
Expand Down
5 changes: 5 additions & 0 deletions Sources/Mantis/Enum.swift
Expand Up @@ -146,6 +146,11 @@ enum RotateBy90DegreeType {
}
}

public enum CropAuxiliaryIndicatorStyleType {
case normal
case transparent
}

enum CropViewAuxiliaryIndicatorHandleType: Int {
case none
case topLeft
Expand Down
3 changes: 2 additions & 1 deletion Sources/Mantis/Mantis.swift
Expand Up @@ -98,7 +98,8 @@ private func buildCropView(withImage image: UIImage,
rotationControlView: RotationControlViewProtocol?) -> CropViewProtocol {
let cropAuxiliaryIndicatorView = CropAuxiliaryIndicatorView(frame: .zero,
cropBoxHotAreaUnit: cropViewConfig.cropBoxHotAreaUnit,
disableCropBoxDeformation: cropViewConfig.disableCropBoxDeformation)
disableCropBoxDeformation: cropViewConfig.disableCropBoxDeformation,
style: cropViewConfig.cropAuxiliaryIndicatorStyle)
let imageContainer = ImageContainer(image: image)
let cropView = CropView(image: image,
cropViewConfig: cropViewConfig,
Expand Down

0 comments on commit 4f7e842

Please sign in to comment.