Dont create a spacing object for returning margin, padding, border, and position

Summary: The current implementation was made out of simplicity and to keep the same API as before. Now that the java version of csslayout is deprecated it is time to change the API to make the calls more efficient for the JNI version. This diff with reduce allocations as well as reduce the number of JNI calls done.

Differential Revision: D4050773
This commit is contained in:
Emil Sjolander 2016-10-24 10:35:43 -07:00 committed by Ahmed El-Helw
parent e909fc01c0
commit c10bbe5599
7 changed files with 27 additions and 22 deletions

View File

@ -9,8 +9,6 @@
package com.facebook.react.flat;
import com.facebook.csslayout.Spacing;
interface AndroidView {
/**
@ -31,7 +29,7 @@ interface AndroidView {
void resetPaddingChanged();
/**
* Get this node's padding, as defined by style + default padding.
* Get the padding for a certain spacingType defined in com.facebook.csslayout.Spacing
*/
Spacing getPadding();
float getPadding(int spacingType);
}

View File

@ -103,7 +103,8 @@ import com.facebook.react.views.art.ARTVirtualNode;
@Override
public void setPadding(int spacingType, float padding) {
if (getPadding().set(spacingType, padding)) {
if (getPadding(spacingType) != padding) {
setPadding(spacingType, padding);
mPaddingChanged = true;
dirty();
}

View File

@ -86,7 +86,8 @@ class FlatReactModalShadowNode extends FlatShadowNode implements AndroidView {
@Override
public void setPadding(int spacingType, float padding) {
if (getPadding().set(spacingType, padding)) {
if (getPadding(spacingType) != padding) {
setPadding(spacingType, padding);
mPaddingChanged = true;
dirty();
}

View File

@ -102,7 +102,8 @@ import com.facebook.react.uimanager.ViewManager;
@Override
public void setPadding(int spacingType, float padding) {
if (getPadding().set(spacingType, padding)) {
if (getPadding(spacingType) != padding) {
setPadding(spacingType, padding);
mPaddingChanged = true;
dirty();
}

View File

@ -173,10 +173,8 @@ import com.facebook.react.uimanager.annotations.ReactProp;
updateNodeRegion = true;
}
Spacing padding = getPadding();
left += padding.get(Spacing.LEFT);
top += padding.get(Spacing.TOP);
left += getPadding(Spacing.LEFT);
top += getPadding(Spacing.TOP);
// these are actual right/bottom coordinates where this DrawCommand will draw.
right = left + mDrawCommand.getLayoutWidth();

View File

@ -90,12 +90,11 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
TypedValue.COMPLEX_UNIT_PX,
fontSize == UNSET ?
(int) Math.ceil(PixelUtil.toPixelFromSP(ViewDefaults.FONT_SIZE_SP)) : fontSize);
Spacing padding = getPadding();
editText.setPadding(
(int) Math.ceil(padding.get(Spacing.START)),
(int) Math.ceil(padding.get(Spacing.TOP)),
(int) Math.ceil(padding.get(Spacing.END)),
(int) Math.ceil(padding.get(Spacing.BOTTOM)));
(int) Math.ceil(getPadding(Spacing.START)),
(int) Math.ceil(getPadding(Spacing.TOP)),
(int) Math.ceil(getPadding(Spacing.END)),
(int) Math.ceil(getPadding(Spacing.BOTTOM)));
if (mNumberOfLines != UNSET) {
editText.setLines(mNumberOfLines);
@ -128,7 +127,15 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
super.onCollectExtraUpdates(uiViewOperationQueue);
if (mJsEventCount != UNSET) {
ReactTextUpdate reactTextUpdate =
new ReactTextUpdate(getText(), mJsEventCount, false, getPadding(), UNSET);
new ReactTextUpdate(
getText(),
mJsEventCount,
false,
getPadding(Spacing.START),
getPadding(Spacing.TOP),
getPadding(Spacing.END),
getPadding(Spacing.BOTTOM),
UNSET);
// TODO: the Float.NaN should be replaced with the real line height see D3592781
uiViewOperationQueue.enqueueUpdateExtraData(getReactTag(), reactTextUpdate);
}

View File

@ -712,13 +712,12 @@ import com.facebook.react.uimanager.events.EventDispatcher;
private void updateViewPadding(AndroidView androidView, int reactTag) {
if (androidView.isPaddingChanged()) {
Spacing padding = androidView.getPadding();
mOperationsQueue.enqueueSetPadding(
reactTag,
Math.round(padding.get(Spacing.LEFT)),
Math.round(padding.get(Spacing.TOP)),
Math.round(padding.get(Spacing.RIGHT)),
Math.round(padding.get(Spacing.BOTTOM)));
Math.round(androidView.getPadding(Spacing.LEFT)),
Math.round(androidView.getPadding(Spacing.TOP)),
Math.round(androidView.getPadding(Spacing.RIGHT)),
Math.round(androidView.getPadding(Spacing.BOTTOM)));
androidView.resetPaddingChanged();
}
}