diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index a647dcb1..3712e8ce 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -664,7 +664,10 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { } public void setStyleInputs(float[] styleInputsArray, int size) { - YogaNative.jni_YGNodeSetStyleInputs(mNativePointer, styleInputsArray, size); + if (useVanillaJNI) + YogaNative.jni_YGNodeSetStyleInputsJNI(mNativePointer, styleInputsArray, size); + else + YogaNative.jni_YGNodeSetStyleInputs(mNativePointer, styleInputsArray, size); } /** diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index 595fe204..bfb0670e 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -22,49 +22,6 @@ 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, -}; - const short int LAYOUT_EDGE_SET_FLAG_INDEX = 0; const short int LAYOUT_WIDTH_INDEX = 1; const short int LAYOUT_HEIGHT_INDEX = 2; @@ -589,174 +546,6 @@ void jni_YGConfigSetLogger( } } -static void YGNodeSetStyleInputs( - const YGNodeRef node, - float* styleInputs, - int size) { - const auto end = styleInputs + size; - auto edgesSet = YGNodeEdges{node}; - 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: { - auto edge = static_cast(*styleInputs++); - float marginValue = *styleInputs++; - edgesSet.add(YGNodeEdges::MARGIN); - YGNodeStyleSetMargin(node, edge, marginValue); - break; - } - case MarginPercent: { - auto edge = static_cast(*styleInputs++); - float marginPercent = *styleInputs++; - edgesSet.add(YGNodeEdges::MARGIN); - YGNodeStyleSetMarginPercent(node, edge, marginPercent); - break; - } - case MarginAuto: { - edgesSet.add(YGNodeEdges::MARGIN); - YGNodeStyleSetMarginAuto(node, static_cast(*styleInputs++)); - break; - } - case Padding: { - auto edge = static_cast(*styleInputs++); - float paddingValue = *styleInputs++; - edgesSet.add(YGNodeEdges::PADDING); - YGNodeStyleSetPadding(node, edge, paddingValue); - break; - } - case PaddingPercent: { - auto edge = static_cast(*styleInputs++); - float paddingPercent = *styleInputs++; - edgesSet.add(YGNodeEdges::PADDING); - YGNodeStyleSetPaddingPercent(node, edge, paddingPercent); - break; - } - case Border: { - auto edge = static_cast(*styleInputs++); - float borderValue = *styleInputs++; - edgesSet.add(YGNodeEdges::BORDER); - YGNodeStyleSetBorder(node, edge, borderValue); - break; - } - case Position: { - auto edge = static_cast(*styleInputs++); - float positionValue = *styleInputs++; - YGNodeStyleSetPosition(node, edge, positionValue); - break; - } - case PositionPercent: { - auto edge = static_cast(*styleInputs++); - float positionPercent = *styleInputs++; - YGNodeStyleSetPositionPercent(node, edge, positionPercent); - break; - } - case IsReferenceBaseline: { - YGNodeSetIsReferenceBaseline(node, *styleInputs++ == 1 ? true : false); - break; - } - default: - break; - } - } - edgesSet.setOn(node); -} - void jni_YGNodeSetStyleInputs( alias_ref, jlong nativePointer, diff --git a/java/jni/YGJNI.h b/java/jni/YGJNI.h index f0c489c1..926b6ca2 100644 --- a/java/jni/YGJNI.h +++ b/java/jni/YGJNI.h @@ -4,6 +4,49 @@ * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. */ +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, +}; + namespace { union YGNodeContext { @@ -56,3 +99,171 @@ struct YogaValue { } }; } // namespace + +static void YGNodeSetStyleInputs( + const YGNodeRef node, + float* styleInputs, + int size) { + const auto end = styleInputs + size; + auto edgesSet = YGNodeEdges{node}; + 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: { + auto edge = static_cast(*styleInputs++); + float marginValue = *styleInputs++; + edgesSet.add(YGNodeEdges::MARGIN); + YGNodeStyleSetMargin(node, edge, marginValue); + break; + } + case MarginPercent: { + auto edge = static_cast(*styleInputs++); + float marginPercent = *styleInputs++; + edgesSet.add(YGNodeEdges::MARGIN); + YGNodeStyleSetMarginPercent(node, edge, marginPercent); + break; + } + case MarginAuto: { + edgesSet.add(YGNodeEdges::MARGIN); + YGNodeStyleSetMarginAuto(node, static_cast(*styleInputs++)); + break; + } + case Padding: { + auto edge = static_cast(*styleInputs++); + float paddingValue = *styleInputs++; + edgesSet.add(YGNodeEdges::PADDING); + YGNodeStyleSetPadding(node, edge, paddingValue); + break; + } + case PaddingPercent: { + auto edge = static_cast(*styleInputs++); + float paddingPercent = *styleInputs++; + edgesSet.add(YGNodeEdges::PADDING); + YGNodeStyleSetPaddingPercent(node, edge, paddingPercent); + break; + } + case Border: { + auto edge = static_cast(*styleInputs++); + float borderValue = *styleInputs++; + edgesSet.add(YGNodeEdges::BORDER); + YGNodeStyleSetBorder(node, edge, borderValue); + break; + } + case Position: { + auto edge = static_cast(*styleInputs++); + float positionValue = *styleInputs++; + YGNodeStyleSetPosition(node, edge, positionValue); + break; + } + case PositionPercent: { + auto edge = static_cast(*styleInputs++); + float positionPercent = *styleInputs++; + YGNodeStyleSetPositionPercent(node, edge, positionPercent); + break; + } + case IsReferenceBaseline: { + YGNodeSetIsReferenceBaseline(node, *styleInputs++ == 1 ? true : false); + break; + } + default: + break; + } + } + edgesSet.setOn(node); +} diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 9c50bce5..2cf6cbd2 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -396,6 +396,17 @@ static jlong jni_YGNodeCloneJNI(JNIEnv* env, jobject obj, jlong nativePointer) { // Yoga specific properties, not compatible with flexbox specification YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio); +static void jni_YGNodeSetStyleInputsJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jfloatArray styleInputs, + jint size) { + float result[size]; + env->GetFloatArrayRegion(styleInputs, 0, size, result); + YGNodeSetStyleInputs(_jlong2YGNodeRef(nativePointer), result, size); +} + void assertNoPendingJniException(JNIEnv* env) { // This method cannot call any other method of the library, since other // methods of the library use it to check for exceptions too @@ -642,6 +653,9 @@ static JNINativeMethod methods[] = { "(JF)V", (void*) jni_YGNodeStyleSetAspectRatioJNI}, {"jni_YGNodePrintJNI", "(J)V", (void*) jni_YGNodePrintJNI}, + {"jni_YGNodeSetStyleInputsJNI", + "(J[FI)V", + (void*) jni_YGNodeSetStyleInputsJNI}, {"jni_YGNodeCloneJNI", "(J)J", (void*) jni_YGNodeCloneJNI}, };