Skip to content

Commit 810e743

Browse files
committed
Added defaultSource for IOS
1 parent 6989f3f commit 810e743

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

ios/FirebaseUIImageView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
@property (nonatomic, copy) NSString *path;
1616
@property (nonatomic, strong) NSNumber *timestamp;
1717
@property (nonatomic, assign) RCTResizeMode resizeMode;
18+
@property (nonatomic, strong) UIImage *defaultSource;
1819

1920
@end

ios/FirebaseUIImageView.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,29 @@ @implementation FirebaseImageView
1919
- (void)setPath:(NSString *)path
2020
{
2121
_path = path;
22+
23+
_needsReload = YES;
24+
}
2225

26+
- (void)setDefaultSource:(UIImage *)defaultSource
27+
{
28+
_defaultSource = defaultSource;
29+
2330
_needsReload = YES;
2431
}
2532

2633
-(void)setTimestamp:(NSNumber*)timestamp
2734
{
2835
_timestamp = timestamp;
29-
36+
3037
_needsReload = YES;
3138
}
3239

3340
- (void)setResizeMode:(RCTResizeMode)resizeMode
3441
{
3542
if (_resizeMode != resizeMode) {
3643
_resizeMode = resizeMode;
37-
44+
3845
if (_resizeMode == RCTResizeModeRepeat) {
3946
// Repeat resize mode is handled by the UIImage. Use scale to fill
4047
// so the repeated image fills the UIImageView.
@@ -59,10 +66,10 @@ -(void)reloadImage
5966
_needsReload = NO;
6067
// Reference to an image file in Firebase Storage
6168
FIRStorageReference *reference = [[FIRStorage storage] referenceWithPath:_path];
62-
69+
6370
// Load the image using SDWebImage
6471
NSString* timestamp = [_timestamp stringValue];
65-
[self sd_setImageWithStorageReference:reference customKey:timestamp];
72+
[self sd_setImageWithStorageReference:reference placeholderImage:_defaultSource customKey:timestamp];
6673
}
6774

6875
@end

ios/RCTFirebaseImageViewManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ @implementation RCTFirebaseImageViewManager
1616
RCT_EXPORT_VIEW_PROPERTY(path, NSString)
1717
RCT_EXPORT_VIEW_PROPERTY(timestamp, NSNumber)
1818
RCT_EXPORT_VIEW_PROPERTY(resizeMode, RCTResizeMode)
19-
19+
RCT_EXPORT_VIEW_PROPERTY(defaultSource, UIImage)
2020

2121
- (UIView *)view
2222
{
2323
FirebaseImageView *imageView = [[FirebaseImageView alloc] init];
24-
24+
2525
return imageView;
2626
}
2727

ios/UIImageView+FirebaseStorage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ NS_ASSUME_NONNULL_BEGIN
6060
* could not be found in cache).
6161
*/
6262
- (nullable FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef
63+
placeholderImage:(nullable UIImage *)placeholder
6364
customKey:(NSString*)customKey;
6465

6566
/**

ios/UIImageView+FirebaseStorage.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ - (FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference
3939
}
4040

4141
- (FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef
42+
placeholderImage:(nullable UIImage *)placeholder
4243
customKey:(NSString*)customKey {
4344
return [self sd_setImageWithStorageReference:storageRef
4445
maxImageSize:[UIImageView sd_defaultMaxImageSize]
45-
placeholderImage:nil
46+
placeholderImage:placeholder
4647
cache:[SDImageCache sharedImageCache]
4748
completion:nil
4849
customKey:customKey];

0 commit comments

Comments
 (0)