mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-13 09:21:46 +08:00
Implement DrawImage using Drawee
Summary: Alternative implementation of DrawImage using DraweeHierarchy instead of ImagePipeline directly. Yields same results, but potentially more stable. We'll run tests to measure performance of both. Reviewed By: ahmedre Differential Revision: D2746197
This commit is contained in:
committed by
Ahmed El-Helw
parent
2daf696064
commit
7075744b94
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.react.flat;
|
||||
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
|
||||
/* package */ final class DraweeRequestHelper {
|
||||
|
||||
private static GenericDraweeHierarchyBuilder sHierarchyBuilder;
|
||||
private static AbstractDraweeControllerBuilder sControllerBuilder;
|
||||
|
||||
/* package */ static void setResources(Resources resources) {
|
||||
sHierarchyBuilder = new GenericDraweeHierarchyBuilder(resources);
|
||||
}
|
||||
|
||||
/* package */ static void setDraweeControllerBuilder(AbstractDraweeControllerBuilder builder) {
|
||||
sControllerBuilder = builder;
|
||||
}
|
||||
|
||||
private final DraweeController mDraweeController;
|
||||
private int mAttachCounter;
|
||||
|
||||
/* package */ DraweeRequestHelper(ImageRequest imageRequest) {
|
||||
DraweeController controller = sControllerBuilder
|
||||
.setImageRequest(imageRequest)
|
||||
.setCallerContext(RCTImageView.getCallerContext())
|
||||
.build();
|
||||
|
||||
controller.setHierarchy(sHierarchyBuilder.build());
|
||||
|
||||
mDraweeController = controller;
|
||||
}
|
||||
|
||||
/* package */ void attach(FlatViewGroup.InvalidateCallback callback) {
|
||||
++mAttachCounter;
|
||||
if (mAttachCounter == 1) {
|
||||
getDrawable().setCallback(callback.get());
|
||||
mDraweeController.onAttach();
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ void detach() {
|
||||
--mAttachCounter;
|
||||
if (mAttachCounter == 0) {
|
||||
mDraweeController.onDetach();
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ GenericDraweeHierarchy getHierarchy() {
|
||||
return (GenericDraweeHierarchy) Assertions.assumeNotNull(mDraweeController.getHierarchy());
|
||||
}
|
||||
|
||||
/* package */ Drawable getDrawable() {
|
||||
return getHierarchy().getTopLevelDrawable();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user