Make AndroidView an interface

Summary:
The current AndroidView stipulates that the backing shadow node can't
be a FlatShadowNode. In some cases, however, we want to apply some of the same
logic (ex not adding NodeRegions, etc) to other ViewManagers that have a
FlatShadowNode backing (and that don't necessarily create a FlatViewGroup).
This commit renames AndroidView to NativeViewWrapper, and re-introduces
AndroidView as an interface, so that logic for padding, NodeRegions, etc can
be shared.

Differential Revision: D2942387
This commit is contained in:
Ahmed El-Helw
2016-02-17 19:08:19 -08:00
parent b461c70b76
commit f0535152ab
5 changed files with 142 additions and 106 deletions

View File

@@ -9,86 +9,29 @@
package com.facebook.react.flat;
import com.facebook.csslayout.CSSNode;
import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.ReactShadowNode;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.csslayout.Spacing;
/* package */ final class AndroidView extends FlatShadowNode {
interface AndroidView {
final ViewManager mViewManager;
private final ReactShadowNode mReactShadowNode;
private final boolean mNeedsCustomLayoutForChildren;
private boolean mPaddingChanged = false;
/**
* Whether or not custom layout is needed for the children
* @return a boolean representing whether custom layout is needed
*/
boolean needsCustomLayoutForChildren();
/* package */ AndroidView(ViewManager viewManager) {
mViewManager = viewManager;
ReactShadowNode reactShadowNode = viewManager.createShadowNodeInstance();
if (reactShadowNode instanceof CSSNode.MeasureFunction) {
mReactShadowNode = reactShadowNode;
setMeasureFunction((CSSNode.MeasureFunction) reactShadowNode);
} else {
mReactShadowNode = null;
}
/**
* Did the padding change
* @return a boolean representing whether the padding changed
*/
boolean isPaddingChanged();
if (viewManager instanceof ViewGroupManager) {
ViewGroupManager viewGroupManager = (ViewGroupManager) viewManager;
mNeedsCustomLayoutForChildren = viewGroupManager.needsCustomLayoutForChildren();
} else {
mNeedsCustomLayoutForChildren = false;
}
/**
* Reset the padding changed internal state
*/
void resetPaddingChanged();
forceMountToView();
}
/* package */ boolean needsCustomLayoutForChildren() {
return mNeedsCustomLayoutForChildren;
}
/* package */ boolean isPaddingChanged() {
return mPaddingChanged;
}
/* package */ void resetPaddingChanged() {
mPaddingChanged = false;
}
@Override
public void setBackgroundColor(int backgroundColor) {
// suppress, this is handled by a ViewManager
}
@Override
public void setThemedContext(ThemedReactContext themedContext) {
super.setThemedContext(themedContext);
if (mReactShadowNode != null) {
mReactShadowNode.setThemedContext(themedContext);
}
}
@Override
/* package*/ void handleUpdateProperties(ReactStylesDiffMap styles) {
if (mReactShadowNode != null) {
mReactShadowNode.updateProperties(styles);
}
}
@Override
public void addChildAt(CSSNode child, int i) {
super.addChildAt(child, i);
if (child instanceof FlatShadowNode) {
((FlatShadowNode) child).forceMountToView();
}
}
@Override
public void setPadding(int spacingType, float padding) {
if (getPadding().set(spacingType, padding)) {
mPaddingChanged = true;
dirty();
}
}
/**
* Get this node's padding, as defined by style + default padding.
*/
Spacing getPadding();
}