Skip to content

Commit

Permalink
Add meta position to LayoutShadowNode
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel committed Feb 24, 2023
1 parent ab086a1 commit 2529150
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void setFromDynamic(Dynamic dynamic) {
}

private final MutableYogaValue mTempYogaValue;
private final Dynamic[] mPosition = new Dynamic[Spacing.INLINE_START + 1];

public LayoutShadowNode() {
mTempYogaValue = new MutableYogaValue();
Expand Down Expand Up @@ -784,15 +785,62 @@ public void setPositionValues(int index, Dynamic position) {
Spacing.TOP,
Spacing.BOTTOM,
Spacing.ALL,
Spacing.VERTICAL,
Spacing.BOTTOM,
Spacing.TOP,
Spacing.HORIZONTAL,
Spacing.START,
Spacing.END
Spacing.BLOCK,
Spacing.BLOCK_END,
Spacing.BLOCK_START,
Spacing.INLINE,
Spacing.INLINE_END,
Spacing.INLINE_START
};

int spacingType = maybeTransformLeftRightToStartEnd(POSITION_SPACING_TYPES[index]);
mPosition[POSITION_SPACING_TYPES[index]] = position;
updatePositionValues();
}

private void updatePositionValues() {
setYogaPosition(Spacing.TOP, mPosition[Spacing.TOP]);
setYogaPosition(Spacing.BOTTOM, mPosition[Spacing.BOTTOM]);
setYogaPosition(Spacing.START, mPosition[Spacing.START]);
setYogaPosition(Spacing.END, mPosition[Spacing.END]);

if (!I18nUtil.getInstance().doLeftAndRightSwapInRTL(getThemedContext())) {
setYogaPosition(Spacing.LEFT, mPosition[Spacing.LEFT]);
setYogaPosition(Spacing.RIGHT, mPosition[Spacing.RIGHT]);
} else {
setYogaPosition(Spacing.START, mPosition[Spacing.LEFT]);
setYogaPosition(Spacing.END, mPosition[Spacing.RIGHT]);
}

// Aliases with precedence
if (mPosition[Spacing.ALL] != null && !mPosition[Spacing.ALL].isNull()) {
setYogaPosition(Spacing.ALL, mPosition[Spacing.ALL]);
}
if (mPosition[Spacing.BLOCK] != null && !mPosition[Spacing.BLOCK].isNull()) {
setYogaPosition(Spacing.VERTICAL, mPosition[Spacing.BLOCK]);
}
if (mPosition[Spacing.INLINE] != null && !mPosition[Spacing.INLINE].isNull()) {
setYogaPosition(Spacing.HORIZONTAL, mPosition[Spacing.INLINE]);
}
if (mPosition[Spacing.INLINE_END] != null && !mPosition[Spacing.INLINE_END].isNull()) {
setYogaPosition(Spacing.END, mPosition[Spacing.INLINE_END]);
}
if (mPosition[Spacing.INLINE_START] != null && !mPosition[Spacing.INLINE_START].isNull()) {
setYogaPosition(Spacing.START, mPosition[Spacing.INLINE_START]);
}

// Aliases without precedence
if (mPosition[Spacing.BOTTOM] == null || mPosition[Spacing.BOTTOM].isNull()) {
setYogaPosition(Spacing.BOTTOM, mPosition[Spacing.BLOCK_END]);
}
if (mPosition[Spacing.TOP] == null || mPosition[Spacing.TOP].isNull()) {
setYogaPosition(Spacing.TOP, mPosition[Spacing.BLOCK_START]);
}
}

private void setYogaPosition(int spacingType, Dynamic position) {
if(position == null){
return;
}

mTempYogaValue.setFromDynamic(position);
switch (mTempYogaValue.unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,23 @@ public class Spacing {
* Spacing type that represents the block start direction (top). E.g. {@code marginBlockStart}.
*/
public static final int BLOCK_START = 11;
/** Spacing type that represents inline directions (left, right). E.g. {@code marginInline}. */
public static final int INLINE = 12;
/**
* Spacing type that represents the inline end direction (right in left-to-right, left in
* right-to-left). E.g. {@code marginInlineEnd}.
*/
public static final int INLINE_END = 13;
/**
* Spacing type that represents the inline start direction (left in left-to-right, right in
* right-to-left). E.g. {@code marginInlineStart}.
*/
public static final int INLINE_START = 14;

private static final int[] sFlagsMap = {
1, /*LEFT*/ 2, /*TOP*/ 4, /*RIGHT*/ 8, /*BOTTOM*/ 16, /*START*/ 32, /*END*/ 64, /*HORIZONTAL*/
128, /*VERTICAL*/ 256, /*ALL*/ 512, /*BLOCK*/ 1024, /*BLOCK_END*/ 2048, /*BLOCK_START*/
4096, /*INLINE*/ 8192, /*INLINE_END*/ 16384, /*INLINE_START*/
};

private final float[] mSpacing;
Expand Down Expand Up @@ -105,7 +118,8 @@ public boolean set(int spacingType, float value) {
(mValueFlags & sFlagsMap[ALL]) != 0
|| (mValueFlags & sFlagsMap[VERTICAL]) != 0
|| (mValueFlags & sFlagsMap[HORIZONTAL]) != 0
|| (mValueFlags & sFlagsMap[BLOCK]) != 0;
|| (mValueFlags & sFlagsMap[BLOCK]) != 0
|| (mValueFlags & sFlagsMap[INLINE]) != 0;

return true;
}
Expand All @@ -125,6 +139,9 @@ public float get(int spacingType) {
|| spacingType == BLOCK
|| spacingType == BLOCK_END
|| spacingType == BLOCK_START
|| spacingType == INLINE
|| spacingType == INLINE_END
|| spacingType == INLINE_START
? YogaConstants.UNDEFINED
: mDefaultValue);

Expand Down Expand Up @@ -192,6 +209,9 @@ private static float[] newFullSpacingArray() {
YogaConstants.UNDEFINED,
YogaConstants.UNDEFINED,
YogaConstants.UNDEFINED,
YogaConstants.UNDEFINED,
YogaConstants.UNDEFINED,
YogaConstants.UNDEFINED,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ object ReactMapBufferPropSetter {
private const val EDGE_BLOCK = 7
private const val EDGE_BLOCK_END = 8
private const val EDGE_BLOCK_START = 9
private const val EDGE_INLINE = 10
private const val EDGE_INLINE_END = 11
private const val EDGE_INLINE_START = 12

private const val CORNER_TOP_LEFT = 0
private const val CORNER_TOP_RIGHT = 1
Expand Down Expand Up @@ -355,6 +358,9 @@ object ReactMapBufferPropSetter {
EDGE_BLOCK -> 7
EDGE_BLOCK_END -> 8
EDGE_BLOCK_START -> 9
EDGE_INLINE -> 10
EDGE_INLINE_END -> 11
EDGE_INLINE_START -> 12
else -> throw IllegalArgumentException("Unknown key for border color: $key")
}
val colorValue = entry.intValue
Expand Down

0 comments on commit 2529150

Please sign in to comment.