mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-06 00:43:38 +08:00
Backed out changeset 708058c5f244
Reviewed By: dmmiller Differential Revision: D3496881 fbshipit-source-id: 0f2e0d5769d09e0c70feceda7ff7d959e3a9ef2e
This commit is contained in:
committed by
Facebook Github Bot 9
parent
cbd8214b43
commit
f0f2645ec7
@@ -9,7 +9,6 @@ android_library(
|
||||
react_native_target('java/com/facebook/csslayout:csslayout'),
|
||||
react_native_target('java/com/facebook/react/uimanager:uimanager'),
|
||||
react_native_target('java/com/facebook/react/uimanager/annotations:annotations'),
|
||||
react_native_target('java/com/facebook/react/views/imagehelper:imagehelper'),
|
||||
react_native_dep('libraries/fresco/fresco-react-native:fbcore'),
|
||||
react_native_dep('libraries/fresco/fresco-react-native:fresco-react-native'),
|
||||
react_native_dep('libraries/fresco/fresco-react-native:fresco-drawee'),
|
||||
|
||||
@@ -37,6 +37,7 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
|
||||
return REACT_CLASS;
|
||||
}
|
||||
|
||||
private ResourceDrawableIdHelper mResourceDrawableIdHelper;
|
||||
private @Nullable AbstractDraweeControllerBuilder mDraweeControllerBuilder;
|
||||
private final @Nullable Object mCallerContext;
|
||||
|
||||
@@ -45,12 +46,14 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
|
||||
Object callerContext) {
|
||||
mDraweeControllerBuilder = draweeControllerBuilder;
|
||||
mCallerContext = callerContext;
|
||||
mResourceDrawableIdHelper = new ResourceDrawableIdHelper();
|
||||
}
|
||||
|
||||
public ReactImageManager() {
|
||||
// Lazily initialize as FrescoModule have not been initialized yet
|
||||
mDraweeControllerBuilder = null;
|
||||
mCallerContext = null;
|
||||
mResourceDrawableIdHelper = new ResourceDrawableIdHelper();
|
||||
}
|
||||
|
||||
public AbstractDraweeControllerBuilder getDraweeControllerBuilder() {
|
||||
@@ -69,7 +72,8 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
|
||||
return new ReactImageView(
|
||||
context,
|
||||
getDraweeControllerBuilder(),
|
||||
getCallerContext());
|
||||
getCallerContext(),
|
||||
mResourceDrawableIdHelper);
|
||||
}
|
||||
|
||||
// In JS this is Image.props.source
|
||||
|
||||
@@ -59,7 +59,6 @@ import com.facebook.react.common.SystemClock;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
|
||||
|
||||
/**
|
||||
* Wrapper class around Fresco's GenericDraweeView, enabling persisting props across multiple view
|
||||
@@ -191,7 +190,7 @@ public class ReactImageView extends GenericDraweeView {
|
||||
// ignore malformed uri, then attempt to extract resource ID.
|
||||
}
|
||||
if (mUri == null) {
|
||||
mUri = ResourceDrawableIdHelper.getInstance().getResourceDrawableUri(getContext(), mSource);
|
||||
mUri = mResourceDrawableIdHelper.getResourceDrawableUri(getContext(), mSource);
|
||||
mIsLocalImage = true;
|
||||
} else {
|
||||
mIsLocalImage = false;
|
||||
@@ -199,6 +198,7 @@ public class ReactImageView extends GenericDraweeView {
|
||||
}
|
||||
}
|
||||
|
||||
private final ResourceDrawableIdHelper mResourceDrawableIdHelper;
|
||||
private final List<ImageSource> mSources;
|
||||
|
||||
private @Nullable ImageSource mImageSource;
|
||||
@@ -229,12 +229,14 @@ public class ReactImageView extends GenericDraweeView {
|
||||
public ReactImageView(
|
||||
Context context,
|
||||
AbstractDraweeControllerBuilder draweeControllerBuilder,
|
||||
@Nullable Object callerContext) {
|
||||
@Nullable Object callerContext,
|
||||
ResourceDrawableIdHelper resourceDrawableIdHelper) {
|
||||
super(context, buildHierarchy(context));
|
||||
mScaleType = ImageResizeMode.defaultValue();
|
||||
mDraweeControllerBuilder = draweeControllerBuilder;
|
||||
mRoundedCornerPostprocessor = new RoundedCornerPostprocessor();
|
||||
mCallerContext = callerContext;
|
||||
mResourceDrawableIdHelper = resourceDrawableIdHelper;
|
||||
mSources = new LinkedList<>();
|
||||
}
|
||||
|
||||
@@ -342,7 +344,7 @@ public class ReactImageView extends GenericDraweeView {
|
||||
}
|
||||
|
||||
public void setLoadingIndicatorSource(@Nullable String name) {
|
||||
Drawable drawable = ResourceDrawableIdHelper.getInstance().getResourceDrawable(getContext(), name);
|
||||
Drawable drawable = mResourceDrawableIdHelper.getResourceDrawable(getContext(), name);
|
||||
mLoadingImageDrawable =
|
||||
drawable != null ? (Drawable) new AutoRotateDrawable(drawable, 1000) : null;
|
||||
mIsDirty = true;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.react.views.image;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.facebook.common.util.UriUtil;
|
||||
|
||||
/**
|
||||
* Helper class for obtaining information about local images.
|
||||
*/
|
||||
/* package */ class ResourceDrawableIdHelper {
|
||||
|
||||
private Map<String, Integer> mResourceDrawableIdMap;
|
||||
|
||||
public ResourceDrawableIdHelper() {
|
||||
mResourceDrawableIdMap = new HashMap<String, Integer>();
|
||||
}
|
||||
|
||||
public int getResourceDrawableId(Context context, @Nullable String name) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
name = name.toLowerCase().replace("-", "_");
|
||||
if (mResourceDrawableIdMap.containsKey(name)) {
|
||||
return mResourceDrawableIdMap.get(name);
|
||||
}
|
||||
int id = context.getResources().getIdentifier(
|
||||
name,
|
||||
"drawable",
|
||||
context.getPackageName());
|
||||
mResourceDrawableIdMap.put(name, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
public @Nullable Drawable getResourceDrawable(Context context, @Nullable String name) {
|
||||
int resId = getResourceDrawableId(context, name);
|
||||
return resId > 0 ? context.getResources().getDrawable(resId) : null;
|
||||
}
|
||||
|
||||
public Uri getResourceDrawableUri(Context context, @Nullable String name) {
|
||||
int resId = getResourceDrawableId(context, name);
|
||||
return resId > 0 ? new Uri.Builder()
|
||||
.scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
|
||||
.path(String.valueOf(resId))
|
||||
.build() : Uri.EMPTY;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user