Skip to content

Commit d023a3e

Browse files
committed
Added native support for defaultSource on Android
1 parent 810e743 commit d023a3e

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

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);

0 commit comments

Comments
 (0)