Skip to content

Commit

Permalink
fix: dynamic processor (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
duguyihou authored Sep 7, 2024
1 parent 82c2290 commit 7539fa4
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions ios/TurboImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,16 @@ final class TurboImageView : UIView {
override func didSetProps(_ changedProps: [String]!) {
super.didSetProps(changedProps)

if changedProps.contains("source") {
if placeholder != nil {
lazyImageView.transition = .none
} else {
lazyImageView.transition =
.fadeIn(duration: (fadeDuration.doubleValue) / 1000)
}
lazyImageView.processors = processors

if !Set(["source", "resize", "blur","monochrome", "tint"])
.intersection(changedProps).isEmpty {
loadImage()
}
}
Expand All @@ -182,21 +191,10 @@ final class TurboImageView : UIView {

fileprivate extension TurboImageView {
func loadImage() {
defer {
if let imageRequest {
lazyImageView.request = imageRequest
}
}

if placeholder != nil {
lazyImageView.transition = .none
} else {
lazyImageView.transition =
.fadeIn(duration: (fadeDuration.doubleValue) / 1000)
}

registerObservers()
lazyImageView.processors = processors
if let imageRequest {
lazyImageView.request = imageRequest
}
}
}

Expand Down Expand Up @@ -282,7 +280,7 @@ fileprivate extension TurboImageView {
"inputIntensity": 1,
"inputColor": CIColor(color: monochrome)
] as [String : Any]
let identifier = "turboImage.monochrome"
let identifier = "turboImage.monochrome.\(monochrome)"
initialProcessors.append(
ImageProcessors.CoreImageFilter(name: name,
parameters: parameters,
Expand All @@ -291,7 +289,7 @@ fileprivate extension TurboImageView {

if let tint {
let tintProcessor = ImageProcessors
.Anonymous(id: "turboImage.tint") { image in
.Anonymous(id: "turboImage.tint.\(tint)") { image in
image.withTintColor(tint)
}
initialProcessors.append(tintProcessor)
Expand Down

0 comments on commit 7539fa4

Please sign in to comment.