Image with null source should still respect `style`
Summary: D8576087 has all the details. Merge conflict messed up the diff hence a new one. Reviewed By: yungsters Differential Revision: D8628053 fbshipit-source-id: 8b211864f8f9d6b56f9469396eaa1d8291bbb56f
This commit is contained in:
parent
04366a9867
commit
4ad13075c3
|
@ -190,9 +190,6 @@ let Image = (
|
||||||
props.loadingIndicatorSource,
|
props.loadingIndicatorSource,
|
||||||
);
|
);
|
||||||
|
|
||||||
// As opposed to the ios version, here we render `null` when there is no source, source.uri
|
|
||||||
// or source array.
|
|
||||||
|
|
||||||
if (source && source.uri === '') {
|
if (source && source.uri === '') {
|
||||||
console.warn('source.uri should not be an empty string');
|
console.warn('source.uri should not be an empty string');
|
||||||
}
|
}
|
||||||
|
@ -215,13 +212,9 @@ let Image = (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!source || (!source.uri && !Array.isArray(source))) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let style;
|
let style;
|
||||||
let sources;
|
let sources;
|
||||||
if (source.uri) {
|
if (source?.uri != null) {
|
||||||
const {width, height} = source;
|
const {width, height} = source;
|
||||||
style = flattenStyle([{width, height}, styles.base, props.style]);
|
style = flattenStyle([{width, height}, styles.base, props.style]);
|
||||||
sources = [{uri: source.uri}];
|
sources = [{uri: source.uri}];
|
||||||
|
@ -235,7 +228,7 @@ let Image = (
|
||||||
style,
|
style,
|
||||||
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd || onError),
|
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd || onError),
|
||||||
src: sources,
|
src: sources,
|
||||||
headers: source.headers,
|
headers: source?.headers,
|
||||||
defaultSrc: defaultSource ? defaultSource.uri : null,
|
defaultSrc: defaultSource ? defaultSource.uri : null,
|
||||||
loadingIndicatorSrc: loadingIndicatorSource
|
loadingIndicatorSrc: loadingIndicatorSource
|
||||||
? loadingIndicatorSource.uri
|
? loadingIndicatorSource.uri
|
||||||
|
|
|
@ -70,6 +70,9 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
|
|
||||||
public static final int REMOTE_IMAGE_FADE_DURATION_MS = 300;
|
public static final int REMOTE_IMAGE_FADE_DURATION_MS = 300;
|
||||||
|
|
||||||
|
public static final String REMOTE_TRANSPARENT_BITMAP_URI =
|
||||||
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
|
||||||
|
|
||||||
private static float[] sComputedCornerRadii = new float[4];
|
private static float[] sComputedCornerRadii = new float[4];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -338,7 +341,10 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
|
|
||||||
public void setSource(@Nullable ReadableArray sources) {
|
public void setSource(@Nullable ReadableArray sources) {
|
||||||
mSources.clear();
|
mSources.clear();
|
||||||
if (sources != null && sources.size() != 0) {
|
if (sources == null || sources.size() == 0) {
|
||||||
|
ImageSource imageSource = new ImageSource(getContext(), REMOTE_TRANSPARENT_BITMAP_URI);
|
||||||
|
mSources.add(imageSource);
|
||||||
|
} else {
|
||||||
// Optimize for the case where we have just one uri, case in which we don't need the sizes
|
// Optimize for the case where we have just one uri, case in which we don't need the sizes
|
||||||
if (sources.size() == 1) {
|
if (sources.size() == 1) {
|
||||||
ReadableMap source = sources.getMap(0);
|
ReadableMap source = sources.getMap(0);
|
||||||
|
@ -572,9 +578,9 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
private void setSourceImage() {
|
private void setSourceImage() {
|
||||||
mImageSource = null;
|
mImageSource = null;
|
||||||
if (mSources.isEmpty()) {
|
if (mSources.isEmpty()) {
|
||||||
return;
|
ImageSource imageSource = new ImageSource(getContext(), REMOTE_TRANSPARENT_BITMAP_URI);
|
||||||
}
|
mSources.add(imageSource);
|
||||||
if (hasMultipleSources()) {
|
} else if (hasMultipleSources()) {
|
||||||
MultiSourceResult multiSource =
|
MultiSourceResult multiSource =
|
||||||
MultiSourceHelper.getBestSourceForSize(getWidth(), getHeight(), mSources);
|
MultiSourceHelper.getBestSourceForSize(getWidth(), getHeight(), mSources);
|
||||||
mImageSource = multiSource.getBestResult();
|
mImageSource = multiSource.getBestResult();
|
||||||
|
@ -609,4 +615,3 @@ public class ReactImageView extends GenericDraweeView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue