Skip to content

Commit

Permalink
Minor optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdrobne committed Jan 20, 2022
1 parent 5c40286 commit d098c5f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Sources/CameraButton/CameraButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ public class CameraButton: UIButton, CAAnimationDelegate {
layer.addSublayer(shapeLayer)
shapeLayer.fillColor = fillColor.default.cgColor
shapeLayer.position = CGPoint(x: layer.bounds.midX, y: layer.bounds.midY)

let diameter = frame.width * 0.87
let rect = CGRect(x: -diameter / 2, y: -diameter / 2, width: diameter, height: diameter)
shapeLayer.path = UIBezierPath(ovalIn: rect).cgPath
shapeLayer.path = UIBezierPath(ovalIn: rect(for: frame.width * 0.87)).cgPath
}

private func setupProgressLayer() {
Expand All @@ -135,9 +132,8 @@ public class CameraButton: UIButton, CAAnimationDelegate {
progressLayer.position = CGPoint(x: layer.bounds.midX, y: layer.bounds.midY)

let diameter = frame.width
let rect = CGRect(x: -diameter / 2, y: -diameter / 2, width: diameter, height: diameter)
let path = UIBezierPath(
roundedRect: rect,
roundedRect: rect(for: diameter),
byRoundingCorners: .allCorners,
cornerRadii: CGSize(width: diameter, height: diameter)
)
Expand Down Expand Up @@ -182,6 +178,12 @@ public class CameraButton: UIButton, CAAnimationDelegate {
}
}

// MARK: - Utilities

private func rect(for diameter: CGFloat) -> CGRect {
return CGRect(x: -diameter / 2, y: -diameter / 2, width: diameter, height: diameter)
}

// MARK: - CAAnimationDelegate

public func animationDidStop(_ animation: CAAnimation, finished flag: Bool) {
Expand Down

0 comments on commit d098c5f

Please sign in to comment.