Skip to content

Commit

Permalink
pass AbstractDraweeControllerBuilder and CallerContext to Nodes
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D4487352

fbshipit-source-id: cf4540a5b2f8fc1444ff7ff0ce2ce280538f4f7b
  • Loading branch information
aaronechiu authored and nicktate committed Feb 9, 2017
1 parent 2bd5fc8 commit 672a08a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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;
Expand All @@ -26,7 +25,7 @@
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
Expand All @@ -40,9 +39,9 @@ public static FlatUIImplementation createInstance(
List<ViewManager> 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);
}
Expand All @@ -59,7 +58,7 @@ public static FlatUIImplementation createInstance(
nativeViewHierarchyManager);
return new FlatUIImplementation(
reactContext,
reactImageManager,
rctImageViewManager,
viewManagerRegistry,
operationsQueue,
eventDispatcher
Expand All @@ -71,32 +70,32 @@ public static FlatUIImplementation createInstance(
* 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();
Expand Down Expand Up @@ -547,10 +546,10 @@ public void setJSResponder(int possiblyVirtualReactTag, boolean blockNativeRespo
blockNativeResponder);
}

private static @Nullable ReactImageManager findReactImageManager(List<ViewManager> viewManagers) {
private static @Nullable RCTImageViewManager findRCTImageManager(List<ViewManager> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -25,4 +44,15 @@ public RCTImageView createShadowNodeInstance() {
public Class<RCTImageView> getShadowNodeClass() {
return RCTImageView.class;
}

public AbstractDraweeControllerBuilder getDraweeControllerBuilder() {
if (mDraweeControllerBuilder == null) {
mDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
}
return mDraweeControllerBuilder;
}

public Object getCallerContext() {
return mCallerContext;
}
}

0 comments on commit 672a08a

Please sign in to comment.