diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index e5201297..e0744e3b 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -212,4 +212,6 @@ public abstract class YogaNode { public abstract Object getData(); public abstract void print(); + + public abstract void setStyleInputs(float[] styleInputs, int size); } diff --git a/java/com/facebook/yoga/YogaNodeJNI.java b/java/com/facebook/yoga/YogaNodeJNI.java index ec5f1673..c0dbccd3 100644 --- a/java/com/facebook/yoga/YogaNodeJNI.java +++ b/java/com/facebook/yoga/YogaNodeJNI.java @@ -730,6 +730,12 @@ public class YogaNodeJNI extends YogaNode { jni_YGNodePrint(mNativePointer); } + private static native void jni_YGNodeSetStyleInputs(long nativePointer, float[] styleInputsArray, int size); + + public void setStyleInputs(float[] styleInputsArray, int size) { + jni_YGNodeSetStyleInputs(mNativePointer, styleInputsArray, size); + } + /** * This method replaces the child at childIndex position with the newNode received by parameter. * This is different than calling removeChildAt and addChildAt because this method ONLY replaces diff --git a/java/com/facebook/yoga/YogaStyleInputs.java b/java/com/facebook/yoga/YogaStyleInputs.java new file mode 100644 index 00000000..0149fa83 --- /dev/null +++ b/java/com/facebook/yoga/YogaStyleInputs.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class YogaStyleInputs { + public static final short LAYOUT_DIRECTION = 0; + public static final short FLEX_DIRECTION = 1; + public static final short FLEX = 2; + public static final short FLEX_GROW = 3; + public static final short FLEX_SHRINK = 4; + public static final short FLEX_BASIS = 5; + public static final short FLEX_BASIS_PERCENT = 6; + public static final short FLEX_BASIS_AUTO = 7; + public static final short FLEX_WRAP = 8; + public static final short WIDTH = 9; + public static final short WIDTH_PERCENT = 10; + public static final short WIDTH_AUTO = 11; + public static final short MIN_WIDTH = 12; + public static final short MIN_WIDTH_PERCENT = 13; + public static final short MAX_WIDTH = 14; + public static final short MAX_WIDTH_PERCENT = 15; + public static final short HEIGHT = 16; + public static final short HEIGHT_PERCENT = 17; + public static final short HEIGHT_AUTO = 18; + public static final short MIN_HEIGHT = 19; + public static final short MIN_HEIGHT_PERCENT = 20; + public static final short MAX_HEIGHT = 21; + public static final short MAX_HEIGHT_PERCENT = 22; + public static final short JUSTIFY_CONTENT = 23; + public static final short ALIGN_ITEMS = 24; + public static final short ALIGN_SELF = 25; + public static final short ALIGN_CONTENT = 26; + public static final short POSITION_TYPE = 27; + public static final short ASPECT_RATIO = 28; + public static final short OVERFLOW = 29; + public static final short DISPLAY = 30; + public static final short MARGIN = 31; + public static final short MARGIN_PERCENT = 32; + public static final short MARGIN_AUTO = 33; + public static final short PADDING = 34; + public static final short PADDING_PERCENT = 35; + public static final short BORDER = 36; + public static final short POSITION = 37; + public static final short POSITION_PERCENT = 38; + public static final short IS_REFERENCE_BASELINE = 39; +} diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index d2f24101..b8da886c 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -15,6 +15,49 @@ using namespace facebook::jni; using namespace std; using facebook::yoga::detail::Log; +enum YGStyleInput { + LayoutDirection, + FlexDirection, + Flex, + FlexGrow, + FlexShrink, + FlexBasis, + FlexBasisPercent, + FlexBasisAuto, + FlexWrap, + Width, + WidthPercent, + WidthAuto, + MinWidth, + MinWidthPercent, + MaxWidth, + MaxWidthPercent, + Height, + HeightPercent, + HeightAuto, + MinHeight, + MinHeightPercent, + MaxHeight, + MaxHeightPercent, + JustifyContent, + AlignItems, + AlignSelf, + AlignContent, + PositionType, + AspectRatio, + Overflow, + Display, + Margin, + MarginPercent, + MarginAuto, + Padding, + PaddingPercent, + Border, + Position, + PositionPercent, + IsReferenceBaseline, +}; + struct JYogaNode : public JavaClass { static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNI;"; }; @@ -647,6 +690,178 @@ void jni_YGConfigSetLogger( } } +static void YGNodeSetStyleInputs( + const YGNodeRef node, + float* styleInputs, + int size) { + const auto end = styleInputs + size; + while (styleInputs < end) { + auto styleInputKey = static_cast((int) *styleInputs++); + switch (styleInputKey) { + case LayoutDirection: + YGNodeStyleSetDirection(node, static_cast(*styleInputs++)); + break; + case FlexDirection: + YGNodeStyleSetFlexDirection( + node, static_cast(*styleInputs++)); + break; + case Flex: + YGNodeStyleSetFlex(node, *styleInputs++); + break; + case FlexGrow: + YGNodeStyleSetFlexGrow(node, *styleInputs++); + break; + case FlexShrink: + YGNodeStyleSetFlexShrink(node, *styleInputs++); + break; + case FlexBasis: + YGNodeStyleSetFlexBasis(node, *styleInputs++); + break; + case FlexBasisPercent: + YGNodeStyleSetFlexBasisPercent(node, *styleInputs++); + break; + case FlexBasisAuto: + YGNodeStyleSetFlexBasisAuto(node); + break; + case FlexWrap: + YGNodeStyleSetFlexWrap(node, static_cast(*styleInputs++)); + break; + case Width: + YGNodeStyleSetWidth(node, *styleInputs++); + break; + case WidthPercent: + YGNodeStyleSetWidthPercent(node, *styleInputs++); + break; + case WidthAuto: + YGNodeStyleSetWidthAuto(node); + break; + case MinWidth: + YGNodeStyleSetMinWidth(node, *styleInputs++); + break; + case MinWidthPercent: + YGNodeStyleSetMinWidthPercent(node, *styleInputs++); + break; + case MaxWidth: + YGNodeStyleSetMaxWidth(node, *styleInputs++); + break; + case MaxWidthPercent: + YGNodeStyleSetMaxWidthPercent(node, *styleInputs++); + break; + case Height: + YGNodeStyleSetHeight(node, *styleInputs++); + break; + case HeightPercent: + YGNodeStyleSetHeightPercent(node, *styleInputs++); + break; + case HeightAuto: + YGNodeStyleSetHeightAuto(node); + break; + case MinHeight: + YGNodeStyleSetMinHeight(node, *styleInputs++); + break; + case MinHeightPercent: + YGNodeStyleSetMinHeightPercent(node, *styleInputs++); + break; + case MaxHeight: + YGNodeStyleSetMaxHeight(node, *styleInputs++); + break; + case MaxHeightPercent: + YGNodeStyleSetMaxHeightPercent(node, *styleInputs++); + break; + case JustifyContent: + YGNodeStyleSetJustifyContent( + node, static_cast(*styleInputs++)); + break; + case AlignItems: + YGNodeStyleSetAlignItems(node, static_cast(*styleInputs++)); + break; + case AlignSelf: + YGNodeStyleSetAlignSelf(node, static_cast(*styleInputs++)); + break; + case AlignContent: + YGNodeStyleSetAlignContent(node, static_cast(*styleInputs++)); + break; + case PositionType: + YGNodeStyleSetPositionType( + node, static_cast(*styleInputs++)); + break; + case AspectRatio: + YGNodeStyleSetAspectRatio(node, *styleInputs++); + break; + case Overflow: + YGNodeStyleSetOverflow(node, static_cast(*styleInputs++)); + break; + case Display: + YGNodeStyleSetDisplay(node, static_cast(*styleInputs++)); + break; + case Margin: { + float edge = *styleInputs++; + float marginValue = *styleInputs++; + YGNodeStyleSetMargin(node, static_cast(edge), marginValue); + break; + } + case MarginPercent: { + float edge = *styleInputs++; + float marginPercent = *styleInputs++; + YGNodeStyleSetMarginPercent( + node, static_cast(edge), marginPercent); + break; + } + case MarginAuto: + YGNodeStyleSetMarginAuto(node, static_cast(*styleInputs++)); + break; + case Padding: { + float edge = *styleInputs++; + float paddingValue = *styleInputs++; + YGNodeStyleSetPadding(node, static_cast(edge), paddingValue); + break; + } + case PaddingPercent: { + float edge = *styleInputs++; + float paddingPercent = *styleInputs++; + YGNodeStyleSetPaddingPercent( + node, static_cast(edge), paddingPercent); + break; + } + case Border: { + float edge = *styleInputs++; + float borderValue = *styleInputs++; + YGNodeStyleSetBorder(node, static_cast(edge), borderValue); + break; + } + case Position: { + float edge = *styleInputs++; + float positionValue = *styleInputs++; + YGNodeStyleSetPosition(node, static_cast(edge), positionValue); + break; + } + case PositionPercent: { + float edge = *styleInputs++; + float positionPercent = *styleInputs++; + YGNodeStyleSetPositionPercent( + node, static_cast(edge), positionPercent); + break; + } + case IsReferenceBaseline: { + YGNodeSetIsReferenceBaseline(node, *styleInputs++ == 1 ? true : false); + break; + } + default: + break; + } + } +} + +void jni_YGNodeSetStyleInputs( + alias_ref thiz, + jlong nativePointer, + alias_ref styleInputs, + jint size) { + float result[size]; + styleInputs->getRegion(0, size, result); + YGNodeSetStyleInputs(_jlong2YGNodeRef(nativePointer), result, size); +} + jint jni_YGNodeGetInstanceCount() { return YGNodeGetInstanceCount(); } @@ -823,6 +1038,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) { YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio), YGMakeCriticalNativeMethod(jni_YGNodeGetInstanceCount), YGMakeCriticalNativeMethod(jni_YGNodePrint), + YGMakeNativeMethod(jni_YGNodeSetStyleInputs), }); registerNatives( "com/facebook/yoga/YogaConfig",