Skip to content

Commit

Permalink
feat(iOS): tint color (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
duguyihou authored Nov 19, 2023
1 parent 486c20f commit 13de94a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function App() {
fadeDuration={10}
base64Placeholder={base64Placeholder}
rounded
tintColor="red"
onSuccess={handleOnSuccess}
onError={handleOnError}
/>
Expand Down
12 changes: 10 additions & 2 deletions ios/TurboImage/TurboImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class TurboImageView : UIView {
}
}

@objc var tint: UIColor = .clear

override init(frame: CGRect) {
super.init(frame: frame)
addSubview(lazyImageView)
Expand Down Expand Up @@ -76,7 +78,7 @@ fileprivate extension TurboImageView {
guard let url = URL(string: url!)
else { return }

let processor = composeProcessor(rounded)
let processor = composeProcessor(tint, rounded)

KF.url(url)
.fade(duration: TimeInterval(truncating: fadeDuration))
Expand All @@ -91,11 +93,17 @@ fileprivate extension TurboImageView {
.set(to: lazyImageView)
}

func composeProcessor(_ rounded: Bool?) -> ImageProcessor {
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
}
}
2 changes: 2 additions & 0 deletions ios/TurboImage/TurboImageViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ @interface RCT_EXTERN_MODULE(TurboImageViewManager, RCTViewManager)

RCT_EXPORT_VIEW_PROPERTY(rounded, BOOL)

RCT_REMAP_VIEW_PROPERTY(tintColor, tint, UIColor)

RCT_EXPORT_VIEW_PROPERTY(onSuccess, RCTDirectEventBlock)

RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock)
Expand Down
1 change: 1 addition & 0 deletions src/TurboImage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface TurboImageProps extends AccessibilityProps, ViewProps {
base64Placeholder?: string;
fadeDuration?: number;
rounded?: boolean;
tintColor?: string;
onSuccess?: () => void;
onError?: (error: any) => void;
ref?: React.Ref<any>;
Expand Down

0 comments on commit 13de94a

Please sign in to comment.