Skip to content

Commit

Permalink
Implement method bindings for gap/row-gap/column-gap
Browse files Browse the repository at this point in the history
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
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Oct 13, 2022
1 parent 1373a70 commit 803a297
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ReactAndroid/src/main/java/com/facebook/yoga/YogaNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class YogaNative {
static {
SoLoader.loadLibrary("yoga");
}

// JNI methods that use Vanilla JNI
// YGConfig related
static native long jni_YGConfigNewJNI();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public interface Inputs {

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();
Expand Down
10 changes: 10 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,14 @@ public void markLayoutSeen() {
}
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);
}
}
23 changes: 23 additions & 0 deletions ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 803a297

Please sign in to comment.