Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blur radius for iOS #591

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/FastImage/FFFastImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@property (nonatomic, assign) RCTResizeMode resizeMode;
@property (nonatomic, strong) FFFastImageSource *source;
@property (nonatomic, strong) UIColor *imageColor;
@property (nonatomic, assign) CGFloat blurRadius;

@end

24 changes: 18 additions & 6 deletions ios/FastImage/FFFastImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ - (void)reloadImage
}
self.hasCompleted = YES;
[self sendOnLoad:image];

if (self.onFastImageLoadEnd) {
self.onFastImageLoadEnd(@{});
}
return;
}

// Set headers.
[_source.headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString* header, BOOL *stop) {
[[SDWebImageDownloader sharedDownloader] setValue:header forHTTPHeaderField:key];
}];

// Set priority.
SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageHandleCookies;
switch (_source.priority) {
Expand All @@ -159,7 +159,7 @@ - (void)reloadImage
options |= SDWebImageHighPriority;
break;
}

switch (_source.cacheControl) {
case FFFCacheControlWeb:
options |= SDWebImageRefreshCached;
Expand All @@ -170,7 +170,7 @@ - (void)reloadImage
case FFFCacheControlImmutable:
break;
}

if (self.onFastImageLoadStart) {
self.onFastImageLoadStart(@{});
self.hasSentOnLoadStart = YES;
Expand All @@ -179,7 +179,7 @@ - (void)reloadImage
}
self.hasCompleted = NO;
self.hasErrored = NO;

[self downloadImage:_source options:options];
}
}
Expand Down Expand Up @@ -216,6 +216,18 @@ - (void)downloadImage:(FFFastImageSource *) source options:(SDWebImageOptions) o
}
}
}];
if (_blurRadius && _blurRadius > 0) {
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = self.bounds;
visualEffectView.alpha = 1 - (_blurRadius / 10);
visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[self addSubview:visualEffectView];
}
}

@end
Expand Down
1 change: 1 addition & 0 deletions ios/FastImage/FFFastImageViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ - (FFFastImageView*)view {
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoad, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoadEnd, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(tintColor, imageColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(blurRadius, CGFloat)

RCT_EXPORT_METHOD(preload:(nonnull NSArray<FFFastImageSource *> *)sources)
{
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface OnProgressEvent {
export interface FastImageProperties {
source: FastImageSource | number
resizeMode?: FastImage.ResizeMode
blurRadius?: number
fallback?: boolean

onLoadStart?(): void
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function FastImageBase({
children,
fallback,
forwardedRef,
blurRadius,
...props
}) {
const resolvedSource = Image.resolveAssetSource(source)
Expand All @@ -38,6 +39,7 @@ function FastImageBase({
onLoad={onLoad}
onError={onError}
onLoadEnd={onLoadEnd}
blurRadius={blurRadius}
/>
{children}
</View>
Expand All @@ -56,6 +58,7 @@ function FastImageBase({
onFastImageLoad={onLoad}
onFastImageError={onError}
onFastImageLoadEnd={onLoadEnd}
blurRadius={blurRadius}
/>
{children}
</View>
Expand Down