mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-04 09:27:53 +08:00
Implement Image.defaultSource property on Android
Summary: This pull request implements Image.defaultSource property on Android, using Fresco (http://frescolib.org/docs/placeholder-failure-retry.html), which will show placeholder image (local asset) while loading remote image. Implementation code is almost same with loadingIndicatorSource, but without rotation. This requires release or production to bundle local images in an APK file. This provides feature parity with iOS. Set Image.defaultSource on Android, and will show it while loading Image.source. ```JSX <Image defaultSource={require('<path to image>')} source={{uri: '<url to remote image>'}} style={{ height: 300, width: 300 }} /> ``` [ANDROID] [FEATURE] [IMAGE] - Image.defaultSource will show local image as placeholder while loading remote Image.source. Closes https://github.com/facebook/react-native/pull/18588 Differential Revision: D7540489 Pulled By: himabindugadupudi fbshipit-source-id: 908ceb659b3416e517bba64c76a31879d965ec09
This commit is contained in:
committed by
Facebook Github Bot
parent
bf7601fde1
commit
b0fa3228a7
@@ -88,6 +88,12 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
|
||||
view.setBlurRadius(blurRadius);
|
||||
}
|
||||
|
||||
// In JS this is Image.props.defaultSource
|
||||
@ReactProp(name = "defaultSrc")
|
||||
public void setDefaultSource(ReactImageView view, @Nullable String source) {
|
||||
view.setDefaultSource(source);
|
||||
}
|
||||
|
||||
// In JS this is Image.props.loadingIndicatorSource.uri
|
||||
@ReactProp(name = "loadingIndicatorSrc")
|
||||
public void setLoadingIndicatorSource(ReactImageView view, @Nullable String source) {
|
||||
|
||||
@@ -184,6 +184,7 @@ public class ReactImageView extends GenericDraweeView {
|
||||
|
||||
private @Nullable ImageSource mImageSource;
|
||||
private @Nullable ImageSource mCachedImageSource;
|
||||
private @Nullable Drawable mDefaultImageDrawable;
|
||||
private @Nullable Drawable mLoadingImageDrawable;
|
||||
private @Nullable RoundedColorDrawable mBackgroundImageDrawable;
|
||||
private int mBackgroundColor = 0x00000000;
|
||||
@@ -369,6 +370,11 @@ public class ReactImageView extends GenericDraweeView {
|
||||
mIsDirty = true;
|
||||
}
|
||||
|
||||
public void setDefaultSource(@Nullable String name) {
|
||||
mDefaultImageDrawable = ResourceDrawableIdHelper.getInstance().getResourceDrawable(getContext(), name);
|
||||
mIsDirty = true;
|
||||
}
|
||||
|
||||
public void setLoadingIndicatorSource(@Nullable String name) {
|
||||
Drawable drawable = ResourceDrawableIdHelper.getInstance().getResourceDrawable(getContext(), name);
|
||||
mLoadingImageDrawable =
|
||||
@@ -428,6 +434,10 @@ public class ReactImageView extends GenericDraweeView {
|
||||
GenericDraweeHierarchy hierarchy = getHierarchy();
|
||||
hierarchy.setActualImageScaleType(mScaleType);
|
||||
|
||||
if (mDefaultImageDrawable != null) {
|
||||
hierarchy.setPlaceholderImage(mDefaultImageDrawable, ScalingUtils.ScaleType.CENTER);
|
||||
}
|
||||
|
||||
if (mLoadingImageDrawable != null) {
|
||||
hierarchy.setPlaceholderImage(mLoadingImageDrawable, ScalingUtils.ScaleType.CENTER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user