Skip to content

Commit ce89208

Browse files
Add meta position to LayoutShadowNode
1 parent d9d1553 commit ce89208

File tree

3 files changed

+82
-8
lines changed

3 files changed

+82
-8
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void setFromDynamic(Dynamic dynamic) {
7676
}
7777

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

8081
public LayoutShadowNode() {
8182
mTempYogaValue = new MutableYogaValue();
@@ -786,15 +787,62 @@ public void setPositionValues(int index, Dynamic position) {
786787
Spacing.TOP,
787788
Spacing.BOTTOM,
788789
Spacing.ALL,
789-
Spacing.VERTICAL,
790-
Spacing.BOTTOM,
791-
Spacing.TOP,
792-
Spacing.HORIZONTAL,
793-
Spacing.START,
794-
Spacing.END
790+
Spacing.BLOCK,
791+
Spacing.BLOCK_END,
792+
Spacing.BLOCK_START,
793+
Spacing.INLINE,
794+
Spacing.INLINE_END,
795+
Spacing.INLINE_START
795796
};
796797

797-
int spacingType = maybeTransformLeftRightToStartEnd(POSITION_SPACING_TYPES[index]);
798+
mPosition[POSITION_SPACING_TYPES[index]] = position;
799+
updatePositionValues();
800+
}
801+
802+
private void updatePositionValues() {
803+
setYogaPosition(Spacing.TOP, mPosition[Spacing.TOP]);
804+
setYogaPosition(Spacing.BOTTOM, mPosition[Spacing.BOTTOM]);
805+
setYogaPosition(Spacing.START, mPosition[Spacing.START]);
806+
setYogaPosition(Spacing.END, mPosition[Spacing.END]);
807+
808+
if (!I18nUtil.getInstance().doLeftAndRightSwapInRTL(getThemedContext())) {
809+
setYogaPosition(Spacing.LEFT, mPosition[Spacing.LEFT]);
810+
setYogaPosition(Spacing.RIGHT, mPosition[Spacing.RIGHT]);
811+
} else {
812+
setYogaPosition(Spacing.START, mPosition[Spacing.LEFT]);
813+
setYogaPosition(Spacing.END, mPosition[Spacing.RIGHT]);
814+
}
815+
816+
// Aliases with precedence
817+
if (mPosition[Spacing.ALL] != null && !mPosition[Spacing.ALL].isNull()) {
818+
setYogaPosition(Spacing.ALL, mPosition[Spacing.ALL]);
819+
}
820+
if (mPosition[Spacing.BLOCK] != null && !mPosition[Spacing.BLOCK].isNull()) {
821+
setYogaPosition(Spacing.VERTICAL, mPosition[Spacing.BLOCK]);
822+
}
823+
if (mPosition[Spacing.INLINE] != null && !mPosition[Spacing.INLINE].isNull()) {
824+
setYogaPosition(Spacing.HORIZONTAL, mPosition[Spacing.INLINE]);
825+
}
826+
if (mPosition[Spacing.INLINE_END] != null && !mPosition[Spacing.INLINE_END].isNull()) {
827+
setYogaPosition(Spacing.END, mPosition[Spacing.INLINE_END]);
828+
}
829+
if (mPosition[Spacing.INLINE_START] != null && !mPosition[Spacing.INLINE_START].isNull()) {
830+
setYogaPosition(Spacing.START, mPosition[Spacing.INLINE_START]);
831+
}
832+
833+
// Aliases without precedence
834+
if (mPosition[Spacing.BOTTOM] == null || mPosition[Spacing.BOTTOM].isNull()) {
835+
setYogaPosition(Spacing.BOTTOM, mPosition[Spacing.BLOCK_END]);
836+
}
837+
if (mPosition[Spacing.TOP] == null || mPosition[Spacing.TOP].isNull()) {
838+
setYogaPosition(Spacing.TOP, mPosition[Spacing.BLOCK_START]);
839+
}
840+
}
841+
842+
private void setYogaPosition(int spacingType, Dynamic position) {
843+
if(position == null){
844+
return;
845+
}
798846

799847
mTempYogaValue.setFromDynamic(position);
800848
switch (mTempYogaValue.unit) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,23 @@ public class Spacing {
5555
* Spacing type that represents the block start direction (top). E.g. {@code marginBlockStart}.
5656
*/
5757
public static final int BLOCK_START = 11;
58+
/** Spacing type that represents inline directions (left, right). E.g. {@code marginInline}. */
59+
public static final int INLINE = 12;
60+
/**
61+
* Spacing type that represents the inline end direction (right in left-to-right, left in
62+
* right-to-left). E.g. {@code marginInlineEnd}.
63+
*/
64+
public static final int INLINE_END = 13;
65+
/**
66+
* Spacing type that represents the inline start direction (left in left-to-right, right in
67+
* right-to-left). E.g. {@code marginInlineStart}.
68+
*/
69+
public static final int INLINE_START = 14;
5870

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

6477
private final float[] mSpacing;
@@ -105,7 +118,8 @@ public boolean set(int spacingType, float value) {
105118
(mValueFlags & sFlagsMap[ALL]) != 0
106119
|| (mValueFlags & sFlagsMap[VERTICAL]) != 0
107120
|| (mValueFlags & sFlagsMap[HORIZONTAL]) != 0
108-
|| (mValueFlags & sFlagsMap[BLOCK]) != 0;
121+
|| (mValueFlags & sFlagsMap[BLOCK]) != 0
122+
|| (mValueFlags & sFlagsMap[INLINE]) != 0;
109123

110124
return true;
111125
}
@@ -125,6 +139,9 @@ public float get(int spacingType) {
125139
|| spacingType == BLOCK
126140
|| spacingType == BLOCK_END
127141
|| spacingType == BLOCK_START
142+
|| spacingType == INLINE
143+
|| spacingType == INLINE_END
144+
|| spacingType == INLINE_START
128145
? YogaConstants.UNDEFINED
129146
: mDefaultValue);
130147

@@ -192,6 +209,9 @@ private static float[] newFullSpacingArray() {
192209
YogaConstants.UNDEFINED,
193210
YogaConstants.UNDEFINED,
194211
YogaConstants.UNDEFINED,
212+
YogaConstants.UNDEFINED,
213+
YogaConstants.UNDEFINED,
214+
YogaConstants.UNDEFINED,
195215
};
196216
}
197217
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferPropSetter.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ object ReactMapBufferPropSetter {
9090
private const val EDGE_BLOCK = 7
9191
private const val EDGE_BLOCK_END = 8
9292
private const val EDGE_BLOCK_START = 9
93+
private const val EDGE_INLINE = 10
94+
private const val EDGE_INLINE_END = 11
95+
private const val EDGE_INLINE_START = 12
9396

9497
private const val CORNER_TOP_LEFT = 0
9598
private const val CORNER_TOP_RIGHT = 1
@@ -355,6 +358,9 @@ object ReactMapBufferPropSetter {
355358
EDGE_BLOCK -> 7
356359
EDGE_BLOCK_END -> 8
357360
EDGE_BLOCK_START -> 9
361+
EDGE_INLINE -> 10
362+
EDGE_INLINE_END -> 11
363+
EDGE_INLINE_START -> 12
358364
else -> throw IllegalArgumentException("Unknown key for border color: $key")
359365
}
360366
val colorValue = entry.intValue

0 commit comments

Comments
 (0)