pass AbstractDraweeControllerBuilder and CallerContext to Nodes
Reviewed By: yungsters Differential Revision: D4487352 fbshipit-source-id: cf4540a5b2f8fc1444ff7ff0ce2ce280538f4f7b
This commit is contained in:
parent
49729e9d2c
commit
af111ab2ac
|
@ -14,7 +14,6 @@ import javax.annotation.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.facebook.yoga.YogaDirection;
|
|
||||||
import com.facebook.infer.annotation.Assertions;
|
import com.facebook.infer.annotation.Assertions;
|
||||||
import com.facebook.react.bridge.Callback;
|
import com.facebook.react.bridge.Callback;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
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.ViewManager;
|
||||||
import com.facebook.react.uimanager.ViewManagerRegistry;
|
import com.facebook.react.uimanager.ViewManagerRegistry;
|
||||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
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
|
* FlatUIImplementation builds on top of UIImplementation and allows pre-creating everything
|
||||||
|
@ -40,9 +39,9 @@ public class FlatUIImplementation extends UIImplementation {
|
||||||
List<ViewManager> viewManagers,
|
List<ViewManager> viewManagers,
|
||||||
EventDispatcher eventDispatcher) {
|
EventDispatcher eventDispatcher) {
|
||||||
|
|
||||||
ReactImageManager reactImageManager = findReactImageManager(viewManagers);
|
RCTImageViewManager rctImageViewManager = findRCTImageManager(viewManagers);
|
||||||
if (reactImageManager != null) {
|
if (rctImageViewManager != null) {
|
||||||
Object callerContext = reactImageManager.getCallerContext();
|
Object callerContext = rctImageViewManager.getCallerContext();
|
||||||
if (callerContext != null) {
|
if (callerContext != null) {
|
||||||
RCTImageView.setCallerContext(callerContext);
|
RCTImageView.setCallerContext(callerContext);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +58,7 @@ public class FlatUIImplementation extends UIImplementation {
|
||||||
nativeViewHierarchyManager);
|
nativeViewHierarchyManager);
|
||||||
return new FlatUIImplementation(
|
return new FlatUIImplementation(
|
||||||
reactContext,
|
reactContext,
|
||||||
reactImageManager,
|
rctImageViewManager,
|
||||||
viewManagerRegistry,
|
viewManagerRegistry,
|
||||||
operationsQueue,
|
operationsQueue,
|
||||||
eventDispatcher
|
eventDispatcher
|
||||||
|
@ -71,32 +70,32 @@ public class FlatUIImplementation extends UIImplementation {
|
||||||
* Not used outside of the said method.
|
* Not used outside of the said method.
|
||||||
*/
|
*/
|
||||||
private final MoveProxy mMoveProxy = new MoveProxy();
|
private final MoveProxy mMoveProxy = new MoveProxy();
|
||||||
private final StateBuilder mStateBuilder;
|
|
||||||
private @Nullable ReactImageManager mReactImageManager;
|
|
||||||
private final ReactApplicationContext mReactContext;
|
private final ReactApplicationContext mReactContext;
|
||||||
|
private @Nullable RCTImageViewManager mRCTImageViewManager;
|
||||||
|
private final StateBuilder mStateBuilder;
|
||||||
|
|
||||||
private FlatUIImplementation(
|
private FlatUIImplementation(
|
||||||
ReactApplicationContext reactContext,
|
ReactApplicationContext reactContext,
|
||||||
@Nullable ReactImageManager reactImageManager,
|
@Nullable RCTImageViewManager rctImageViewManager,
|
||||||
ViewManagerRegistry viewManagers,
|
ViewManagerRegistry viewManagers,
|
||||||
FlatUIViewOperationQueue operationsQueue,
|
FlatUIViewOperationQueue operationsQueue,
|
||||||
EventDispatcher eventDispatcher) {
|
EventDispatcher eventDispatcher) {
|
||||||
super(reactContext, viewManagers, operationsQueue, eventDispatcher);
|
super(reactContext, viewManagers, operationsQueue, eventDispatcher);
|
||||||
mReactContext = reactContext;
|
mReactContext = reactContext;
|
||||||
|
mRCTImageViewManager = rctImageViewManager;
|
||||||
mStateBuilder = new StateBuilder(operationsQueue);
|
mStateBuilder = new StateBuilder(operationsQueue);
|
||||||
mReactImageManager = reactImageManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReactShadowNode createRootShadowNode() {
|
protected ReactShadowNode createRootShadowNode() {
|
||||||
if (mReactImageManager != null) {
|
if (mRCTImageViewManager != null) {
|
||||||
// This is not the best place to initialize DraweeRequestHelper, but order of module
|
// 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
|
// 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
|
// that Fresco is initalized and DraweeControllerBuilder can be queried. This also happens
|
||||||
// relatively rarely to have any performance considerations.
|
// relatively rarely to have any performance considerations.
|
||||||
DraweeRequestHelper.setDraweeControllerBuilder(
|
DraweeRequestHelper.setDraweeControllerBuilder(
|
||||||
mReactImageManager.getDraweeControllerBuilder());
|
mRCTImageViewManager.getDraweeControllerBuilder());
|
||||||
mReactImageManager = null;
|
mRCTImageViewManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReactShadowNode node = new FlatRootShadowNode();
|
ReactShadowNode node = new FlatRootShadowNode();
|
||||||
|
@ -547,10 +546,10 @@ public class FlatUIImplementation extends UIImplementation {
|
||||||
blockNativeResponder);
|
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) {
|
for (int i = 0, size = viewManagers.size(); i != size; ++i) {
|
||||||
if (viewManagers.get(i) instanceof ReactImageManager) {
|
if (viewManagers.get(i) instanceof RCTImageViewManager) {
|
||||||
return (ReactImageManager) viewManagers.get(i);
|
return (RCTImageViewManager) viewManagers.get(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,27 @@
|
||||||
|
|
||||||
package com.facebook.react.flat;
|
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 {
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "RCTImageView";
|
return "RCTImageView";
|
||||||
|
@ -25,4 +44,15 @@ public final class RCTImageViewManager extends FlatViewManager {
|
||||||
public Class<RCTImageView> getShadowNodeClass() {
|
public Class<RCTImageView> getShadowNodeClass() {
|
||||||
return RCTImageView.class;
|
return RCTImageView.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractDraweeControllerBuilder getDraweeControllerBuilder() {
|
||||||
|
if (mDraweeControllerBuilder == null) {
|
||||||
|
mDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
|
||||||
|
}
|
||||||
|
return mDraweeControllerBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getCallerContext() {
|
||||||
|
return mCallerContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue