Skip to content

Commit

Permalink
fix: round corner (#41)
Browse files Browse the repository at this point in the history
* fix: round corner

* fix: change processor order
  • Loading branch information
duguyihou authored Nov 19, 2023
1 parent 13de94a commit 6cd377c
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions ios/TurboImage/TurboImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React
class TurboImageView : UIView {

private var placeholder: UIImage?
private var cornerRadius: CGFloat?
private var cornerRadius: CGFloat = 0.0
lazy var lazyImageView = UIImageView()
@objc var onError: RCTDirectEventBlock?
@objc var onSuccess: RCTDirectEventBlock?
Expand Down Expand Up @@ -42,9 +42,10 @@ class TurboImageView : UIView {

@objc var rounded: Bool = false {
didSet {
guard let width = placeholder?.size.width else { return }
cornerRadius = width
placeholder = placeholder?.roundedCorner(with: width)
cornerRadius = 0.5
if let width = placeholder?.size.width {
placeholder = placeholder?.roundedCorner(with: width)
}
}
}

Expand Down Expand Up @@ -78,12 +79,11 @@ fileprivate extension TurboImageView {
guard let url = URL(string: url!)
else { return }

let processor = composeProcessor(tint, rounded)

KF.url(url)
.fade(duration: TimeInterval(truncating: fadeDuration))
.placeholder(placeholder)
.setProcessor(processor)
.tint(color: tint)
.roundCorner(radius:.widthFraction(cornerRadius))
.onSuccess({ result in
self.onSuccess?(["result": "success"])
})
Expand All @@ -92,18 +92,4 @@ fileprivate extension TurboImageView {
})
.set(to: lazyImageView)
}

func composeProcessor( _ tint: UIColor?, _ rounded: Bool?) -> ImageProcessor {
var processor: ImageProcessor = DefaultImageProcessor.default

if tint != nil && tint != .clear {
processor = processor |> TintImageProcessor(tint: tint!)
}

if rounded ?? false && (cornerRadius != nil) {
processor = processor |> RoundCornerImageProcessor(cornerRadius: cornerRadius!)
}

return processor
}
}

0 comments on commit 6cd377c

Please sign in to comment.