Don't pass tag alongside node in StateBuilder methods

Summary:
Many of StateBuilder methods take a lot of arguments, which makes it hard to read. This patch is doing a bit of cleanup by removing tag from the method signatures, because tag can be easily obtained from the node itself.

This is a pure refactoring diff and should have no functional changes.

Reviewed By: ahmedre

Differential Revision: D2915815
This commit is contained in:
Denis Koroskin 2016-02-19 17:36:59 -08:00 committed by Ahmed El-Helw
parent 3b63d7c3bc
commit 3e30b70e29
2 changed files with 14 additions and 23 deletions

View File

@ -132,8 +132,7 @@ public class FlatUIImplementation extends UIImplementation {
} }
if (node.mountsToView()) { if (node.mountsToView()) {
int tag = cssNode.getReactTag(); mStateBuilder.ensureBackingViewIsCreated(node, styles);
mStateBuilder.ensureBackingViewIsCreated(node, tag, styles);
} }
} else { } else {
super.handleCreateView(cssNode, rootViewTag, styles); super.handleCreateView(cssNode, rootViewTag, styles);
@ -151,8 +150,7 @@ public class FlatUIImplementation extends UIImplementation {
node.handleUpdateProperties(styles); node.handleUpdateProperties(styles);
if (node.mountsToView()) { if (node.mountsToView()) {
int tag = cssNode.getReactTag(); mStateBuilder.ensureBackingViewIsCreated(node, styles);
mStateBuilder.ensureBackingViewIsCreated(node, tag, styles);
} }
} else { } else {
super.handleUpdateView(cssNode, className, styles); super.handleUpdateView(cssNode, className, styles);
@ -427,13 +425,12 @@ public class FlatUIImplementation extends UIImplementation {
} }
FlatShadowNode nonVirtualNode = (FlatShadowNode) node; FlatShadowNode nonVirtualNode = (FlatShadowNode) node;
int nonVirtualTag = nonVirtualNode.getReactTag();
nonVirtualNode.forceMountToView(); nonVirtualNode.forceMountToView();
mStateBuilder.ensureBackingViewIsCreated(nonVirtualNode, nonVirtualTag, null); mStateBuilder.ensureBackingViewIsCreated(nonVirtualNode, null);
FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue(); FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue();
operationsQueue.enqueueSetJSResponder( operationsQueue.enqueueSetJSResponder(
nonVirtualTag, nonVirtualNode.getReactTag(),
possiblyVirtualReactTag, possiblyVirtualReactTag,
blockNativeResponder); blockNativeResponder);
} }

View File

@ -62,8 +62,6 @@ import com.facebook.react.uimanager.events.EventDispatcher;
* DrawCommands that will then mount in UI thread to a root FlatViewGroup so that it can draw. * DrawCommands that will then mount in UI thread to a root FlatViewGroup so that it can draw.
*/ */
/* package */ void applyUpdates(EventDispatcher eventDispatcher, FlatShadowNode node) { /* package */ void applyUpdates(EventDispatcher eventDispatcher, FlatShadowNode node) {
int tag = node.getReactTag();
float width = node.getLayoutWidth(); float width = node.getLayoutWidth();
float height = node.getLayoutHeight(); float height = node.getLayoutHeight();
float left = node.getLayoutX(); float left = node.getLayoutX();
@ -73,7 +71,6 @@ import com.facebook.react.uimanager.events.EventDispatcher;
collectStateForMountableNode( collectStateForMountableNode(
node, node,
tag,
left, left,
top, top,
right, right,
@ -126,17 +123,18 @@ import com.facebook.react.uimanager.events.EventDispatcher;
/* package */ void ensureBackingViewIsCreated( /* package */ void ensureBackingViewIsCreated(
FlatShadowNode node, FlatShadowNode node,
int tag,
@Nullable ReactStylesDiffMap styles) { @Nullable ReactStylesDiffMap styles) {
if (node.isBackingViewCreated()) { if (node.isBackingViewCreated()) {
if (styles != null) { if (styles != null) {
// if the View is already created, make sure propagate new styles. // if the View is already created, make sure propagate new styles.
mOperationsQueue.enqueueUpdateProperties(tag, node.getViewClass(), styles); mOperationsQueue.enqueueUpdateProperties(node.getReactTag(), node.getViewClass(), styles);
} }
return; return;
} }
int tag = node.getReactTag();
mOperationsQueue.enqueueCreateView(node.getThemedContext(), tag, node.getViewClass(), styles); mOperationsQueue.enqueueCreateView(node.getThemedContext(), tag, node.getViewClass(), styles);
node.signalBackingViewIsCreated(); node.signalBackingViewIsCreated();
} }
@ -195,7 +193,6 @@ import com.facebook.react.uimanager.events.EventDispatcher;
*/ */
private void collectStateForMountableNode( private void collectStateForMountableNode(
FlatShadowNode node, FlatShadowNode node,
int tag,
float left, float left,
float top, float top,
float right, float right,
@ -213,7 +210,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
boolean needsCustomLayoutForChildren = false; boolean needsCustomLayoutForChildren = false;
if (node instanceof AndroidView) { if (node instanceof AndroidView) {
AndroidView androidView = (AndroidView) node; AndroidView androidView = (AndroidView) node;
updateViewPadding(androidView, tag); updateViewPadding(androidView, node.getReactTag());
isAndroidView = true; isAndroidView = true;
needsCustomLayoutForChildren = androidView.needsCustomLayoutForChildren(); needsCustomLayoutForChildren = androidView.needsCustomLayoutForChildren();
@ -270,7 +267,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
if (shouldUpdateMountState) { if (shouldUpdateMountState) {
mOperationsQueue.enqueueUpdateMountState( mOperationsQueue.enqueueUpdateMountState(
tag, node.getReactTag(),
drawCommands, drawCommands,
listeners, listeners,
nodeRegions); nodeRegions);
@ -283,13 +280,12 @@ import com.facebook.react.uimanager.events.EventDispatcher;
final FlatShadowNode[] nativeChildren = mNativeChildren.finish(); final FlatShadowNode[] nativeChildren = mNativeChildren.finish();
if (nativeChildren != null) { if (nativeChildren != null) {
updateNativeChildren(node, tag, node.getNativeChildren(), nativeChildren); updateNativeChildren(node, node.getNativeChildren(), nativeChildren);
} }
} }
private void updateNativeChildren( private void updateNativeChildren(
FlatShadowNode node, FlatShadowNode node,
int tag,
FlatShadowNode[] oldNativeChildren, FlatShadowNode[] oldNativeChildren,
FlatShadowNode[] newNativeChildren) { FlatShadowNode[] newNativeChildren) {
@ -303,6 +299,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
mViewsToDetachAllChildrenFrom.add(node); mViewsToDetachAllChildrenFrom.add(node);
} }
int tag = node.getReactTag();
int numViewsToAdd = newNativeChildren.length; int numViewsToAdd = newNativeChildren.length;
final int[] viewsToAdd; final int[] viewsToAdd;
if (numViewsToAdd == 0) { if (numViewsToAdd == 0) {
@ -425,8 +422,6 @@ import com.facebook.react.uimanager.events.EventDispatcher;
float parentClipBottom, float parentClipBottom,
boolean parentIsAndroidView, boolean parentIsAndroidView,
boolean needsCustomLayout) { boolean needsCustomLayout) {
int tag = node.getReactTag();
float width = node.getLayoutWidth(); float width = node.getLayoutWidth();
float height = node.getLayoutHeight(); float height = node.getLayoutHeight();
@ -436,7 +431,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
float bottom = top + height; float bottom = top + height;
if (node.mountsToView()) { if (node.mountsToView()) {
ensureBackingViewIsCreated(node, tag, null); ensureBackingViewIsCreated(node, null);
addNativeChild(node); addNativeChild(node);
if (!parentIsAndroidView) { if (!parentIsAndroidView) {
@ -449,7 +444,6 @@ import com.facebook.react.uimanager.events.EventDispatcher;
collectStateForMountableNode( collectStateForMountableNode(
node, node,
tag,
left - left, left - left,
top - top, top - top,
right - left, right - left,
@ -479,11 +473,11 @@ import com.facebook.react.uimanager.events.EventDispatcher;
} }
} }
private void updateViewPadding(AndroidView androidView, int tag) { private void updateViewPadding(AndroidView androidView, int reactTag) {
if (androidView.isPaddingChanged()) { if (androidView.isPaddingChanged()) {
Spacing padding = androidView.getPadding(); Spacing padding = androidView.getPadding();
mOperationsQueue.enqueueSetPadding( mOperationsQueue.enqueueSetPadding(
tag, reactTag,
Math.round(padding.get(Spacing.LEFT)), Math.round(padding.get(Spacing.LEFT)),
Math.round(padding.get(Spacing.TOP)), Math.round(padding.get(Spacing.TOP)),
Math.round(padding.get(Spacing.RIGHT)), Math.round(padding.get(Spacing.RIGHT)),