From af111ab2ac0146befc8568be0904770f44f11d27 Mon Sep 17 00:00:00 2001 From: Aaron Chiu Date: Mon, 30 Jan 2017 23:18:07 -0800 Subject: [PATCH] pass AbstractDraweeControllerBuilder and CallerContext to Nodes Reviewed By: yungsters Differential Revision: D4487352 fbshipit-source-id: cf4540a5b2f8fc1444ff7ff0ce2ce280538f4f7b --- .../react/flat/FlatUIImplementation.java | 31 +++++++++---------- .../react/flat/RCTImageViewManager.java | 30 ++++++++++++++++++ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java index 3b9d6e9c7..c5211b7d1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java @@ -14,7 +14,6 @@ import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; -import com.facebook.yoga.YogaDirection; import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactApplicationContext; @@ -26,7 +25,7 @@ import com.facebook.react.uimanager.UIImplementation; import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManagerRegistry; import com.facebook.react.uimanager.events.EventDispatcher; -import com.facebook.react.views.image.ReactImageManager; +import com.facebook.yoga.YogaDirection; /** * FlatUIImplementation builds on top of UIImplementation and allows pre-creating everything @@ -40,9 +39,9 @@ public class FlatUIImplementation extends UIImplementation { List viewManagers, EventDispatcher eventDispatcher) { - ReactImageManager reactImageManager = findReactImageManager(viewManagers); - if (reactImageManager != null) { - Object callerContext = reactImageManager.getCallerContext(); + RCTImageViewManager rctImageViewManager = findRCTImageManager(viewManagers); + if (rctImageViewManager != null) { + Object callerContext = rctImageViewManager.getCallerContext(); if (callerContext != null) { RCTImageView.setCallerContext(callerContext); } @@ -59,7 +58,7 @@ public class FlatUIImplementation extends UIImplementation { nativeViewHierarchyManager); return new FlatUIImplementation( reactContext, - reactImageManager, + rctImageViewManager, viewManagerRegistry, operationsQueue, eventDispatcher @@ -71,32 +70,32 @@ public class FlatUIImplementation extends UIImplementation { * Not used outside of the said method. */ private final MoveProxy mMoveProxy = new MoveProxy(); - private final StateBuilder mStateBuilder; - private @Nullable ReactImageManager mReactImageManager; private final ReactApplicationContext mReactContext; + private @Nullable RCTImageViewManager mRCTImageViewManager; + private final StateBuilder mStateBuilder; private FlatUIImplementation( ReactApplicationContext reactContext, - @Nullable ReactImageManager reactImageManager, + @Nullable RCTImageViewManager rctImageViewManager, ViewManagerRegistry viewManagers, FlatUIViewOperationQueue operationsQueue, EventDispatcher eventDispatcher) { super(reactContext, viewManagers, operationsQueue, eventDispatcher); mReactContext = reactContext; + mRCTImageViewManager = rctImageViewManager; mStateBuilder = new StateBuilder(operationsQueue); - mReactImageManager = reactImageManager; } @Override protected ReactShadowNode createRootShadowNode() { - if (mReactImageManager != null) { + if (mRCTImageViewManager != null) { // This is not the best place to initialize DraweeRequestHelper, but order of module // initialization is undefined, and this is pretty much the earliest when we are guarantied // that Fresco is initalized and DraweeControllerBuilder can be queried. This also happens // relatively rarely to have any performance considerations. DraweeRequestHelper.setDraweeControllerBuilder( - mReactImageManager.getDraweeControllerBuilder()); - mReactImageManager = null; + mRCTImageViewManager.getDraweeControllerBuilder()); + mRCTImageViewManager = null; } ReactShadowNode node = new FlatRootShadowNode(); @@ -547,10 +546,10 @@ public class FlatUIImplementation extends UIImplementation { blockNativeResponder); } - private static @Nullable ReactImageManager findReactImageManager(List viewManagers) { + private static @Nullable RCTImageViewManager findRCTImageManager(List viewManagers) { for (int i = 0, size = viewManagers.size(); i != size; ++i) { - if (viewManagers.get(i) instanceof ReactImageManager) { - return (ReactImageManager) viewManagers.get(i); + if (viewManagers.get(i) instanceof RCTImageViewManager) { + return (RCTImageViewManager) viewManagers.get(i); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageViewManager.java index c697be207..9b06476d2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageViewManager.java @@ -9,8 +9,27 @@ package com.facebook.react.flat; +import javax.annotation.Nullable; + +import com.facebook.drawee.backends.pipeline.Fresco; +import com.facebook.drawee.controller.AbstractDraweeControllerBuilder; + public final class RCTImageViewManager extends FlatViewManager { + private @Nullable AbstractDraweeControllerBuilder mDraweeControllerBuilder; + private final @Nullable Object mCallerContext; + + public RCTImageViewManager() { + this(null, null); + } + + public RCTImageViewManager( + AbstractDraweeControllerBuilder draweeControllerBuilder, + Object callerContext) { + mDraweeControllerBuilder = draweeControllerBuilder; + mCallerContext = callerContext; + } + @Override public String getName() { return "RCTImageView"; @@ -25,4 +44,15 @@ public final class RCTImageViewManager extends FlatViewManager { public Class getShadowNodeClass() { return RCTImageView.class; } + + public AbstractDraweeControllerBuilder getDraweeControllerBuilder() { + if (mDraweeControllerBuilder == null) { + mDraweeControllerBuilder = Fresco.newDraweeControllerBuilder(); + } + return mDraweeControllerBuilder; + } + + public Object getCallerContext() { + return mCallerContext; + } }