Skip to content

Commit e615b98

Browse files
authored
Merge pull request #6 from rmrs/add_photo_timestamp_prop
Add photo timestamp prop
2 parents fbdc164 + 1a29c92 commit e615b98

File tree

13 files changed

+422
-16
lines changed

13 files changed

+422
-16
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ https://github.com/invertase/react-native-firebase
1616

1717
For iOS add the following pod to your podfile:
1818
```
19-
pod 'FirebaseUI/Storage'
19+
pod 'SDWebImage', '~> 4.0'
2020
```
2121
and run pod install.
2222

@@ -75,6 +75,7 @@ export class MyFirebaseImageView extends Component<void, void, void> {
7575
<ImageView
7676
{...imageProps}
7777
path='firebase/storage/path'
78+
timestamp={0} //optional, can be used to specify last modified time for same storage path
7879
resizeMode='cover' //'cover', 'contain', 'stretch'
7980
/>
8081
)
@@ -94,6 +95,7 @@ export class MyFirebasePhotoView extends Component<void, void, void> {
9495
<PhotoView
9596
{...imageProps}
9697
path='firebase/storage/path'
98+
timestamp={0} //optional, can be used to specify last modified time for same storage path
9799
resizeMode='cover' //'cover', 'contain', 'stretch'
98100
/>
99101
)

android/src/main/java/io/rumors/reactnativefirebaseui/storage/ExtendedImageView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.bumptech.glide.load.resource.bitmap.FitCenter;
1818
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
1919
import com.bumptech.glide.load.MultiTransformation;
20+
import com.bumptech.glide.signature.MediaStoreSignature;
2021
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
2122

2223
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@@ -27,6 +28,7 @@ public class ExtendedImageView extends ImageView {
2728
protected String mPath = null;
2829
protected Map<CornerType, Integer> mBorderRadii = new HashMap<CornerType, Integer>();
2930
protected ScaleType mScaleType;
31+
protected long mTimestamp = 0;
3032

3133
protected ThemedReactContext mContext = null;
3234

@@ -39,6 +41,10 @@ public void setPath(String path) {
3941
mPath = path;
4042
}
4143

44+
public void setTimestamp(long timestamp) {
45+
mTimestamp = timestamp;
46+
}
47+
4248
@Override
4349
public void setScaleType(ScaleType scaleType) {
4450
mScaleType = scaleType;
@@ -73,6 +79,8 @@ public void updateView() {
7379
GlideApp.with(mContext)
7480
.load(storageReference)
7581
.apply(bitmapTransform(multi))
82+
//(String mimeType, long dateModified, int orientation)
83+
.signature(new MediaStoreSignature("", mTimestamp, 0))
7684
.into(this);
7785
}
7886
}

android/src/main/java/io/rumors/reactnativefirebaseui/storage/ExtendedPhotoView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.bumptech.glide.load.resource.bitmap.FitCenter;
1818
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
1919
import com.bumptech.glide.load.MultiTransformation;
20+
import com.bumptech.glide.signature.MediaStoreSignature;
2021
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
2122

2223
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@@ -27,6 +28,7 @@ public class ExtendedPhotoView extends PhotoView {
2728
protected String mPath = null;
2829
protected Map<CornerType, Integer> mBorderRadii = new HashMap<CornerType, Integer>();
2930
protected ScaleType mScaleType;
31+
protected long mTimestamp = 0;
3032

3133
protected ThemedReactContext mContext = null;
3234

@@ -39,6 +41,10 @@ public void setPath(String path) {
3941
mPath = path;
4042
}
4143

44+
public void setTimestamp(long timestamp) {
45+
mTimestamp = timestamp;
46+
}
47+
4248
@Override
4349
public void setScaleType(ScaleType scaleType) {
4450
mScaleType = scaleType;
@@ -72,6 +78,8 @@ public void updateView() {
7278
GlideApp.with(mContext)
7379
.load(storageReference)
7480
.apply(bitmapTransform(multi))
81+
//(String mimeType, long dateModified, int orientation)
82+
.signature(new MediaStoreSignature("", mTimestamp, 0))
7583
.into(this);
7684
}
7785
}

android/src/main/java/io/rumors/reactnativefirebaseui/storage/FirebaseImageViewManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public void setPath(ExtendedImageView imageView, @Nullable String path) {
3232
imageView.setPath(path);
3333
}
3434

35+
@ReactProp(name = "timestamp")
36+
public void setTimestamp(ExtendedImageView imageView, @Nullable double timestamp) {
37+
imageView.setTimestamp((long)timestamp);
38+
}
39+
3540
@ReactProp(name = ViewProps.RESIZE_MODE)
3641
public void setResizeMode(ExtendedImageView imageView, @Nullable String resizeMode) {
3742
ScaleType scaleType = ScaleType.CENTER_INSIDE;

android/src/main/java/io/rumors/reactnativefirebaseui/storage/FirebasePhotoViewManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public void setPath(ExtendedPhotoView imageView, @Nullable String path) {
3333
imageView.setPath(path);
3434
}
3535

36+
@ReactProp(name = "timestamp")
37+
public void setTimestamp(ExtendedImageView imageView, @Nullable double timestamp) {
38+
imageView.setTimestamp((long)timestamp);
39+
}
40+
3641
@ReactProp(name = ViewProps.RESIZE_MODE)
3742
public void setResizeMode(ExtendedPhotoView imageView, @Nullable String resizeMode) {
3843
ScaleType scaleType = ScaleType.CENTER_INSIDE;

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var iface = {
66
propTypes: {
77
...Image.propTypes,
88
path: PropTypes.string,
9+
timestamp: PropTypes.number,
910
resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
1011
},
1112
}

ios/FirebaseUIImageView.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
//
88

99
#import "Firebase.h"
10-
#import <FirebaseStorageUI/FirebaseStorageUI.h>
1110

1211
#import <React/RCTResizeMode.h>
1312

1413
@interface FirebaseImageView : UIImageView
1514

1615
@property (nonatomic, copy) NSString *path;
16+
@property (nonatomic, strong) NSNumber *timestamp;
1717
@property (nonatomic, assign) RCTResizeMode resizeMode;
1818

1919
@end
20-

ios/FirebaseUIImageView.m

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,32 @@
99

1010
#import "FirebaseUIImageView.h"
1111
#import "Firebase.h"
12-
#import <FirebaseStorageUI/FirebaseStorageUI.h>
12+
#import "UIImageView+FirebaseStorage.h"
1313

1414
@implementation FirebaseImageView
15+
{
16+
BOOL _needsReload;
17+
}
1518

1619
- (void)setPath:(NSString *)path
1720
{
1821
_path = path;
19-
20-
// Reference to an image file in Firebase Storage
21-
FIRStorageReference *reference = [[FIRStorage storage] referenceWithPath:_path];
22-
23-
// Placeholder image
24-
UIImage *placeholderImage;
25-
26-
// Load the image using SDWebImage
27-
[self sd_setImageWithStorageReference:reference placeholderImage:placeholderImage];
22+
23+
_needsReload = YES;
24+
}
25+
26+
-(void)setTimestamp:(NSNumber*)timestamp
27+
{
28+
_timestamp = timestamp;
29+
30+
_needsReload = YES;
2831
}
2932

3033
- (void)setResizeMode:(RCTResizeMode)resizeMode
3134
{
3235
if (_resizeMode != resizeMode) {
3336
_resizeMode = resizeMode;
34-
37+
3538
if (_resizeMode == RCTResizeModeRepeat) {
3639
// Repeat resize mode is handled by the UIImage. Use scale to fill
3740
// so the repeated image fills the UIImageView.
@@ -44,4 +47,22 @@ - (void)setResizeMode:(RCTResizeMode)resizeMode
4447
}
4548
}
4649

50+
- (void)didSetProps:(NSArray<NSString *> *)changedProps
51+
{
52+
if (_needsReload) {
53+
[self reloadImage];
54+
}
55+
}
56+
57+
-(void)reloadImage
58+
{
59+
_needsReload = NO;
60+
// Reference to an image file in Firebase Storage
61+
FIRStorageReference *reference = [[FIRStorage storage] referenceWithPath:_path];
62+
63+
// Load the image using SDWebImage
64+
NSString* timestamp = [_timestamp stringValue];
65+
[self sd_setImageWithStorageReference:reference customKey:timestamp];
66+
}
67+
4768
@end

ios/RCTFirebaseImageViewManager.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ @implementation RCTFirebaseImageViewManager
1414

1515
RCT_EXPORT_MODULE()
1616
RCT_EXPORT_VIEW_PROPERTY(path, NSString)
17+
RCT_EXPORT_VIEW_PROPERTY(timestamp, NSNumber)
1718
RCT_EXPORT_VIEW_PROPERTY(resizeMode, RCTResizeMode)
1819

20+
1921
- (UIView *)view
2022
{
2123
FirebaseImageView *imageView = [[FirebaseImageView alloc] init];
22-
24+
2325
return imageView;
2426
}
2527

ios/RNFirebaseUi.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
B3E7B58A1CC2AC0600A0062D /* RCTFirebaseImageViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RCTFirebaseImageViewManager.m */; };
1111
BA04DF251F1506A800122A3C /* FirebaseUIImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = BA04DF241F1506A800122A3C /* FirebaseUIImageView.m */; };
12+
BAC95E541FA3D2C400E33F4D /* UIImageView+FirebaseStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC95E511FA3D2C300E33F4D /* UIImageView+FirebaseStorage.m */; };
1213
/* End PBXBuildFile section */
1314

1415
/* Begin PBXCopyFilesBuildPhase section */
@@ -29,6 +30,8 @@
2930
BA04DF241F1506A800122A3C /* FirebaseUIImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FirebaseUIImageView.m; sourceTree = "<group>"; };
3031
BA04DF261F1506CE00122A3C /* FirebaseUIImageView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirebaseUIImageView.h; sourceTree = "<group>"; };
3132
BA43A3101F14BB0300791965 /* RCTFirebaseImageViewManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTFirebaseImageViewManager.h; sourceTree = "<group>"; };
33+
BAC95E511FA3D2C300E33F4D /* UIImageView+FirebaseStorage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+FirebaseStorage.m"; sourceTree = "<group>"; };
34+
BAC95E531FA3D2C300E33F4D /* UIImageView+FirebaseStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+FirebaseStorage.h"; sourceTree = "<group>"; };
3235
/* End PBXFileReference section */
3336

3437
/* Begin PBXFrameworksBuildPhase section */
@@ -53,6 +56,8 @@
5356
58B511D21A9E6C8500147676 = {
5457
isa = PBXGroup;
5558
children = (
59+
BAC95E531FA3D2C300E33F4D /* UIImageView+FirebaseStorage.h */,
60+
BAC95E511FA3D2C300E33F4D /* UIImageView+FirebaseStorage.m */,
5661
BA04DF261F1506CE00122A3C /* FirebaseUIImageView.h */,
5762
BA04DF241F1506A800122A3C /* FirebaseUIImageView.m */,
5863
B3E7B5891CC2AC0600A0062D /* RCTFirebaseImageViewManager.m */,
@@ -119,6 +124,7 @@
119124
files = (
120125
B3E7B58A1CC2AC0600A0062D /* RCTFirebaseImageViewManager.m in Sources */,
121126
BA04DF251F1506A800122A3C /* FirebaseUIImageView.m in Sources */,
127+
BAC95E541FA3D2C400E33F4D /* UIImageView+FirebaseStorage.m in Sources */,
122128
);
123129
runOnlyForDeploymentPostprocessing = 0;
124130
};

0 commit comments

Comments
 (0)