Implement method bindings for gap/row-gap/column-gap

Summary:
This adds method bindings for `YGNodeStyleSetGap` and `YGNodeStyleGetGap`.

Changelog:
[Genral][Added] - Implement method bindings for yoga gap/row-gap/column-gap

Reviewed By: yungsters

Differential Revision: D39922411

fbshipit-source-id: 6cbb4d352203d2ec92df162c3f2f2efd02bd9568
This commit is contained in:
Nick Gerleman
2022-10-13 08:18:49 -07:00
committed by Facebook GitHub Bot
parent 582533dbc6
commit f992e63ac5
13 changed files with 111 additions and 1 deletions

View File

@@ -285,6 +285,10 @@ YG_VALUE_PROPERTY(maxWidth, MaxWidth)
YG_VALUE_PROPERTY(maxHeight, MaxHeight)
YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
YG_EDGE_PROPERTY(columnGap, ColumnGap, Gap, YGGutterColumn)
YG_EDGE_PROPERTY(rowGap, RowGap, Gap, YGGutterRow)
YG_EDGE_PROPERTY(gap, Gap, Gap, YGGutterAll)
#pragma mark - Layout and Sizing
- (YGDirection)resolvedDirection {

View File

@@ -293,6 +293,12 @@ namespace Facebook.Yoga
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeStyleGetAspectRatio(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetGap(YGNodeHandle node, YogaGutter gutter, float gapLength);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeStyleGetGap(YGNodeHandle node, YogaGutter gutter);
#endregion
#region YG_NODE_STYLE_EDGE_PROPERTY

View File

@@ -432,6 +432,45 @@ namespace Facebook.Yoga
}
}
public float Gap
{
get
{
return Native.YGNodeStyleGetGap(_ygNode, YogaGutter.All);
}
set
{
Native.YGNodeStyleSetGap(_ygNode, YogaGutter.All, value);
}
}
public float ColumnGap
{
get
{
return Native.YGNodeStyleGetGap(_ygNode, YogaGutter.Column);
}
set
{
Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Column, value);
}
}
public float RowGap
{
get
{
return Native.YGNodeStyleGetGap(_ygNode, YogaGutter.Row);
}
set
{
Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Row, value);
}
}
public float LayoutX
{
get

View File

@@ -108,6 +108,8 @@ public class YogaNative {
static native void jni_YGNodeStyleSetMaxHeightPercentJNI(long nativePointer, float percent);
static native float jni_YGNodeStyleGetAspectRatioJNI(long nativePointer);
static native void jni_YGNodeStyleSetAspectRatioJNI(long nativePointer, float aspectRatio);
static native float jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter);
static native void jni_YGNodeStyleSetGapJNI(long nativePointer, int gutter, float gapLength);
static native void jni_YGNodeSetHasMeasureFuncJNI(long nativePointer, boolean hasMeasureFunc);
static native void jni_YGNodeSetHasBaselineFuncJNI(long nativePointer, boolean hasMeasureFunc);
static native void jni_YGNodePrintJNI(long nativePointer);

View File

@@ -188,6 +188,10 @@ public abstract class YogaNode implements YogaProps {
public abstract void setAspectRatio(float aspectRatio);
public abstract float getGap(YogaGutter gutter);
public abstract void setGap(YogaGutter gutter, float gapLength);
public abstract float getLayoutX();
public abstract float getLayoutY();

View File

@@ -725,4 +725,14 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
mHasNewLayout = false;
}
@Override
public float getGap(YogaGutter gutter) {
return YogaNative.jni_YGNodeStyleGetGapJNI(mNativePointer, gutter.intValue());
}
@Override
public void setGap(YogaGutter gutter, float gapLength) {
YogaNative.jni_YGNodeStyleSetGapJNI(mNativePointer, gutter.intValue(), gapLength);
}
}

View File

@@ -734,6 +734,27 @@ static jlong jni_YGNodeCloneJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
return reinterpret_cast<jlong>(clonedYogaNode);
}
static jfloat jni_YGNodeStyleGetGapJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jint gutter) {
return (jfloat) YGNodeStyleGetGap(
_jlong2YGNodeRef(nativePointer), static_cast<YGGutter>(gutter));
}
static void jni_YGNodeStyleSetGapJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jint gutter,
jfloat gapLength) {
YGNodeStyleSetGap(
_jlong2YGNodeRef(nativePointer),
static_cast<YGGutter>(gutter),
static_cast<float>(gapLength));
}
// Yoga specific properties, not compatible with flexbox specification
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
@@ -971,6 +992,8 @@ static JNINativeMethod methods[] = {
{"jni_YGNodeSetHasMeasureFuncJNI",
"(JZ)V",
(void*) jni_YGNodeSetHasMeasureFuncJNI},
{"jni_YGNodeStyleGetGapJNI", "(JI)F", (void*) jni_YGNodeStyleGetGapJNI},
{"jni_YGNodeStyleSetGapJNI", "(JIF)V", (void*) jni_YGNodeStyleSetGapJNI},
{"jni_YGNodeSetHasBaselineFuncJNI",
"(JZ)V",
(void*) jni_YGNodeSetHasBaselineFuncJNI},

View File

@@ -232,6 +232,10 @@ void Node::setIsReferenceBaseline(bool isReferenceBaseline) {
YGNodeSetIsReferenceBaseline(m_node, isReferenceBaseline);
}
void Node::setGap(int gutter, double gapLength) {
YGNodeStyleSetGap(m_node, static_cast<YGGutter>(gutter), gapLength);
}
int Node::getPositionType(void) const {
return YGNodeStyleGetPositionType(m_node);
}
@@ -327,6 +331,11 @@ Value Node::getPadding(int edge) const {
YGNodeStyleGetPadding(m_node, static_cast<YGEdge>(edge)));
}
Value Node::getGap(int gutter, ) {
return Value::fromYGValue(
YGNodeStyleGetGap(m_node, static_cast<YGGutter>(gutter)));
}
bool Node::isReferenceBaseline() {
return YGNodeIsReferenceBaseline(m_node);
}

View File

@@ -95,6 +95,8 @@ public: // Style setters
void setPadding(int edge, double padding);
void setPaddingPercent(int edge, double padding);
void setGap(int gutter, double gapLength);
public: // Style getters
int getPositionType(void) const;
Value getPosition(int edge) const;
@@ -130,6 +132,8 @@ public: // Style getters
Value getPadding(int edge) const;
Value getGap(int gutter);
public: // Tree hierarchy mutators
void insertChild(Node* child, unsigned index);
void removeChild(Node* child);

View File

@@ -43,6 +43,7 @@ export type {
Yoga$FlexDirection,
Yoga$Direction,
Yoga$Wrap,
Yoga$Gutter,
Yoga$Edge,
Yoga$Display,
Yoga$Unit,

View File

@@ -15,6 +15,7 @@ import type {
Yoga$Wrap,
Yoga$Align,
Yoga$FlexDirection,
Yoga$Gap,
Yoga$Direction,
Yoga$PositionType,
Yoga$Overflow,
@@ -155,6 +156,7 @@ export type Yoga$Node = {
getFlexWrap(): Yoga$Wrap,
getHeight(): Value,
getJustifyContent(): Yoga$Justify,
getGap(gutter: Yoga$Gutter): Value,
getMargin(edge: Yoga$Edge): Value,
getMaxHeight(): Value,
getMaxWidth(): Value,
@@ -189,6 +191,7 @@ export type Yoga$Node = {
setHeightAuto(): void,
setHeightPercent(height: number): void,
setJustifyContent(justifyContent: Yoga$Justify): void,
setGap(gutter: Yoga$Gutter, gapLength: number): Value,
setMargin(edge: Yoga$Edge, margin: number): void,
setMarginAuto(edge: Yoga$Edge): void,
setMarginPercent(edge: Yoga$Edge, margin: number): void,

View File

@@ -18,6 +18,7 @@ export type {
Yoga$FlexDirection,
Yoga$Direction,
Yoga$Wrap,
Yoga$Gutter,
Yoga$Edge,
Yoga$Display,
Yoga$Unit,

View File

@@ -98,6 +98,8 @@ NBIND_CLASS(Node) {
method(setPadding);
method(setPaddingPercent);
method(setGap);
method(getPositionType);
method(getPosition);
@@ -132,6 +134,8 @@ NBIND_CLASS(Node) {
method(getPadding);
method(getGap);
method(insertChild);
method(removeChild);