Skip to content

Commit 0fde399

Browse files
committed
fix(android): fixed border-radius no longer working for image-view
1 parent 8d50c4f commit 0fde399

File tree

3 files changed

+19
-131
lines changed

3 files changed

+19
-131
lines changed

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

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,20 @@
11
package io.rumors.reactnativefirebaseui.storage;
22

3-
import java.util.Map;
4-
import java.util.Map.Entry;
5-
import java.util.HashMap;
6-
import java.util.ArrayList;
7-
83
import javax.annotation.Nullable;
94

105
import android.widget.ImageView;
11-
import android.widget.ImageView.ScaleType;
126
import android.graphics.drawable.Drawable;
137

148
import com.facebook.react.uimanager.ThemedReactContext;
159
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
16-
import com.firebase.ui.storage.images.FirebaseImageLoader;
1710
import com.google.firebase.storage.StorageReference;
1811
import com.google.firebase.storage.FirebaseStorage;
1912
import com.bumptech.glide.Glide;
20-
import com.bumptech.glide.load.Transformation;
21-
import com.bumptech.glide.load.resource.bitmap.FitCenter;
22-
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
23-
import com.bumptech.glide.load.MultiTransformation;
2413
import com.bumptech.glide.signature.MediaStoreSignature;
25-
import com.bumptech.glide.request.RequestOptions;
26-
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
27-
28-
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
29-
import jp.wasabeef.glide.transformations.RoundedCornersTransformation.CornerType;
30-
3114

3215
public class ExtendedImageView extends ImageView {
3316
protected String mPath = null;
3417
protected @Nullable Drawable mDefaultImageDrawable;
35-
protected Map<CornerType, Integer> mBorderRadii = new HashMap<CornerType, Integer>();
36-
protected ScaleType mScaleType;
3718
protected long mTimestamp = 0;
3819

3920
protected ThemedReactContext mContext = null;
@@ -55,78 +36,12 @@ public void setTimestamp(long timestamp) {
5536
mTimestamp = timestamp;
5637
}
5738

58-
@Override
59-
public void setScaleType(ScaleType scaleType) {
60-
mScaleType = scaleType;
61-
}
62-
63-
public void setBorderRadius(int borderRadius, CornerType cornerType) {
64-
mBorderRadii.put(cornerType, borderRadius);
65-
}
66-
67-
static Integer getCommonBorderRadii(Map<CornerType, Integer> borderRadii) {
68-
int borderRadiiCount = 0;
69-
Integer borderRadius = 0;
70-
for (Entry<CornerType, Integer> entry : borderRadii.entrySet()) {
71-
CornerType cornerType = entry.getKey();
72-
Integer radius = entry.getValue();
73-
if (borderRadiiCount == 0) {
74-
borderRadius = radius;
75-
} else if (radius != borderRadius) {
76-
return -1; // not the same
77-
}
78-
borderRadiiCount += (cornerType == RoundedCornersTransformation.CornerType.ALL) ? 4 : 1;
79-
}
80-
return ((borderRadiiCount == 0) || (borderRadiiCount >= 4)) ? borderRadius : -1;
81-
}
82-
8339
public void updateView() {
8440
StorageReference storageReference = FirebaseStorage.getInstance().getReference(mPath);
85-
FirebaseImageLoader imageLoader = new FirebaseImageLoader();
86-
87-
// When the border-radii are not all the same, apply the
88-
// rounded corner transformation directly on top of the
89-
// scaled bitmap.
90-
RequestOptions transform;
91-
if (ExtendedImageView.getCommonBorderRadii(mBorderRadii) < 0) {
92-
ArrayList<Transformation> transformations = new ArrayList<Transformation>(1 + mBorderRadii.size());
93-
94-
if (mScaleType == ScaleType.CENTER_CROP) {
95-
transformations.add(new CenterCrop());
96-
} else {
97-
transformations.add(new FitCenter());
98-
}
99-
100-
for (Entry<CornerType, Integer> entry : mBorderRadii.entrySet()) {
101-
CornerType cornerType = entry.getKey();
102-
Integer radius = entry.getValue();
103-
transformations.add(new RoundedCornersTransformation(radius, 0, cornerType));
104-
}
105-
106-
Transformation[] transformationsArray = transformations.toArray(new Transformation[transformations.size()]);
107-
108-
MultiTransformation multi = new MultiTransformation<>(transformationsArray);
109-
transform = bitmapTransform(multi);
110-
}
111-
112-
// When all border-radii are the same (or none are set)
113-
// then let the ImageView apply the scale-type. This causes the
114-
// underlying BitmapDrawable to use the original bitmap and makes
115-
// it possible to do shared element transitions on this view.
116-
else {
117-
transform = null;
118-
super.setScaleType(mScaleType);
119-
}
120-
121-
GlideRequest request = GlideApp.with(mContext)
41+
GlideApp.with(mContext)
12242
.load(storageReference)
123-
.placeholder(mDefaultImageDrawable);
124-
if (transform != null) {
125-
request = request.apply(transform);
126-
} else {
127-
request = request.dontTransform();
128-
}
129-
request
43+
.placeholder(mDefaultImageDrawable)
44+
.dontTransform()
13045
//(String mimeType, long dateModified, int orientation)
13146
.signature(new MediaStoreSignature("", mTimestamp, 0))
13247
.into(this);

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
import javax.annotation.Nullable;
44
import android.widget.ImageView.ScaleType;
55

6-
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
7-
86
import com.facebook.react.uimanager.ViewProps;
97
import com.facebook.react.uimanager.annotations.ReactProp;
10-
import com.facebook.react.uimanager.annotations.ReactPropGroup;
118
import com.facebook.react.uimanager.SimpleViewManager;
129
import com.facebook.react.uimanager.ThemedReactContext;
13-
import com.facebook.yoga.YogaConstants;
14-
import com.facebook.react.uimanager.PixelUtil;
15-
import com.facebook.react.uimanager.ThemedReactContext;
1610

1711
public class FirebaseImageViewManager extends SimpleViewManager<ExtendedImageView> {
1812
public static final String REACT_CLASS = "RCTFirebaseImageView";
@@ -54,40 +48,6 @@ public void setResizeMode(ExtendedImageView imageView, @Nullable String resizeMo
5448
imageView.setScaleType(scaleType);
5549
}
5650

57-
@ReactPropGroup(names = {
58-
ViewProps.BORDER_RADIUS,
59-
ViewProps.BORDER_TOP_LEFT_RADIUS,
60-
ViewProps.BORDER_TOP_RIGHT_RADIUS,
61-
ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
62-
ViewProps.BORDER_BOTTOM_LEFT_RADIUS
63-
}, defaultFloat = YogaConstants.UNDEFINED)
64-
public void setBorderRadius(ExtendedImageView imageView, int index, float borderRadius) {
65-
if (!YogaConstants.isUndefined(borderRadius)) {
66-
borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
67-
}
68-
69-
RoundedCornersTransformation.CornerType cornerType = RoundedCornersTransformation.CornerType.ALL;
70-
switch (index) {
71-
case 0:
72-
cornerType = RoundedCornersTransformation.CornerType.ALL;
73-
break;
74-
case 1:
75-
cornerType = RoundedCornersTransformation.CornerType.TOP_LEFT;
76-
break;
77-
case 2:
78-
cornerType = RoundedCornersTransformation.CornerType.TOP_RIGHT;
79-
break;
80-
case 3:
81-
cornerType = RoundedCornersTransformation.CornerType.BOTTOM_RIGHT;
82-
break;
83-
case 4:
84-
cornerType = RoundedCornersTransformation.CornerType.BOTTOM_LEFT;
85-
break;
86-
}
87-
88-
imageView.setBorderRadius(Math.round(borderRadius), cornerType);
89-
}
90-
9151
@Override
9252
protected void onAfterUpdateTransaction(ExtendedImageView imageView) {
9353
super.onAfterUpdateTransaction(imageView);

src/index.android.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// and defaultSource is converted to a uri that the
33
// native side can interpret
44
import React, { Component } from 'react'
5-
import { requireNativeComponent, Image, Platform } from 'react-native'
5+
import { requireNativeComponent, Image, View, StyleSheet } from 'react-native'
66
import iface from './interface'
77

88
const RCTFirebaseImageView = requireNativeComponent(
@@ -14,14 +14,27 @@ const RCTFirebasePhotoView = requireNativeComponent(
1414
iface
1515
)
1616

17+
const styles = StyleSheet.create({
18+
imageContainer: {
19+
overflow: 'hidden',
20+
},
21+
});
22+
1723
class ImageView extends Component {
1824
render() {
19-
let { defaultSource, ...otherProps } = this.props
25+
let { source, style, defaultSource, resizeMode, ...otherProps } = this.props
2026
defaultSource = defaultSource
2127
? Image.resolveAssetSource(defaultSource).uri
2228
: undefined
29+
resizeMode = resizeMode || (style ? style.resizeMode : undefined) || 'cover';
2330
return (
24-
<RCTFirebaseImageView {...otherProps} defaultSource={defaultSource} />
31+
<View style={[styles.imageContainer, style]}>
32+
<RCTFirebaseImageView
33+
style={StyleSheet.absoluteFill}
34+
defaultSource={defaultSource}
35+
resizeMode={resizeMode}
36+
{...otherProps} />
37+
</View>
2538
)
2639
}
2740
}

0 commit comments

Comments
 (0)