Skip to content

Commit b4f5712

Browse files
authored
Merge pull request #16 from IjzerenHein/feature-defaultsource
Feature: Support placeholder images (defaultSource prop)
2 parents 6989f3f + f6f4941 commit b4f5712

22 files changed

+146
-30
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"javascript.preferences.quoteStyle": "single",
3+
"editor.formatOnSave": false
4+
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class MyFirebaseImageView extends Component<void, void, void> {
7575
<ImageView
7676
{...imageProps}
7777
path='firebase/storage/path'
78+
defaultSource={require('./placeholder.png')} // optional, show placeholder until image is loaded
7879
timestamp={0} //optional, can be used to specify last modified time for same storage path
7980
resizeMode='cover' //'cover', 'contain', 'stretch'
8081
/>
@@ -95,10 +96,13 @@ export class MyFirebasePhotoView extends Component<void, void, void> {
9596
<PhotoView
9697
{...imageProps}
9798
path='firebase/storage/path'
99+
defaultSource={require('./placeholder.png')} // optional, show placeholder until image is loaded
98100
timestamp={0} //optional, can be used to specify last modified time for same storage path
99101
resizeMode='cover' //'cover', 'contain', 'stretch'
100102
/>
101103
)
102104
}
103105
}
104106
```
107+
108+
> Note: On Android, the `defaultSource` prop is ignored on debug builds.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
import java.util.HashMap;
66
import java.util.ArrayList;
77

8+
import javax.annotation.Nullable;
9+
810
import android.widget.ImageView;
911
import android.widget.ImageView.ScaleType;
12+
import android.graphics.drawable.Drawable;
1013

1114
import com.facebook.react.uimanager.ThemedReactContext;
15+
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
1216
import com.firebase.ui.storage.images.FirebaseImageLoader;
1317
import com.google.firebase.storage.StorageReference;
1418
import com.google.firebase.storage.FirebaseStorage;
@@ -26,6 +30,7 @@
2630

2731
public class ExtendedImageView extends ImageView {
2832
protected String mPath = null;
33+
protected @Nullable Drawable mDefaultImageDrawable;
2934
protected Map<CornerType, Integer> mBorderRadii = new HashMap<CornerType, Integer>();
3035
protected ScaleType mScaleType;
3136
protected long mTimestamp = 0;
@@ -41,6 +46,10 @@ public void setPath(String path) {
4146
mPath = path;
4247
}
4348

49+
public void setDefaultSource(String name) {
50+
mDefaultImageDrawable = ResourceDrawableIdHelper.getInstance().getResourceDrawable(getContext(), name);
51+
}
52+
4453
public void setTimestamp(long timestamp) {
4554
mTimestamp = timestamp;
4655
}
@@ -78,6 +87,7 @@ public void updateView() {
7887

7988
GlideApp.with(mContext)
8089
.load(storageReference)
90+
.placeholder(mDefaultImageDrawable)
8191
.apply(bitmapTransform(multi))
8292
//(String mimeType, long dateModified, int orientation)
8393
.signature(new MediaStoreSignature("", mTimestamp, 0))

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
import java.util.HashMap;
66
import java.util.ArrayList;
77

8+
import javax.annotation.Nullable;
9+
810
import com.github.chrisbanes.photoview.PhotoView;
911
import android.widget.ImageView.ScaleType;
12+
import android.graphics.drawable.Drawable;
1013

1114
import com.facebook.react.uimanager.ThemedReactContext;
15+
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
1216
import com.firebase.ui.storage.images.FirebaseImageLoader;
1317
import com.google.firebase.storage.StorageReference;
1418
import com.google.firebase.storage.FirebaseStorage;
@@ -26,6 +30,7 @@
2630

2731
public class ExtendedPhotoView extends PhotoView {
2832
protected String mPath = null;
33+
protected @Nullable Drawable mDefaultImageDrawable;
2934
protected Map<CornerType, Integer> mBorderRadii = new HashMap<CornerType, Integer>();
3035
protected ScaleType mScaleType;
3136
protected long mTimestamp = 0;
@@ -41,6 +46,10 @@ public void setPath(String path) {
4146
mPath = path;
4247
}
4348

49+
public void setDefaultSource(String name) {
50+
mDefaultImageDrawable = ResourceDrawableIdHelper.getInstance().getResourceDrawable(getContext(), name);
51+
}
52+
4453
public void setTimestamp(long timestamp) {
4554
mTimestamp = timestamp;
4655
}
@@ -77,6 +86,7 @@ public void updateView() {
7786

7887
GlideApp.with(mContext)
7988
.load(storageReference)
89+
.placeholder(mDefaultImageDrawable)
8090
.apply(bitmapTransform(multi))
8191
//(String mimeType, long dateModified, int orientation)
8292
.signature(new MediaStoreSignature("", mTimestamp, 0))

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 = "defaultSource")
36+
public void setDefaultSource(ExtendedImageView imageView, @Nullable String source) {
37+
imageView.setDefaultSource(source);
38+
}
39+
3540
@ReactProp(name = "timestamp")
3641
public void setTimestamp(ExtendedImageView imageView, @Nullable double timestamp) {
3742
imageView.setTimestamp((long)timestamp);

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 = "defaultSource")
37+
public void setDefaultSource(ExtendedPhotoView imageView, @Nullable String source) {
38+
imageView.setDefaultSource(source);
39+
}
40+
3641
@ReactProp(name = "timestamp")
3742
public void setTimestamp(ExtendedPhotoView imageView, @Nullable double timestamp) {
3843
imageView.setTimestamp((long)timestamp);

example/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ end_of_line = lf
88
charset = utf-8
99
trim_trailing_whitespace = true
1010
insert_final_newline = true
11+
12+
[*.js]
13+
quote_type = single

example/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MyFirebaseImageView extends Component {
1111
<ImageView
1212
{...imageProps}
1313
path='images/firebase_logo.png'
14+
defaultSource={require('./assets/placeholder.png')}
1415
timestamp={1000} //optional, can be used to specify last modified time for same storage path
1516
resizeMode='cover' //'cover', 'contain', 'stretch'
1617
/>
@@ -27,6 +28,7 @@ class MyFirebasePhotoView extends Component {
2728
<PhotoView
2829
{...imageProps}
2930
path='images/firebase_logo.png'
31+
defaultSource={require('./assets/placeholder.png')}
3032
timestamp={1000} //optional, can be used to specify last modified time for same storage path
3133
resizeMode='cover' //'cover', 'contain', 'stretch'
3234
/>

example/android/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ android {
132132
release {
133133
minifyEnabled enableProguardInReleaseBuilds
134134
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
135+
signingConfig signingConfigs.debug
135136
}
136137
debug {
137138
minifyEnabled false

example/assets/placeholder.png

6.03 KB
Loading

0 commit comments

Comments
 (0)