Compare commits
18 Commits
v1.12.0-pr
...
1.12.0-pre
Author | SHA1 | Date | |
---|---|---|---|
|
5bb2265083 | ||
|
ab3bf40c7d | ||
|
f273e80c77 | ||
|
1471be54e3 | ||
|
f039835249 | ||
|
f793ba2d6b | ||
|
9f72ad05ce | ||
|
14f3827491 | ||
|
0d96098fd9 | ||
|
42e3b78f04 | ||
|
3ad49d27d9 | ||
|
3331a9e480 | ||
|
7890672ecc | ||
|
d7bfbf3646 | ||
|
6d271c05f6 | ||
|
a9bddf87ff | ||
|
88994129ae | ||
|
888892885e |
17
BUCK
17
BUCK
@@ -15,6 +15,7 @@ COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
|
||||
|
||||
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [
|
||||
"-std=c++1y",
|
||||
"-DDEBUG",
|
||||
]
|
||||
|
||||
yoga_cxx_library(
|
||||
@@ -31,6 +32,20 @@ yoga_cxx_library(
|
||||
],
|
||||
)
|
||||
|
||||
yoga_cxx_library(
|
||||
name = "yogaForDebug",
|
||||
srcs = glob(["yoga/*.cpp"]),
|
||||
header_namespace = "",
|
||||
exported_headers = subdir_glob([("", "yoga/*.h")]),
|
||||
compiler_flags = TEST_COMPILER_FLAGS,
|
||||
soname = "libyogacore.$(ext)",
|
||||
tests = [":YogaTests"],
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
yoga_dep("lib/fb:ndklog"),
|
||||
],
|
||||
)
|
||||
|
||||
yoga_cxx_test(
|
||||
name = "YogaTests",
|
||||
srcs = glob(["tests/*.cpp"]),
|
||||
@@ -39,7 +54,7 @@ yoga_cxx_test(
|
||||
contacts = ["emilsj@fb.com"],
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
":yoga",
|
||||
":yogaForDebug",
|
||||
GTEST_TARGET,
|
||||
],
|
||||
)
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#
|
||||
Pod::Spec.new do |spec|
|
||||
spec.name = 'Yoga'
|
||||
spec.version = '1.9.0'
|
||||
spec.version = '1.12.0-pre.1'
|
||||
spec.license = { :type => 'MIT', :file => "LICENSE" }
|
||||
spec.homepage = 'https://yogalayout.com/'
|
||||
spec.documentation_url = 'https://yogalayout.com/docs'
|
||||
|
@@ -1,10 +1,3 @@
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
|
@@ -12,7 +12,7 @@ load(
|
||||
"yoga_dep",
|
||||
)
|
||||
|
||||
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++11"]
|
||||
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++14"]
|
||||
|
||||
fb_native.csharp_library(
|
||||
name = "yogalibnet46",
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
|
||||
VERSION_NAME=1.12.0-SNAPSHOT
|
||||
VERSION_NAME=1.13.1-SNAPSHOT
|
||||
POM_URL=https://github.com/facebook/yoga
|
||||
POM_SCM_URL=https://github.com/facebook/yoga.git
|
||||
POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git
|
||||
|
@@ -18,7 +18,7 @@ yoga_cxx_library(
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Os",
|
||||
"-std=c++11",
|
||||
"-std=c++14",
|
||||
],
|
||||
platforms = ANDROID,
|
||||
preprocessor_flags = [
|
||||
|
@@ -29,7 +29,7 @@ add_compile_options(
|
||||
-Wall
|
||||
-std=c++11)
|
||||
|
||||
add_library(yoga SHARED jni/YGJNI.cpp)
|
||||
add_library(yoga SHARED jni/YGJNI.cpp jni/YGJTypes.cpp)
|
||||
|
||||
target_include_directories(yoga PRIVATE
|
||||
${libfb_DIR}/include
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* 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.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,83 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaConfig {
|
||||
|
||||
public static int SPACING_TYPE = 1;
|
||||
|
||||
static {
|
||||
SoLoader.loadLibrary("yoga");
|
||||
}
|
||||
|
||||
long mNativePointer;
|
||||
private YogaLogger mLogger;
|
||||
private YogaNodeCloneFunction mYogaNodeCloneFunction;
|
||||
public boolean avoidGlobalJNIRefs = false;
|
||||
|
||||
private native long jni_YGConfigNew();
|
||||
public YogaConfig() {
|
||||
mNativePointer = jni_YGConfigNew();
|
||||
mNativePointer = YogaNative.jni_YGConfigNew();
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
private native void jni_YGConfigFree(long nativePointer);
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
jni_YGConfigFree(mNativePointer);
|
||||
YogaNative.jni_YGConfigFree(mNativePointer);
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetExperimentalFeatureEnabled(
|
||||
long nativePointer,
|
||||
int feature,
|
||||
boolean enabled);
|
||||
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
|
||||
jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
||||
YogaNative.jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetUseWebDefaults(long nativePointer, boolean useWebDefaults);
|
||||
public void setUseWebDefaults(boolean useWebDefaults) {
|
||||
jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
||||
YogaNative.jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetPrintTreeFlag(long nativePointer, boolean enable);
|
||||
public void setPrintTreeFlag(boolean enable) {
|
||||
jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
|
||||
YogaNative.jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetPointScaleFactor(long nativePointer, float pixelsInPoint);
|
||||
public void setPointScaleFactor(float pixelsInPoint) {
|
||||
jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
||||
YogaNative.jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetUseLegacyStretchBehaviour(long nativePointer, boolean useLegacyStretchBehaviour);
|
||||
|
||||
/**
|
||||
* Yoga previously had an error where containers would take the maximum space possible instead of the minimum
|
||||
* like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch;
|
||||
* Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
|
||||
*/
|
||||
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
|
||||
jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
||||
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||
/**
|
||||
* If this flag is set then yoga would diff the layout without legacy flag and would set a bool in
|
||||
* YogaNode(mDoesLegacyStretchFlagAffectsLayout) with true if the layouts were different and false
|
||||
@@ -85,14 +64,13 @@ public class YogaConfig {
|
||||
*/
|
||||
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
|
||||
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetLogger(long nativePointer, Object logger);
|
||||
public void setLogger(YogaLogger logger) {
|
||||
mLogger = logger;
|
||||
jni_YGConfigSetLogger(mNativePointer, logger);
|
||||
YogaNative.jni_YGConfigSetLogger(mNativePointer, logger);
|
||||
}
|
||||
|
||||
public YogaLogger getLogger() {
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* 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.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* 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.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* 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.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
114
java/com/facebook/yoga/YogaNative.java
Normal file
114
java/com/facebook/yoga/YogaNative.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* 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;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaNative {
|
||||
static {
|
||||
SoLoader.loadLibrary("yoga");
|
||||
}
|
||||
|
||||
// YGConfig related
|
||||
static native long jni_YGConfigNew();
|
||||
static native void jni_YGConfigFree(long nativePointer);
|
||||
static native void jni_YGConfigSetExperimentalFeatureEnabled(long nativePointer, int feature, boolean enabled);
|
||||
static native void jni_YGConfigSetUseWebDefaults(long nativePointer, boolean useWebDefaults);
|
||||
static native void jni_YGConfigSetPrintTreeFlag(long nativePointer, boolean enable);
|
||||
static native void jni_YGConfigSetPointScaleFactor(long nativePointer, float pixelsInPoint);
|
||||
static native void jni_YGConfigSetUseLegacyStretchBehaviour(long nativePointer, boolean useLegacyStretchBehaviour);
|
||||
static native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||
static native void jni_YGConfigSetLogger(long nativePointer, Object logger);
|
||||
|
||||
|
||||
// YGNode related
|
||||
static native int jni_YGNodeGetInstanceCount();
|
||||
static native long jni_YGNodeNew();
|
||||
static native long jni_YGNodeNewWithConfig(long configPointer);
|
||||
static native void jni_YGNodeFree(long nativePointer);
|
||||
static native void jni_YGNodeReset(long nativePointer);
|
||||
static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
||||
static native void jni_YGNodeSetIsReferenceBaseline(long nativePointer, boolean isReferenceBaseline);
|
||||
static native boolean jni_YGNodeIsReferenceBaseline(long nativePointer);
|
||||
static native void jni_YGNodeClearChildren(long nativePointer);
|
||||
static native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
|
||||
static native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height, long[] nativePointers, YogaNodeJNIBase[] nodes);
|
||||
static native void jni_YGNodeMarkDirty(long nativePointer);
|
||||
static native void jni_YGNodeMarkDirtyAndPropogateToDescendants(long nativePointer);
|
||||
static native boolean jni_YGNodeIsDirty(long nativePointer);
|
||||
static native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
|
||||
static native int jni_YGNodeStyleGetDirection(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetDirection(long nativePointer, int direction);
|
||||
static native int jni_YGNodeStyleGetFlexDirection(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection);
|
||||
static native int jni_YGNodeStyleGetJustifyContent(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent);
|
||||
static native int jni_YGNodeStyleGetAlignItems(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems);
|
||||
static native int jni_YGNodeStyleGetAlignSelf(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf);
|
||||
static native int jni_YGNodeStyleGetAlignContent(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent);
|
||||
static native int jni_YGNodeStyleGetPositionType(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType);
|
||||
static native int jni_YGNodeStyleGetFlexWrap(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexWrap(long nativePointer, int wrapType);
|
||||
static native int jni_YGNodeStyleGetOverflow(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow);
|
||||
static native int jni_YGNodeStyleGetDisplay(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetDisplay(long nativePointer, int display);
|
||||
static native float jni_YGNodeStyleGetFlex(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlex(long nativePointer, float flex);
|
||||
static native float jni_YGNodeStyleGetFlexGrow(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexGrow(long nativePointer, float flexGrow);
|
||||
static native float jni_YGNodeStyleGetFlexShrink(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexShrink(long nativePointer, float flexShrink);
|
||||
static native Object jni_YGNodeStyleGetFlexBasis(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexBasis(long nativePointer, float flexBasis);
|
||||
static native void jni_YGNodeStyleSetFlexBasisPercent(long nativePointer, float percent);
|
||||
static native void jni_YGNodeStyleSetFlexBasisAuto(long nativePointer);
|
||||
static native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
|
||||
static native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
|
||||
static native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
|
||||
static native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
|
||||
static native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
|
||||
static native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
|
||||
static native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
|
||||
static native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
|
||||
static native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border);
|
||||
static native Object jni_YGNodeStyleGetPosition(long nativePointer, int edge);
|
||||
static native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position);
|
||||
static native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent);
|
||||
static native Object jni_YGNodeStyleGetWidth(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetWidth(long nativePointer, float width);
|
||||
static native void jni_YGNodeStyleSetWidthPercent(long nativePointer, float percent);
|
||||
static native void jni_YGNodeStyleSetWidthAuto(long nativePointer);
|
||||
static native Object jni_YGNodeStyleGetHeight(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetHeight(long nativePointer, float height);
|
||||
static native void jni_YGNodeStyleSetHeightPercent(long nativePointer, float percent);
|
||||
static native void jni_YGNodeStyleSetHeightAuto(long nativePointer);
|
||||
static native Object jni_YGNodeStyleGetMinWidth(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetMinWidth(long nativePointer, float minWidth);
|
||||
static native void jni_YGNodeStyleSetMinWidthPercent(long nativePointer, float percent);
|
||||
static native Object jni_YGNodeStyleGetMinHeight(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetMinHeight(long nativePointer, float minHeight);
|
||||
static native void jni_YGNodeStyleSetMinHeightPercent(long nativePointer, float percent);
|
||||
static native Object jni_YGNodeStyleGetMaxWidth(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetMaxWidth(long nativePointer, float maxWidth);
|
||||
static native void jni_YGNodeStyleSetMaxWidthPercent(long nativePointer, float percent);
|
||||
static native Object jni_YGNodeStyleGetMaxHeight(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetMaxHeight(long nativePointer, float maxheight);
|
||||
static native void jni_YGNodeStyleSetMaxHeightPercent(long nativePointer, float percent);
|
||||
static native float jni_YGNodeStyleGetAspectRatio(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetAspectRatio(long nativePointer, float aspectRatio);
|
||||
static native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
static native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
static native void jni_YGNodePrint(long nativePointer);
|
||||
static native void jni_YGNodeSetStyleInputs(long nativePointer, float[] styleInputsArray, int size);
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* 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.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -7,760 +7,15 @@
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaNodeJNI extends YogaNode {
|
||||
public class YogaNodeJNI extends YogaNodeJNIBase {
|
||||
|
||||
static {
|
||||
SoLoader.loadLibrary("yoga");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get native instance count. Useful for testing only.
|
||||
*/
|
||||
static native int jni_YGNodeGetInstanceCount();
|
||||
|
||||
private YogaNodeJNI mOwner;
|
||||
@Nullable private List<YogaNodeJNI> mChildren;
|
||||
private YogaMeasureFunction mMeasureFunction;
|
||||
private YogaBaselineFunction mBaselineFunction;
|
||||
private long mNativePointer;
|
||||
private Object mData;
|
||||
|
||||
/* Those flags needs be in sync with YGJNI.cpp */
|
||||
private static final int MARGIN = 1;
|
||||
private static final int PADDING = 2;
|
||||
private static final int BORDER = 4;
|
||||
|
||||
private final boolean mAvoidGlobalJNIRefs;
|
||||
|
||||
@DoNotStrip
|
||||
private float mWidth = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mHeight = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mTop = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mLeft = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mMarginLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginTop = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginRight = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingTop = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingRight = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderTop = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderRight = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderBottom = 0;
|
||||
@DoNotStrip
|
||||
private int mLayoutDirection = 0;
|
||||
@DoNotStrip
|
||||
private boolean mHasNewLayout = true;
|
||||
@DoNotStrip private boolean mDoesLegacyStretchFlagAffectsLayout = false;
|
||||
|
||||
private native long jni_YGNodeNew();
|
||||
public YogaNodeJNI() {
|
||||
mAvoidGlobalJNIRefs = false;
|
||||
mNativePointer = jni_YGNodeNew();
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
super();
|
||||
}
|
||||
|
||||
private native long jni_YGNodeNewWithConfig(long configPointer, boolean avoidGlobalJNIRefs);
|
||||
public YogaNodeJNI(YogaConfig config) {
|
||||
mAvoidGlobalJNIRefs = config.avoidGlobalJNIRefs;
|
||||
mNativePointer = jni_YGNodeNewWithConfig(config.mNativePointer, mAvoidGlobalJNIRefs);
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
freeNatives();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeFree(long nativePointer);
|
||||
|
||||
/* frees the native underlying YGNode. Useful for testing. */
|
||||
public void freeNatives() {
|
||||
if (mNativePointer > 0) {
|
||||
long nativePointer = mNativePointer;
|
||||
mNativePointer = 0;
|
||||
jni_YGNodeFree(nativePointer);
|
||||
}
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeReset(long nativePointer);
|
||||
public void reset() {
|
||||
mHasNewLayout = true;
|
||||
|
||||
mWidth = YogaConstants.UNDEFINED;
|
||||
mHeight = YogaConstants.UNDEFINED;
|
||||
mTop = YogaConstants.UNDEFINED;
|
||||
mLeft = YogaConstants.UNDEFINED;
|
||||
mMarginLeft = 0;
|
||||
mMarginTop = 0;
|
||||
mMarginRight = 0;
|
||||
mMarginBottom = 0;
|
||||
mPaddingLeft = 0;
|
||||
mPaddingTop = 0;
|
||||
mPaddingRight = 0;
|
||||
mPaddingBottom = 0;
|
||||
mBorderLeft = 0;
|
||||
mBorderTop = 0;
|
||||
mBorderRight = 0;
|
||||
mBorderBottom = 0;
|
||||
mLayoutDirection = 0;
|
||||
|
||||
mMeasureFunction = null;
|
||||
mBaselineFunction = null;
|
||||
mData = null;
|
||||
mDoesLegacyStretchFlagAffectsLayout = false;
|
||||
|
||||
jni_YGNodeReset(mNativePointer);
|
||||
}
|
||||
|
||||
public int getChildCount() {
|
||||
return mChildren == null ? 0 : mChildren.size();
|
||||
}
|
||||
|
||||
public YogaNodeJNI getChildAt(int i) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException("YogaNode does not have children");
|
||||
}
|
||||
return mChildren.get(i);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
||||
|
||||
public void addChildAt(YogaNode c, int i) {
|
||||
YogaNodeJNI child = (YogaNodeJNI) c;
|
||||
if (child.mOwner != null) {
|
||||
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
||||
}
|
||||
|
||||
if (mChildren == null) {
|
||||
mChildren = new ArrayList<>(4);
|
||||
}
|
||||
mChildren.add(i, child);
|
||||
child.mOwner = this;
|
||||
jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeSetIsReferenceBaseline(long nativePointer, boolean isReferenceBaseline);
|
||||
|
||||
public void setIsReferenceBaseline(boolean isReferenceBaseline) {
|
||||
jni_YGNodeSetIsReferenceBaseline(mNativePointer, isReferenceBaseline);
|
||||
}
|
||||
|
||||
private static native boolean jni_YGNodeIsReferenceBaseline(long nativePointer);
|
||||
|
||||
public boolean isReferenceBaseline() {
|
||||
return jni_YGNodeIsReferenceBaseline(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeClearChildren(long nativePointer);
|
||||
|
||||
private void clearChildren() {
|
||||
mChildren = null;
|
||||
jni_YGNodeClearChildren(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
|
||||
public YogaNodeJNI removeChildAt(int i) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException(
|
||||
"Trying to remove a child of a YogaNode that does not have children");
|
||||
}
|
||||
final YogaNodeJNI child = mChildren.remove(i);
|
||||
child.mOwner = null;
|
||||
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
|
||||
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
|
||||
* to.
|
||||
* This method will return the parent of the {@link YogaNode} when the
|
||||
* {@link YogaNode} only belongs to one YogaTree or null when the
|
||||
* {@link YogaNode} is shared between two or more YogaTrees.
|
||||
*/
|
||||
@Nullable
|
||||
public YogaNodeJNI getOwner() {
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
/** @deprecated Use #getOwner() instead. This will be removed in the next version. */
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public YogaNodeJNI getParent() {
|
||||
return getOwner();
|
||||
}
|
||||
|
||||
public int indexOf(YogaNode child) {
|
||||
return mChildren == null ? -1 : mChildren.indexOf(child);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height, long[] nativePointers, YogaNodeJNI[] nodes);
|
||||
public void calculateLayout(float width, float height) {
|
||||
long[] nativePointers = null;
|
||||
YogaNodeJNI[] nodes = null;
|
||||
|
||||
if (mAvoidGlobalJNIRefs) {
|
||||
ArrayList<YogaNodeJNI> n = new ArrayList<>();
|
||||
n.add(this);
|
||||
for (int i = 0; i < n.size(); ++i) {
|
||||
List<YogaNodeJNI> children = n.get(i).mChildren;
|
||||
if (children != null) {
|
||||
n.addAll(children);
|
||||
}
|
||||
}
|
||||
|
||||
nodes = n.toArray(new YogaNodeJNI[n.size()]);
|
||||
nativePointers = new long[nodes.length];
|
||||
for (int i = 0; i < nodes.length; ++i) {
|
||||
nativePointers[i] = nodes[i].mNativePointer;
|
||||
}
|
||||
}
|
||||
|
||||
jni_YGNodeCalculateLayout(mNativePointer, width, height, nativePointers, nodes);
|
||||
}
|
||||
|
||||
public boolean hasNewLayout() {
|
||||
return mHasNewLayout;
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeMarkDirty(long nativePointer);
|
||||
public void dirty() {
|
||||
jni_YGNodeMarkDirty(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeMarkDirtyAndPropogateToDescendants(long nativePointer);
|
||||
|
||||
public void dirtyAllDescendants() {
|
||||
jni_YGNodeMarkDirtyAndPropogateToDescendants(mNativePointer);
|
||||
}
|
||||
|
||||
private static native boolean jni_YGNodeIsDirty(long nativePointer);
|
||||
public boolean isDirty() {
|
||||
return jni_YGNodeIsDirty(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
|
||||
@Override
|
||||
public void copyStyle(YogaNode srcNode) {
|
||||
jni_YGNodeCopyStyle(mNativePointer, ((YogaNodeJNI) srcNode).mNativePointer);
|
||||
}
|
||||
|
||||
public void markLayoutSeen() {
|
||||
mHasNewLayout = false;
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetDirection(long nativePointer);
|
||||
public YogaDirection getStyleDirection() {
|
||||
return YogaDirection.fromInt(jni_YGNodeStyleGetDirection(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetDirection(long nativePointer, int direction);
|
||||
public void setDirection(YogaDirection direction) {
|
||||
jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetFlexDirection(long nativePointer);
|
||||
public YogaFlexDirection getFlexDirection() {
|
||||
return YogaFlexDirection.fromInt(jni_YGNodeStyleGetFlexDirection(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection);
|
||||
public void setFlexDirection(YogaFlexDirection flexDirection) {
|
||||
jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetJustifyContent(long nativePointer);
|
||||
public YogaJustify getJustifyContent() {
|
||||
return YogaJustify.fromInt(jni_YGNodeStyleGetJustifyContent(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent);
|
||||
public void setJustifyContent(YogaJustify justifyContent) {
|
||||
jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetAlignItems(long nativePointer);
|
||||
public YogaAlign getAlignItems() {
|
||||
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignItems(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems);
|
||||
public void setAlignItems(YogaAlign alignItems) {
|
||||
jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetAlignSelf(long nativePointer);
|
||||
public YogaAlign getAlignSelf() {
|
||||
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignSelf(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf);
|
||||
public void setAlignSelf(YogaAlign alignSelf) {
|
||||
jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetAlignContent(long nativePointer);
|
||||
public YogaAlign getAlignContent() {
|
||||
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignContent(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent);
|
||||
public void setAlignContent(YogaAlign alignContent) {
|
||||
jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetPositionType(long nativePointer);
|
||||
public YogaPositionType getPositionType() {
|
||||
return YogaPositionType.fromInt(jni_YGNodeStyleGetPositionType(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType);
|
||||
public void setPositionType(YogaPositionType positionType) {
|
||||
jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetFlexWrap(long nativePointer);
|
||||
public YogaWrap getWrap() {
|
||||
return YogaWrap.fromInt(jni_YGNodeStyleGetFlexWrap(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexWrap(long nativePointer, int wrapType);
|
||||
public void setWrap(YogaWrap flexWrap) {
|
||||
jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetOverflow(long nativePointer);
|
||||
public YogaOverflow getOverflow() {
|
||||
return YogaOverflow.fromInt(jni_YGNodeStyleGetOverflow(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow);
|
||||
public void setOverflow(YogaOverflow overflow) {
|
||||
jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetDisplay(long nativePointer);
|
||||
public YogaDisplay getDisplay() {
|
||||
return YogaDisplay.fromInt(jni_YGNodeStyleGetDisplay(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetDisplay(long nativePointer, int display);
|
||||
public void setDisplay(YogaDisplay display) {
|
||||
jni_YGNodeStyleSetDisplay(mNativePointer, display.intValue());
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetFlex(long nativePointer);
|
||||
public float getFlex() {
|
||||
return jni_YGNodeStyleGetFlex(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlex(long nativePointer, float flex);
|
||||
public void setFlex(float flex) {
|
||||
jni_YGNodeStyleSetFlex(mNativePointer, flex);
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetFlexGrow(long nativePointer);
|
||||
public float getFlexGrow() {
|
||||
return jni_YGNodeStyleGetFlexGrow(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexGrow(long nativePointer, float flexGrow);
|
||||
public void setFlexGrow(float flexGrow) {
|
||||
jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow);
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetFlexShrink(long nativePointer);
|
||||
public float getFlexShrink() {
|
||||
return jni_YGNodeStyleGetFlexShrink(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexShrink(long nativePointer, float flexShrink);
|
||||
public void setFlexShrink(float flexShrink) {
|
||||
jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetFlexBasis(long nativePointer);
|
||||
public YogaValue getFlexBasis() {
|
||||
return (YogaValue) jni_YGNodeStyleGetFlexBasis(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexBasis(long nativePointer, float flexBasis);
|
||||
public void setFlexBasis(float flexBasis) {
|
||||
jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexBasisPercent(long nativePointer, float percent);
|
||||
public void setFlexBasisPercent(float percent) {
|
||||
jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexBasisAuto(long nativePointer);
|
||||
public void setFlexBasisAuto() {
|
||||
jni_YGNodeStyleSetFlexBasisAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
|
||||
public YogaValue getMargin(YogaEdge edge) {
|
||||
return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
|
||||
public void setMargin(YogaEdge edge, float margin) {
|
||||
jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
|
||||
public void setMarginPercent(YogaEdge edge, float percent) {
|
||||
jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
|
||||
public void setMarginAuto(YogaEdge edge) {
|
||||
jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
|
||||
public YogaValue getPadding(YogaEdge edge) {
|
||||
return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
|
||||
public void setPadding(YogaEdge edge, float padding) {
|
||||
jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
|
||||
public void setPaddingPercent(YogaEdge edge, float percent) {
|
||||
jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
|
||||
public float getBorder(YogaEdge edge) {
|
||||
return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border);
|
||||
public void setBorder(YogaEdge edge, float border) {
|
||||
jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetPosition(long nativePointer, int edge);
|
||||
public YogaValue getPosition(YogaEdge edge) {
|
||||
return (YogaValue) jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position);
|
||||
public void setPosition(YogaEdge edge, float position) {
|
||||
jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent);
|
||||
public void setPositionPercent(YogaEdge edge, float percent) {
|
||||
jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetWidth(long nativePointer);
|
||||
public YogaValue getWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetWidth(long nativePointer, float width);
|
||||
public void setWidth(float width) {
|
||||
jni_YGNodeStyleSetWidth(mNativePointer, width);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetWidthPercent(long nativePointer, float percent);
|
||||
public void setWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetWidthAuto(long nativePointer);
|
||||
public void setWidthAuto() {
|
||||
jni_YGNodeStyleSetWidthAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetHeight(long nativePointer);
|
||||
public YogaValue getHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetHeight(long nativePointer, float height);
|
||||
public void setHeight(float height) {
|
||||
jni_YGNodeStyleSetHeight(mNativePointer, height);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetHeightPercent(long nativePointer, float percent);
|
||||
public void setHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetHeightAuto(long nativePointer);
|
||||
public void setHeightAuto() {
|
||||
jni_YGNodeStyleSetHeightAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMinWidth(long nativePointer);
|
||||
public YogaValue getMinWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMinWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMinWidth(long nativePointer, float minWidth);
|
||||
public void setMinWidth(float minWidth) {
|
||||
jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMinWidthPercent(long nativePointer, float percent);
|
||||
public void setMinWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMinHeight(long nativePointer);
|
||||
public YogaValue getMinHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMinHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMinHeight(long nativePointer, float minHeight);
|
||||
public void setMinHeight(float minHeight) {
|
||||
jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMinHeightPercent(long nativePointer, float percent);
|
||||
public void setMinHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMaxWidth(long nativePointer);
|
||||
public YogaValue getMaxWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMaxWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMaxWidth(long nativePointer, float maxWidth);
|
||||
public void setMaxWidth(float maxWidth) {
|
||||
jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMaxWidthPercent(long nativePointer, float percent);
|
||||
public void setMaxWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMaxHeight(long nativePointer);
|
||||
public YogaValue getMaxHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMaxHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMaxHeight(long nativePointer, float maxheight);
|
||||
public void setMaxHeight(float maxheight) {
|
||||
jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMaxHeightPercent(long nativePointer, float percent);
|
||||
public void setMaxHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetAspectRatio(long nativePointer);
|
||||
public float getAspectRatio() {
|
||||
return jni_YGNodeStyleGetAspectRatio(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetAspectRatio(long nativePointer, float aspectRatio);
|
||||
public void setAspectRatio(float aspectRatio) {
|
||||
jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio);
|
||||
}
|
||||
|
||||
public float getLayoutX() {
|
||||
return mLeft;
|
||||
}
|
||||
|
||||
public float getLayoutY() {
|
||||
return mTop;
|
||||
}
|
||||
|
||||
public float getLayoutWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
public float getLayoutHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
public boolean getDoesLegacyStretchFlagAffectsLayout() {
|
||||
return mDoesLegacyStretchFlagAffectsLayout;
|
||||
}
|
||||
|
||||
public float getLayoutMargin(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mMarginLeft;
|
||||
case TOP:
|
||||
return mMarginTop;
|
||||
case RIGHT:
|
||||
return mMarginRight;
|
||||
case BOTTOM:
|
||||
return mMarginBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mMarginRight : mMarginLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mMarginLeft : mMarginRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout margins of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public float getLayoutPadding(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mPaddingLeft;
|
||||
case TOP:
|
||||
return mPaddingTop;
|
||||
case RIGHT:
|
||||
return mPaddingRight;
|
||||
case BOTTOM:
|
||||
return mPaddingBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mPaddingRight : mPaddingLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mPaddingLeft : mPaddingRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout paddings of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public float getLayoutBorder(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mBorderLeft;
|
||||
case TOP:
|
||||
return mBorderTop;
|
||||
case RIGHT:
|
||||
return mBorderRight;
|
||||
case BOTTOM:
|
||||
return mBorderBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderRight : mBorderLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderLeft : mBorderRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout border of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public YogaDirection getLayoutDirection() {
|
||||
return YogaDirection.fromInt(mLayoutDirection);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
|
||||
mMeasureFunction = measureFunction;
|
||||
jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null);
|
||||
}
|
||||
|
||||
// Implementation Note: Why this method needs to stay final
|
||||
//
|
||||
// We cache the jmethodid for this method in Yoga code. This means that even if a subclass
|
||||
// were to override measure, we'd still call this implementation from layout code since the
|
||||
// overriding method will have a different jmethodid. This is final to prevent that mistake.
|
||||
@DoNotStrip
|
||||
public final long measure(float width, int widthMode, float height, int heightMode) {
|
||||
if (!isMeasureDefined()) {
|
||||
throw new RuntimeException("Measure function isn't defined!");
|
||||
}
|
||||
|
||||
return mMeasureFunction.measure(
|
||||
this,
|
||||
width,
|
||||
YogaMeasureMode.fromInt(widthMode),
|
||||
height,
|
||||
YogaMeasureMode.fromInt(heightMode));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
public void setBaselineFunction(YogaBaselineFunction baselineFunction) {
|
||||
mBaselineFunction = baselineFunction;
|
||||
jni_YGNodeSetHasBaselineFunc(mNativePointer, baselineFunction != null);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public final float baseline(float width, float height) {
|
||||
return mBaselineFunction.baseline(this, width, height);
|
||||
}
|
||||
|
||||
public boolean isMeasureDefined() {
|
||||
return mMeasureFunction != null;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
mData = data;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
private static native void jni_YGNodePrint(long nativePointer);
|
||||
|
||||
/**
|
||||
* Use the set logger (defaults to adb log) to print out the styles, children, and computed
|
||||
* layout of the tree rooted at this node.
|
||||
*/
|
||||
public void print() {
|
||||
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
|
||||
* the child in the mChildren datastructure. @DoNotStrip: called from JNI
|
||||
*
|
||||
* @return the nativePointer of the newNode {@linl YogaNode}
|
||||
*/
|
||||
@DoNotStrip
|
||||
private final long replaceChild(YogaNodeJNI newNode, int childIndex) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException("Cannot replace child. YogaNode does not have children");
|
||||
}
|
||||
mChildren.remove(childIndex);
|
||||
mChildren.add(childIndex, newNode);
|
||||
newNode.mOwner = this;
|
||||
return newNode.mNativePointer;
|
||||
super(config);
|
||||
}
|
||||
}
|
||||
|
659
java/com/facebook/yoga/YogaNodeJNIBase.java
Normal file
659
java/com/facebook/yoga/YogaNodeJNIBase.java
Normal file
@@ -0,0 +1,659 @@
|
||||
/**
|
||||
* 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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@DoNotStrip
|
||||
public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
|
||||
private YogaNodeJNIBase mOwner;
|
||||
@Nullable private List<YogaNodeJNIBase> mChildren;
|
||||
private YogaMeasureFunction mMeasureFunction;
|
||||
private YogaBaselineFunction mBaselineFunction;
|
||||
private long mNativePointer;
|
||||
private Object mData;
|
||||
|
||||
/* Those flags needs be in sync with YGJNI.cpp */
|
||||
private static final int MARGIN = 1;
|
||||
private static final int PADDING = 2;
|
||||
private static final int BORDER = 4;
|
||||
|
||||
@DoNotStrip
|
||||
private float mWidth = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mHeight = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mTop = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mLeft = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mMarginLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginTop = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginRight = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingTop = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingRight = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderTop = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderRight = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderBottom = 0;
|
||||
@DoNotStrip
|
||||
private int mLayoutDirection = 0;
|
||||
@DoNotStrip
|
||||
private boolean mHasNewLayout = true;
|
||||
@DoNotStrip private boolean mDoesLegacyStretchFlagAffectsLayout = false;
|
||||
|
||||
public YogaNodeJNIBase() {
|
||||
mNativePointer = YogaNative.jni_YGNodeNew();
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
public YogaNodeJNIBase(YogaConfig config) {
|
||||
mNativePointer = YogaNative.jni_YGNodeNewWithConfig(config.mNativePointer);
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
freeNatives();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/* frees the native underlying YGNode. Useful for testing. */
|
||||
public void freeNatives() {
|
||||
if (mNativePointer > 0) {
|
||||
long nativePointer = mNativePointer;
|
||||
mNativePointer = 0;
|
||||
YogaNative.jni_YGNodeFree(nativePointer);
|
||||
}
|
||||
}
|
||||
public void reset() {
|
||||
mHasNewLayout = true;
|
||||
|
||||
mWidth = YogaConstants.UNDEFINED;
|
||||
mHeight = YogaConstants.UNDEFINED;
|
||||
mTop = YogaConstants.UNDEFINED;
|
||||
mLeft = YogaConstants.UNDEFINED;
|
||||
mMarginLeft = 0;
|
||||
mMarginTop = 0;
|
||||
mMarginRight = 0;
|
||||
mMarginBottom = 0;
|
||||
mPaddingLeft = 0;
|
||||
mPaddingTop = 0;
|
||||
mPaddingRight = 0;
|
||||
mPaddingBottom = 0;
|
||||
mBorderLeft = 0;
|
||||
mBorderTop = 0;
|
||||
mBorderRight = 0;
|
||||
mBorderBottom = 0;
|
||||
mLayoutDirection = 0;
|
||||
|
||||
mMeasureFunction = null;
|
||||
mBaselineFunction = null;
|
||||
mData = null;
|
||||
mDoesLegacyStretchFlagAffectsLayout = false;
|
||||
|
||||
YogaNative.jni_YGNodeReset(mNativePointer);
|
||||
}
|
||||
|
||||
public int getChildCount() {
|
||||
return mChildren == null ? 0 : mChildren.size();
|
||||
}
|
||||
|
||||
public YogaNodeJNIBase getChildAt(int i) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException("YogaNode does not have children");
|
||||
}
|
||||
return mChildren.get(i);
|
||||
}
|
||||
|
||||
public void addChildAt(YogaNode c, int i) {
|
||||
YogaNodeJNIBase child = (YogaNodeJNIBase) c;
|
||||
if (child.mOwner != null) {
|
||||
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
||||
}
|
||||
|
||||
if (mChildren == null) {
|
||||
mChildren = new ArrayList<>(4);
|
||||
}
|
||||
mChildren.add(i, child);
|
||||
child.mOwner = this;
|
||||
YogaNative.jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
||||
}
|
||||
|
||||
public void setIsReferenceBaseline(boolean isReferenceBaseline) {
|
||||
YogaNative.jni_YGNodeSetIsReferenceBaseline(mNativePointer, isReferenceBaseline);
|
||||
}
|
||||
|
||||
public boolean isReferenceBaseline() {
|
||||
return YogaNative.jni_YGNodeIsReferenceBaseline(mNativePointer);
|
||||
}
|
||||
|
||||
private void clearChildren() {
|
||||
mChildren = null;
|
||||
YogaNative.jni_YGNodeClearChildren(mNativePointer);
|
||||
}
|
||||
|
||||
public YogaNodeJNIBase removeChildAt(int i) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException(
|
||||
"Trying to remove a child of a YogaNode that does not have children");
|
||||
}
|
||||
final YogaNodeJNIBase child = mChildren.remove(i);
|
||||
child.mOwner = null;
|
||||
YogaNative.jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
|
||||
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
|
||||
* to.
|
||||
* This method will return the parent of the {@link YogaNode} when the
|
||||
* {@link YogaNode} only belongs to one YogaTree or null when the
|
||||
* {@link YogaNode} is shared between two or more YogaTrees.
|
||||
*/
|
||||
@Nullable
|
||||
public YogaNodeJNIBase getOwner() {
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
/** @deprecated Use #getOwner() instead. This will be removed in the next version. */
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public YogaNodeJNIBase getParent() {
|
||||
return getOwner();
|
||||
}
|
||||
|
||||
public int indexOf(YogaNode child) {
|
||||
return mChildren == null ? -1 : mChildren.indexOf(child);
|
||||
}
|
||||
|
||||
public void calculateLayout(float width, float height) {
|
||||
long[] nativePointers = null;
|
||||
YogaNodeJNIBase[] nodes = null;
|
||||
|
||||
ArrayList<YogaNodeJNIBase> n = new ArrayList<>();
|
||||
n.add(this);
|
||||
for (int i = 0; i < n.size(); ++i) {
|
||||
List<YogaNodeJNIBase> children = n.get(i).mChildren;
|
||||
if (children != null) {
|
||||
n.addAll(children);
|
||||
}
|
||||
}
|
||||
|
||||
nodes = n.toArray(new YogaNodeJNIBase[n.size()]);
|
||||
nativePointers = new long[nodes.length];
|
||||
for (int i = 0; i < nodes.length; ++i) {
|
||||
nativePointers[i] = nodes[i].mNativePointer;
|
||||
}
|
||||
|
||||
YogaNative.jni_YGNodeCalculateLayout(mNativePointer, width, height, nativePointers, nodes);
|
||||
}
|
||||
|
||||
public boolean hasNewLayout() {
|
||||
return mHasNewLayout;
|
||||
}
|
||||
|
||||
public void dirty() {
|
||||
YogaNative.jni_YGNodeMarkDirty(mNativePointer);
|
||||
}
|
||||
|
||||
public void dirtyAllDescendants() {
|
||||
YogaNative.jni_YGNodeMarkDirtyAndPropogateToDescendants(mNativePointer);
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return YogaNative.jni_YGNodeIsDirty(mNativePointer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyStyle(YogaNode srcNode) {
|
||||
YogaNative.jni_YGNodeCopyStyle(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer);
|
||||
}
|
||||
|
||||
public void markLayoutSeen() {
|
||||
mHasNewLayout = false;
|
||||
}
|
||||
|
||||
public YogaDirection getStyleDirection() {
|
||||
return YogaDirection.fromInt(YogaNative.jni_YGNodeStyleGetDirection(mNativePointer));
|
||||
}
|
||||
|
||||
public void setDirection(YogaDirection direction) {
|
||||
YogaNative.jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue());
|
||||
}
|
||||
|
||||
public YogaFlexDirection getFlexDirection() {
|
||||
return YogaFlexDirection.fromInt(YogaNative.jni_YGNodeStyleGetFlexDirection(mNativePointer));
|
||||
}
|
||||
|
||||
public void setFlexDirection(YogaFlexDirection flexDirection) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue());
|
||||
}
|
||||
|
||||
public YogaJustify getJustifyContent() {
|
||||
return YogaJustify.fromInt(YogaNative.jni_YGNodeStyleGetJustifyContent(mNativePointer));
|
||||
}
|
||||
|
||||
public void setJustifyContent(YogaJustify justifyContent) {
|
||||
YogaNative.jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue());
|
||||
}
|
||||
|
||||
public YogaAlign getAlignItems() {
|
||||
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignItems(mNativePointer));
|
||||
}
|
||||
|
||||
public void setAlignItems(YogaAlign alignItems) {
|
||||
YogaNative.jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue());
|
||||
}
|
||||
|
||||
public YogaAlign getAlignSelf() {
|
||||
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignSelf(mNativePointer));
|
||||
}
|
||||
|
||||
public void setAlignSelf(YogaAlign alignSelf) {
|
||||
YogaNative.jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue());
|
||||
}
|
||||
|
||||
public YogaAlign getAlignContent() {
|
||||
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignContent(mNativePointer));
|
||||
}
|
||||
|
||||
public void setAlignContent(YogaAlign alignContent) {
|
||||
YogaNative.jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue());
|
||||
}
|
||||
|
||||
public YogaPositionType getPositionType() {
|
||||
return YogaPositionType.fromInt(YogaNative.jni_YGNodeStyleGetPositionType(mNativePointer));
|
||||
}
|
||||
|
||||
public void setPositionType(YogaPositionType positionType) {
|
||||
YogaNative.jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue());
|
||||
}
|
||||
|
||||
public YogaWrap getWrap() {
|
||||
return YogaWrap.fromInt(YogaNative.jni_YGNodeStyleGetFlexWrap(mNativePointer));
|
||||
}
|
||||
|
||||
public void setWrap(YogaWrap flexWrap) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue());
|
||||
}
|
||||
|
||||
public YogaOverflow getOverflow() {
|
||||
return YogaOverflow.fromInt(YogaNative.jni_YGNodeStyleGetOverflow(mNativePointer));
|
||||
}
|
||||
|
||||
public void setOverflow(YogaOverflow overflow) {
|
||||
YogaNative.jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue());
|
||||
}
|
||||
|
||||
public YogaDisplay getDisplay() {
|
||||
return YogaDisplay.fromInt(YogaNative.jni_YGNodeStyleGetDisplay(mNativePointer));
|
||||
}
|
||||
|
||||
public void setDisplay(YogaDisplay display) {
|
||||
YogaNative.jni_YGNodeStyleSetDisplay(mNativePointer, display.intValue());
|
||||
}
|
||||
|
||||
public float getFlex() {
|
||||
return YogaNative.jni_YGNodeStyleGetFlex(mNativePointer);
|
||||
}
|
||||
|
||||
public void setFlex(float flex) {
|
||||
YogaNative.jni_YGNodeStyleSetFlex(mNativePointer, flex);
|
||||
}
|
||||
|
||||
public float getFlexGrow() {
|
||||
return YogaNative.jni_YGNodeStyleGetFlexGrow(mNativePointer);
|
||||
}
|
||||
|
||||
public void setFlexGrow(float flexGrow) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow);
|
||||
}
|
||||
|
||||
public float getFlexShrink() {
|
||||
return YogaNative.jni_YGNodeStyleGetFlexShrink(mNativePointer);
|
||||
}
|
||||
|
||||
public void setFlexShrink(float flexShrink) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
|
||||
}
|
||||
|
||||
public YogaValue getFlexBasis() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetFlexBasis(mNativePointer);
|
||||
}
|
||||
|
||||
public void setFlexBasis(float flexBasis) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis);
|
||||
}
|
||||
|
||||
public void setFlexBasisPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public void setFlexBasisAuto() {
|
||||
YogaNative.jni_YGNodeStyleSetFlexBasisAuto(mNativePointer);
|
||||
}
|
||||
|
||||
public YogaValue getMargin(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public void setMargin(YogaEdge edge, float margin) {
|
||||
YogaNative.jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
|
||||
}
|
||||
|
||||
public void setMarginPercent(YogaEdge edge, float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
public void setMarginAuto(YogaEdge edge) {
|
||||
YogaNative.jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public YogaValue getPadding(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public void setPadding(YogaEdge edge, float padding) {
|
||||
YogaNative.jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
|
||||
}
|
||||
|
||||
public void setPaddingPercent(YogaEdge edge, float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
public float getBorder(YogaEdge edge) {
|
||||
return YogaNative.jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public void setBorder(YogaEdge edge, float border) {
|
||||
YogaNative.jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
|
||||
}
|
||||
|
||||
public YogaValue getPosition(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public void setPosition(YogaEdge edge, float position) {
|
||||
YogaNative.jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position);
|
||||
}
|
||||
|
||||
public void setPositionPercent(YogaEdge edge, float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
public YogaValue getWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetWidth(mNativePointer);
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
YogaNative.jni_YGNodeStyleSetWidth(mNativePointer, width);
|
||||
}
|
||||
|
||||
public void setWidthPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public void setWidthAuto() {
|
||||
YogaNative.jni_YGNodeStyleSetWidthAuto(mNativePointer);
|
||||
}
|
||||
|
||||
public YogaValue getHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetHeight(mNativePointer);
|
||||
}
|
||||
|
||||
public void setHeight(float height) {
|
||||
YogaNative.jni_YGNodeStyleSetHeight(mNativePointer, height);
|
||||
}
|
||||
|
||||
public void setHeightPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public void setHeightAuto() {
|
||||
YogaNative.jni_YGNodeStyleSetHeightAuto(mNativePointer);
|
||||
}
|
||||
|
||||
public YogaValue getMinWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMinWidth(mNativePointer);
|
||||
}
|
||||
|
||||
public void setMinWidth(float minWidth) {
|
||||
YogaNative.jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth);
|
||||
}
|
||||
|
||||
public void setMinWidthPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public YogaValue getMinHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMinHeight(mNativePointer);
|
||||
}
|
||||
|
||||
public void setMinHeight(float minHeight) {
|
||||
YogaNative.jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight);
|
||||
}
|
||||
|
||||
public void setMinHeightPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public YogaValue getMaxWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMaxWidth(mNativePointer);
|
||||
}
|
||||
|
||||
public void setMaxWidth(float maxWidth) {
|
||||
YogaNative.jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth);
|
||||
}
|
||||
|
||||
public void setMaxWidthPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public YogaValue getMaxHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMaxHeight(mNativePointer);
|
||||
}
|
||||
|
||||
public void setMaxHeight(float maxheight) {
|
||||
YogaNative.jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight);
|
||||
}
|
||||
|
||||
public void setMaxHeightPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public float getAspectRatio() {
|
||||
return YogaNative.jni_YGNodeStyleGetAspectRatio(mNativePointer);
|
||||
}
|
||||
|
||||
public void setAspectRatio(float aspectRatio) {
|
||||
YogaNative.jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio);
|
||||
}
|
||||
|
||||
public float getLayoutX() {
|
||||
return mLeft;
|
||||
}
|
||||
|
||||
public float getLayoutY() {
|
||||
return mTop;
|
||||
}
|
||||
|
||||
public float getLayoutWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
public float getLayoutHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
public boolean getDoesLegacyStretchFlagAffectsLayout() {
|
||||
return mDoesLegacyStretchFlagAffectsLayout;
|
||||
}
|
||||
|
||||
public float getLayoutMargin(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mMarginLeft;
|
||||
case TOP:
|
||||
return mMarginTop;
|
||||
case RIGHT:
|
||||
return mMarginRight;
|
||||
case BOTTOM:
|
||||
return mMarginBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mMarginRight : mMarginLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mMarginLeft : mMarginRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout margins of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public float getLayoutPadding(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mPaddingLeft;
|
||||
case TOP:
|
||||
return mPaddingTop;
|
||||
case RIGHT:
|
||||
return mPaddingRight;
|
||||
case BOTTOM:
|
||||
return mPaddingBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mPaddingRight : mPaddingLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mPaddingLeft : mPaddingRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout paddings of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public float getLayoutBorder(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mBorderLeft;
|
||||
case TOP:
|
||||
return mBorderTop;
|
||||
case RIGHT:
|
||||
return mBorderRight;
|
||||
case BOTTOM:
|
||||
return mBorderBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderRight : mBorderLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderLeft : mBorderRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout border of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public YogaDirection getLayoutDirection() {
|
||||
return YogaDirection.fromInt(mLayoutDirection);
|
||||
}
|
||||
|
||||
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
|
||||
mMeasureFunction = measureFunction;
|
||||
YogaNative.jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null);
|
||||
}
|
||||
|
||||
// Implementation Note: Why this method needs to stay final
|
||||
//
|
||||
// We cache the jmethodid for this method in Yoga code. This means that even if a subclass
|
||||
// were to override measure, we'd still call this implementation from layout code since the
|
||||
// overriding method will have a different jmethodid. This is final to prevent that mistake.
|
||||
@DoNotStrip
|
||||
public final long measure(float width, int widthMode, float height, int heightMode) {
|
||||
if (!isMeasureDefined()) {
|
||||
throw new RuntimeException("Measure function isn't defined!");
|
||||
}
|
||||
|
||||
return mMeasureFunction.measure(
|
||||
this,
|
||||
width,
|
||||
YogaMeasureMode.fromInt(widthMode),
|
||||
height,
|
||||
YogaMeasureMode.fromInt(heightMode));
|
||||
}
|
||||
|
||||
public void setBaselineFunction(YogaBaselineFunction baselineFunction) {
|
||||
mBaselineFunction = baselineFunction;
|
||||
YogaNative.jni_YGNodeSetHasBaselineFunc(mNativePointer, baselineFunction != null);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public final float baseline(float width, float height) {
|
||||
return mBaselineFunction.baseline(this, width, height);
|
||||
}
|
||||
|
||||
public boolean isMeasureDefined() {
|
||||
return mMeasureFunction != null;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
mData = data;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the set logger (defaults to adb log) to print out the styles, children, and computed
|
||||
* layout of the tree rooted at this node.
|
||||
*/
|
||||
public void print() {
|
||||
YogaNative.jni_YGNodePrint(mNativePointer);
|
||||
}
|
||||
|
||||
public void setStyleInputs(float[] styleInputsArray, int size) {
|
||||
YogaNative.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
|
||||
* the child in the mChildren datastructure. @DoNotStrip: called from JNI
|
||||
*
|
||||
* @return the nativePointer of the newNode {@linl YogaNode}
|
||||
*/
|
||||
@DoNotStrip
|
||||
private final long replaceChild(YogaNodeJNIBase newNode, int childIndex) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException("Cannot replace child. YogaNode does not have children");
|
||||
}
|
||||
mChildren.remove(childIndex);
|
||||
mChildren.add(childIndex, newNode);
|
||||
newNode.mOwner = this;
|
||||
return newNode.mNativePointer;
|
||||
}
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@@ -8,9 +8,12 @@
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/log.h>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "YGJTypes.h"
|
||||
|
||||
using namespace facebook::jni;
|
||||
using namespace std;
|
||||
using facebook::yoga::detail::Log;
|
||||
@@ -58,14 +61,6 @@ enum YGStyleInput {
|
||||
IsReferenceBaseline,
|
||||
};
|
||||
|
||||
struct JYogaNode : public JavaClass<JYogaNode> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNI;";
|
||||
};
|
||||
|
||||
struct JYogaConfig : public JavaClass<JYogaConfig> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaConfig;";
|
||||
};
|
||||
|
||||
class PtrJNodeMap {
|
||||
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
||||
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
||||
@@ -94,32 +89,51 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct YGNodeContext {
|
||||
weak_ref<jobject>* ygNodeJObjectRef{nullptr};
|
||||
int edgeSetFlag = 0;
|
||||
~YGNodeContext() {
|
||||
delete ygNodeJObjectRef;
|
||||
namespace {
|
||||
|
||||
union YGNodeContext {
|
||||
uintptr_t edgesSet = 0;
|
||||
void* asVoidPtr;
|
||||
};
|
||||
|
||||
class YGNodeEdges {
|
||||
uintptr_t edges_;
|
||||
|
||||
public:
|
||||
enum Edge {
|
||||
MARGIN = 1,
|
||||
PADDING = 2,
|
||||
BORDER = 4,
|
||||
};
|
||||
|
||||
YGNodeEdges(YGNodeRef node) {
|
||||
auto context = YGNodeContext{};
|
||||
context.asVoidPtr = node->getContext();
|
||||
edges_ = context.edgesSet;
|
||||
}
|
||||
|
||||
void setOn(YGNodeRef node) {
|
||||
auto context = YGNodeContext{};
|
||||
context.edgesSet = edges_;
|
||||
node->setContext(context.asVoidPtr);
|
||||
}
|
||||
|
||||
bool has(Edge edge) {
|
||||
return (edges_ & edge) == edge;
|
||||
}
|
||||
|
||||
YGNodeEdges& add(Edge edge) {
|
||||
edges_ |= edge;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
const int MARGIN = 1;
|
||||
const int PADDING = 2;
|
||||
const int BORDER = 3;
|
||||
|
||||
static inline YGNodeContext* ygNodeRefToYGNodeContext(YGNodeRef node) {
|
||||
return reinterpret_cast<YGNodeContext*>(node->getContext());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
static inline local_ref<JYogaNode> YGNodeJobject(
|
||||
YGNodeRef node,
|
||||
void* layoutContext) {
|
||||
if (layoutContext == nullptr) {
|
||||
return (reinterpret_cast<weak_ref<JYogaNode>*>(
|
||||
ygNodeRefToYGNodeContext(node)->ygNodeJObjectRef))
|
||||
->lockLocal();
|
||||
} else {
|
||||
return reinterpret_cast<PtrJNodeMap*>(layoutContext)->ref(node);
|
||||
}
|
||||
return reinterpret_cast<PtrJNodeMap*>(layoutContext)->ref(node);
|
||||
}
|
||||
|
||||
static void YGTransferLayoutDirection(
|
||||
@@ -147,7 +161,7 @@ static void YGTransferLayoutOutputsRecursive(
|
||||
return;
|
||||
}
|
||||
|
||||
int edgeSetFlag = ygNodeRefToYGNodeContext(root)->edgeSetFlag;
|
||||
auto edgesSet = YGNodeEdges{root};
|
||||
|
||||
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
|
||||
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
|
||||
@@ -191,8 +205,10 @@ static void YGTransferLayoutOutputsRecursive(
|
||||
obj->setFieldValue<jboolean>(
|
||||
doesLegacyStretchBehaviour,
|
||||
YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root));
|
||||
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
||||
YGTransferLayoutDirection(root, obj);
|
||||
|
||||
if ((edgeSetFlag & MARGIN) == MARGIN) {
|
||||
if (edgesSet.has(YGNodeEdges::MARGIN)) {
|
||||
obj->setFieldValue(
|
||||
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
||||
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
||||
@@ -202,7 +218,7 @@ static void YGTransferLayoutOutputsRecursive(
|
||||
marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
||||
}
|
||||
|
||||
if ((edgeSetFlag & PADDING) == PADDING) {
|
||||
if (edgesSet.has(YGNodeEdges::PADDING)) {
|
||||
obj->setFieldValue(
|
||||
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
||||
obj->setFieldValue(
|
||||
@@ -213,7 +229,7 @@ static void YGTransferLayoutOutputsRecursive(
|
||||
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
||||
}
|
||||
|
||||
if ((edgeSetFlag & BORDER) == BORDER) {
|
||||
if (edgesSet.has(YGNodeEdges::BORDER)) {
|
||||
obj->setFieldValue(
|
||||
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
||||
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
||||
@@ -223,8 +239,6 @@ static void YGTransferLayoutOutputsRecursive(
|
||||
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
||||
}
|
||||
|
||||
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
||||
YGTransferLayoutDirection(root, obj);
|
||||
root->setHasNewLayout(false);
|
||||
|
||||
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
||||
@@ -250,10 +264,7 @@ static float YGJNIBaselineFunc(
|
||||
float height,
|
||||
void* layoutContext) {
|
||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||
static auto baselineFunc =
|
||||
findClassStatic("com/facebook/yoga/YogaNodeJNI")
|
||||
->getMethod<jfloat(jfloat, jfloat)>("baseline");
|
||||
return baselineFunc(obj, width, height);
|
||||
return obj->baseline(width, height);
|
||||
} else {
|
||||
return height;
|
||||
}
|
||||
@@ -275,13 +286,9 @@ static YGSize YGJNIMeasureFunc(
|
||||
YGMeasureMode heightMode,
|
||||
void* layoutContext) {
|
||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||
static auto measureFunc =
|
||||
findClassStatic("com/facebook/yoga/YogaNodeJNI")
|
||||
->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
|
||||
|
||||
YGTransferLayoutDirection(node, obj);
|
||||
const auto measureResult =
|
||||
measureFunc(obj, width, widthMode, height, heightMode);
|
||||
obj->measure(width, widthMode, height, heightMode);
|
||||
|
||||
static_assert(
|
||||
sizeof(measureResult) == 8,
|
||||
@@ -307,10 +314,6 @@ static YGSize YGJNIMeasureFunc(
|
||||
}
|
||||
}
|
||||
|
||||
struct JYogaLogLevel : public JavaClass<JYogaLogLevel> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
||||
};
|
||||
|
||||
static int YGJNILogFunc(
|
||||
const YGConfigRef config,
|
||||
const YGNodeRef node,
|
||||
@@ -322,50 +325,31 @@ static int YGJNILogFunc(
|
||||
std::vector<char> buffer(1 + result);
|
||||
vsnprintf(buffer.data(), buffer.size(), format, args);
|
||||
|
||||
static auto logFunc =
|
||||
findClassStatic("com/facebook/yoga/YogaLogger")
|
||||
->getMethod<void(
|
||||
local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
|
||||
|
||||
static auto logLevelFromInt =
|
||||
JYogaLogLevel::javaClassStatic()
|
||||
->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
|
||||
|
||||
auto jloggerPtr =
|
||||
static_cast<global_ref<jobject>*>(YGConfigGetContext(config));
|
||||
static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config));
|
||||
if (jloggerPtr != nullptr) {
|
||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||
logFunc(
|
||||
*jloggerPtr,
|
||||
obj,
|
||||
logLevelFromInt(
|
||||
JYogaLogLevel::javaClassStatic(), static_cast<jint>(level)),
|
||||
Environment::current()->NewStringUTF(buffer.data()));
|
||||
(*jloggerPtr)
|
||||
->log(
|
||||
obj,
|
||||
JYogaLogLevel::fromInt(level),
|
||||
Environment::current()->NewStringUTF(buffer.data()));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
YGNodeContext* createYGNodeContext(alias_ref<jobject> thiz) {
|
||||
YGNodeContext* ygNodeContext = new YGNodeContext();
|
||||
ygNodeContext->ygNodeJObjectRef = new weak_ref<jobject>(make_weak(thiz));
|
||||
return ygNodeContext;
|
||||
}
|
||||
|
||||
jlong jni_YGNodeNew(alias_ref<jobject> thiz) {
|
||||
jlong jni_YGNodeNew(alias_ref<jclass>) {
|
||||
const YGNodeRef node = YGNodeNew();
|
||||
node->setContext(createYGNodeContext(thiz));
|
||||
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||
node->setPrintFunc(YGPrint);
|
||||
return reinterpret_cast<jlong>(node);
|
||||
}
|
||||
|
||||
jlong jni_YGNodeNewWithConfig(
|
||||
alias_ref<jobject> thiz,
|
||||
jlong configPointer,
|
||||
jboolean avoidGlobalJNIRefs) {
|
||||
jlong jni_YGNodeNewWithConfig(alias_ref<jclass>, jlong configPointer) {
|
||||
const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer));
|
||||
node->setContext(createYGNodeContext(avoidGlobalJNIRefs ? nullptr : thiz));
|
||||
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||
return reinterpret_cast<jlong>(node);
|
||||
}
|
||||
|
||||
@@ -374,10 +358,6 @@ void jni_YGNodeFree(alias_ref<jclass>, jlong nativePointer) {
|
||||
return;
|
||||
}
|
||||
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
||||
auto context = node->getContext();
|
||||
if (context != nullptr) {
|
||||
delete reinterpret_cast<YGNodeContext*>(node->getContext());
|
||||
}
|
||||
YGNodeFree(node);
|
||||
}
|
||||
|
||||
@@ -394,11 +374,13 @@ void jni_YGNodeReset(jlong nativePointer) {
|
||||
}
|
||||
|
||||
void jni_YGNodePrint(jlong nativePointer) {
|
||||
#ifdef DEBUG
|
||||
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodePrint(
|
||||
node,
|
||||
(YGPrintOptions)(
|
||||
YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
|
||||
#endif
|
||||
}
|
||||
|
||||
void jni_YGNodeInsertChild(
|
||||
@@ -479,14 +461,6 @@ void jni_YGNodeCopyStyle(jlong dstNativePointer, jlong srcNativePointer) {
|
||||
_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
|
||||
}
|
||||
|
||||
struct JYogaValue : public JavaClass<JYogaValue> {
|
||||
constexpr static auto kJavaDescriptor = "Lcom/facebook/yoga/YogaValue;";
|
||||
|
||||
static local_ref<javaobject> create(YGValue value) {
|
||||
return newInstance(value.value, static_cast<int>(value.unit));
|
||||
}
|
||||
};
|
||||
|
||||
#define YG_NODE_JNI_STYLE_PROP(javatype, type, name) \
|
||||
javatype jni_YGNodeStyleGet##name(jlong nativePointer) { \
|
||||
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \
|
||||
@@ -499,7 +473,7 @@ struct JYogaValue : public JavaClass<JYogaValue> {
|
||||
|
||||
#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \
|
||||
local_ref<jobject> jni_YGNodeStyleGet##name( \
|
||||
alias_ref<jobject>, jlong nativePointer) { \
|
||||
alias_ref<jclass>, jlong nativePointer) { \
|
||||
return JYogaValue::create( \
|
||||
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
|
||||
} \
|
||||
@@ -536,7 +510,7 @@ struct JYogaValue : public JavaClass<JYogaValue> {
|
||||
|
||||
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
|
||||
local_ref<jobject> jni_YGNodeStyleGet##name( \
|
||||
alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
||||
alias_ref<jclass>, jlong nativePointer, jint edge) { \
|
||||
return JYogaValue::create(YGNodeStyleGet##name( \
|
||||
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \
|
||||
} \
|
||||
@@ -598,20 +572,20 @@ YG_NODE_JNI_STYLE_UNIT_PROP(MaxHeight);
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
|
||||
|
||||
jlong jni_YGConfigNew(alias_ref<jobject>) {
|
||||
jlong jni_YGConfigNew(alias_ref<jclass>) {
|
||||
return reinterpret_cast<jlong>(YGConfigNew());
|
||||
}
|
||||
|
||||
void jni_YGConfigFree(alias_ref<jobject>, jlong nativePointer) {
|
||||
void jni_YGConfigFree(alias_ref<jclass>, jlong nativePointer) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
// unique_ptr will destruct the underlying global_ref, if present.
|
||||
auto context = std::unique_ptr<global_ref<jobject>>{
|
||||
static_cast<global_ref<jobject>*>(YGConfigGetContext(config))};
|
||||
auto context = std::unique_ptr<global_ref<JYogaLogger>>{
|
||||
static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config))};
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
void jni_YGConfigSetExperimentalFeatureEnabled(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jint feature,
|
||||
jboolean enabled) {
|
||||
@@ -621,7 +595,7 @@ void jni_YGConfigSetExperimentalFeatureEnabled(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jboolean enabled) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -629,7 +603,7 @@ void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetUseWebDefaults(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jboolean useWebDefaults) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -637,7 +611,7 @@ void jni_YGConfigSetUseWebDefaults(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetPrintTreeFlag(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jboolean enable) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -645,7 +619,7 @@ void jni_YGConfigSetPrintTreeFlag(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetPointScaleFactor(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jfloat pixelsInPoint) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -653,7 +627,7 @@ void jni_YGConfigSetPointScaleFactor(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetUseLegacyStretchBehaviour(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jboolean useLegacyStretchBehaviour) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -661,19 +635,20 @@ void jni_YGConfigSetUseLegacyStretchBehaviour(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetLogger(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
alias_ref<jobject> logger) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
auto context =
|
||||
reinterpret_cast<global_ref<jobject>*>(YGConfigGetContext(config));
|
||||
reinterpret_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config));
|
||||
|
||||
if (logger) {
|
||||
if (context == nullptr) {
|
||||
context = new global_ref<jobject>{};
|
||||
context = new global_ref<JYogaLogger>{};
|
||||
YGConfigSetContext(config, context);
|
||||
}
|
||||
*context = make_global(logger);
|
||||
|
||||
*context = make_global(static_ref_cast<JYogaLogger::javaobject>(logger));
|
||||
config->setLogger(YGJNILogFunc);
|
||||
} else {
|
||||
if (context != nullptr) {
|
||||
@@ -689,6 +664,7 @@ static void YGNodeSetStyleInputs(
|
||||
float* styleInputs,
|
||||
int size) {
|
||||
const auto end = styleInputs + size;
|
||||
auto edgesSet = YGNodeEdges{node};
|
||||
while (styleInputs < end) {
|
||||
auto styleInputKey = static_cast<YGStyleInput>((int) *styleInputs++);
|
||||
switch (styleInputKey) {
|
||||
@@ -789,58 +765,55 @@ static void YGNodeSetStyleInputs(
|
||||
YGNodeStyleSetDisplay(node, static_cast<YGDisplay>(*styleInputs++));
|
||||
break;
|
||||
case Margin: {
|
||||
float edge = *styleInputs++;
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float marginValue = *styleInputs++;
|
||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= MARGIN;
|
||||
YGNodeStyleSetMargin(node, static_cast<YGEdge>(edge), marginValue);
|
||||
edgesSet.add(YGNodeEdges::MARGIN);
|
||||
YGNodeStyleSetMargin(node, edge, marginValue);
|
||||
break;
|
||||
}
|
||||
case MarginPercent: {
|
||||
float edge = *styleInputs++;
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float marginPercent = *styleInputs++;
|
||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= MARGIN;
|
||||
YGNodeStyleSetMarginPercent(
|
||||
node, static_cast<YGEdge>(edge), marginPercent);
|
||||
edgesSet.add(YGNodeEdges::MARGIN);
|
||||
YGNodeStyleSetMarginPercent(node, edge, marginPercent);
|
||||
break;
|
||||
}
|
||||
case MarginAuto: {
|
||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= MARGIN;
|
||||
edgesSet.add(YGNodeEdges::MARGIN);
|
||||
YGNodeStyleSetMarginAuto(node, static_cast<YGEdge>(*styleInputs++));
|
||||
break;
|
||||
}
|
||||
case Padding: {
|
||||
float edge = *styleInputs++;
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float paddingValue = *styleInputs++;
|
||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= PADDING;
|
||||
YGNodeStyleSetPadding(node, static_cast<YGEdge>(edge), paddingValue);
|
||||
edgesSet.add(YGNodeEdges::PADDING);
|
||||
YGNodeStyleSetPadding(node, edge, paddingValue);
|
||||
break;
|
||||
}
|
||||
case PaddingPercent: {
|
||||
float edge = *styleInputs++;
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float paddingPercent = *styleInputs++;
|
||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= PADDING;
|
||||
YGNodeStyleSetPaddingPercent(
|
||||
node, static_cast<YGEdge>(edge), paddingPercent);
|
||||
edgesSet.add(YGNodeEdges::PADDING);
|
||||
YGNodeStyleSetPaddingPercent(node, edge, paddingPercent);
|
||||
break;
|
||||
}
|
||||
case Border: {
|
||||
float edge = *styleInputs++;
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float borderValue = *styleInputs++;
|
||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= BORDER;
|
||||
YGNodeStyleSetBorder(node, static_cast<YGEdge>(edge), borderValue);
|
||||
edgesSet.add(YGNodeEdges::BORDER);
|
||||
YGNodeStyleSetBorder(node, edge, borderValue);
|
||||
break;
|
||||
}
|
||||
case Position: {
|
||||
float edge = *styleInputs++;
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float positionValue = *styleInputs++;
|
||||
YGNodeStyleSetPosition(node, static_cast<YGEdge>(edge), positionValue);
|
||||
YGNodeStyleSetPosition(node, edge, positionValue);
|
||||
break;
|
||||
}
|
||||
case PositionPercent: {
|
||||
float edge = *styleInputs++;
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float positionPercent = *styleInputs++;
|
||||
YGNodeStyleSetPositionPercent(
|
||||
node, static_cast<YGEdge>(edge), positionPercent);
|
||||
YGNodeStyleSetPositionPercent(node, edge, positionPercent);
|
||||
break;
|
||||
}
|
||||
case IsReferenceBaseline: {
|
||||
@@ -851,10 +824,11 @@ static void YGNodeSetStyleInputs(
|
||||
break;
|
||||
}
|
||||
}
|
||||
edgesSet.setOn(node);
|
||||
}
|
||||
|
||||
void jni_YGNodeSetStyleInputs(
|
||||
alias_ref<jobject> thiz,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
alias_ref<JArrayFloat> styleInputs,
|
||||
jint size) {
|
||||
@@ -868,12 +842,11 @@ jint jni_YGNodeGetInstanceCount() {
|
||||
}
|
||||
|
||||
local_ref<jobject> jni_YGNodeStyleGetMargin(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jint edge) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
int edgeSetFlag = ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag;
|
||||
if ((edgeSetFlag & MARGIN) != MARGIN) {
|
||||
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::MARGIN)) {
|
||||
return JYogaValue::create(YGValueUndefined);
|
||||
}
|
||||
return JYogaValue::create(
|
||||
@@ -882,7 +855,7 @@ local_ref<jobject> jni_YGNodeStyleGetMargin(
|
||||
|
||||
void jni_YGNodeStyleSetMargin(jlong nativePointer, jint edge, jfloat margin) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag |= MARGIN;
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetMargin(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(margin));
|
||||
}
|
||||
@@ -892,24 +865,23 @@ void jni_YGNodeStyleSetMarginPercent(
|
||||
jint edge,
|
||||
jfloat percent) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag |= MARGIN;
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetMarginPercent(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(percent));
|
||||
}
|
||||
|
||||
void jni_YGNodeStyleSetMarginAuto(jlong nativePointer, jint edge) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag |= MARGIN;
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetMarginAuto(yogaNodeRef, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
local_ref<jobject> jni_YGNodeStyleGetPadding(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jint edge) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
int edgeSetFlag = ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag;
|
||||
if ((edgeSetFlag & PADDING) != PADDING) {
|
||||
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::PADDING)) {
|
||||
return JYogaValue::create(YGValueUndefined);
|
||||
}
|
||||
return JYogaValue::create(
|
||||
@@ -918,7 +890,7 @@ local_ref<jobject> jni_YGNodeStyleGetPadding(
|
||||
|
||||
void jni_YGNodeStyleSetPadding(jlong nativePointer, jint edge, jfloat padding) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag |= PADDING;
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::PADDING).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetPadding(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(padding));
|
||||
}
|
||||
@@ -928,15 +900,14 @@ void jni_YGNodeStyleSetPaddingPercent(
|
||||
jint edge,
|
||||
jfloat percent) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag |= PADDING;
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::PADDING).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetPaddingPercent(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(percent));
|
||||
}
|
||||
|
||||
jfloat jni_YGNodeStyleGetBorder(jlong nativePointer, jint edge) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
int edgeSetFlag = ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag;
|
||||
if ((edgeSetFlag & BORDER) != BORDER) {
|
||||
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::BORDER)) {
|
||||
return (jfloat) YGUndefined;
|
||||
}
|
||||
return (jfloat) YGNodeStyleGetBorder(yogaNodeRef, static_cast<YGEdge>(edge));
|
||||
@@ -944,7 +915,7 @@ jfloat jni_YGNodeStyleGetBorder(jlong nativePointer, jint edge) {
|
||||
|
||||
void jni_YGNodeStyleSetBorder(jlong nativePointer, jint edge, jfloat border) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
ygNodeRefToYGNodeContext(yogaNodeRef)->edgeSetFlag |= BORDER;
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::BORDER).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetBorder(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(border));
|
||||
}
|
||||
@@ -956,7 +927,7 @@ void jni_YGNodeStyleSetBorder(jlong nativePointer, jint edge, jfloat border) {
|
||||
jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
return initialize(vm, [] {
|
||||
registerNatives(
|
||||
"com/facebook/yoga/YogaNodeJNI",
|
||||
"com/facebook/yoga/YogaNative",
|
||||
{
|
||||
YGMakeNativeMethod(jni_YGNodeNew),
|
||||
YGMakeNativeMethod(jni_YGNodeNewWithConfig),
|
||||
@@ -1042,10 +1013,6 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeGetInstanceCount),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodePrint),
|
||||
YGMakeNativeMethod(jni_YGNodeSetStyleInputs),
|
||||
});
|
||||
registerNatives(
|
||||
"com/facebook/yoga/YogaConfig",
|
||||
{
|
||||
YGMakeNativeMethod(jni_YGConfigNew),
|
||||
YGMakeNativeMethod(jni_YGConfigFree),
|
||||
YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled),
|
||||
|
44
java/jni/YGJTypes.cpp
Normal file
44
java/jni/YGJTypes.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
#include "YGJTypes.h"
|
||||
|
||||
using facebook::jni::alias_ref;
|
||||
using facebook::jni::local_ref;
|
||||
|
||||
jfloat JYogaNode::baseline(jfloat width, jfloat height) {
|
||||
static auto javaMethod =
|
||||
javaClassLocal()->getMethod<jfloat(jfloat, jfloat)>("baseline");
|
||||
return javaMethod(self(), width, height);
|
||||
}
|
||||
|
||||
jlong JYogaNode::measure(
|
||||
jfloat width,
|
||||
jint widthMode,
|
||||
jfloat height,
|
||||
jint heightMode) {
|
||||
static auto javaMethod =
|
||||
javaClassLocal()->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
|
||||
return javaMethod(self(), width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
facebook::jni::local_ref<JYogaLogLevel> JYogaLogLevel::fromInt(jint logLevel) {
|
||||
static auto javaMethod =
|
||||
javaClassStatic()->getStaticMethod<alias_ref<JYogaLogLevel>(jint)>(
|
||||
"fromInt");
|
||||
return javaMethod(javaClassStatic(), logLevel);
|
||||
}
|
||||
|
||||
void JYogaLogger::log(
|
||||
facebook::jni::alias_ref<JYogaNode> node,
|
||||
facebook::jni::alias_ref<JYogaLogLevel> logLevel,
|
||||
jstring message) {
|
||||
static auto javaMethod =
|
||||
javaClassLocal()
|
||||
->getMethod<void(
|
||||
alias_ref<JYogaNode>, alias_ref<JYogaLogLevel>, jstring)>("log");
|
||||
javaMethod(self(), node, logLevel, message);
|
||||
}
|
38
java/jni/YGJTypes.h
Normal file
38
java/jni/YGJTypes.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
#include <fb/fbjni.h>
|
||||
#include <yoga/YGValue.h>
|
||||
|
||||
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;";
|
||||
|
||||
jfloat baseline(jfloat width, jfloat height);
|
||||
jlong measure(jfloat width, jint widthMode, jfloat height, jint heightMode);
|
||||
};
|
||||
|
||||
struct JYogaLogLevel : public facebook::jni::JavaClass<JYogaLogLevel> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
||||
|
||||
static facebook::jni::local_ref<JYogaLogLevel> fromInt(jint);
|
||||
};
|
||||
|
||||
struct JYogaLogger : public facebook::jni::JavaClass<JYogaLogger> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogger";
|
||||
|
||||
void log(
|
||||
facebook::jni::alias_ref<JYogaNode>,
|
||||
facebook::jni::alias_ref<JYogaLogLevel>,
|
||||
jstring);
|
||||
};
|
||||
|
||||
struct JYogaValue : public facebook::jni::JavaClass<JYogaValue> {
|
||||
constexpr static auto kJavaDescriptor = "Lcom/facebook/yoga/YogaValue;";
|
||||
|
||||
static facebook::jni::local_ref<javaobject> create(YGValue value) {
|
||||
return newInstance(value.value, static_cast<int>(value.unit));
|
||||
}
|
||||
};
|
@@ -30,9 +30,9 @@ public class YogaNodeTest {
|
||||
|
||||
@Test
|
||||
public void testInit() {
|
||||
final int refCount = YogaNodeJNI.jni_YGNodeGetInstanceCount();
|
||||
final int refCount = YogaNative.jni_YGNodeGetInstanceCount();
|
||||
final YogaNode node = createNode();
|
||||
assertEquals(refCount + 1, YogaNodeJNI.jni_YGNodeGetInstanceCount());
|
||||
assertEquals(refCount + 1, YogaNative.jni_YGNodeGetInstanceCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -253,7 +253,7 @@ public class YogaNodeTest {
|
||||
root_child0_child0_child0.setFlexShrink(1);
|
||||
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
assertFalse(((YogaNodeJNI) root).getDoesLegacyStretchFlagAffectsLayout());
|
||||
assertFalse(((YogaNodeJNIBase) root).getDoesLegacyStretchFlagAffectsLayout());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -32,7 +32,7 @@ yoga_cxx_library(
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Wno-unused-parameter",
|
||||
"-std=c++11",
|
||||
"-std=c++14",
|
||||
],
|
||||
platforms = (ANDROID,),
|
||||
visibility = ["PUBLIC"],
|
||||
|
@@ -5,7 +5,7 @@
|
||||
load("//tools/build_defs/oss:yoga_defs.bzl", "YOGA_ROOTS", "subdir_glob", "yoga_cxx_library")
|
||||
|
||||
COMPILER_FLAGS = [
|
||||
"-std=c++11",
|
||||
"-std=c++14",
|
||||
"-Wno-missing-prototypes",
|
||||
]
|
||||
|
||||
|
@@ -32,6 +32,6 @@
|
||||
"develop": "gatsby develop"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "1.13.7"
|
||||
"prettier": "1.16.4"
|
||||
}
|
||||
}
|
||||
|
@@ -6978,9 +6978,10 @@ preserve@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
|
||||
|
||||
prettier@1.13.7:
|
||||
version "1.13.7"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.7.tgz#850f3b8af784a49a6ea2d2eaa7ed1428a34b7281"
|
||||
prettier@1.16.4:
|
||||
version "1.16.4"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717"
|
||||
integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==
|
||||
|
||||
pretty-bytes@^4.0.2:
|
||||
version "4.0.2"
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#include "YGNodePrint.h"
|
||||
#include <stdarg.h>
|
||||
#include "YGEnums.h"
|
||||
@@ -230,3 +231,4 @@ void YGNodeToString(
|
||||
}
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
||||
#endif
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
@@ -20,3 +21,4 @@ void YGNodeToString(
|
||||
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
||||
#endif
|
||||
|
@@ -979,6 +979,7 @@ bool YGLayoutNodeInternal(
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext);
|
||||
|
||||
#ifdef DEBUG
|
||||
static void YGNodePrintInternal(
|
||||
const YGNodeRef node,
|
||||
const YGPrintOptions options) {
|
||||
@@ -990,6 +991,7 @@ static void YGNodePrintInternal(
|
||||
void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) {
|
||||
YGNodePrintInternal(node, options);
|
||||
}
|
||||
#endif
|
||||
|
||||
const std::array<YGEdge, 4> leading = {
|
||||
{YGEdgeTop, YGEdgeBottom, YGEdgeLeft, YGEdgeRight}};
|
||||
@@ -4091,6 +4093,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth);
|
||||
YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (node->getConfig()->printTree) {
|
||||
YGNodePrint(
|
||||
node,
|
||||
@@ -4098,6 +4101,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||
YGPrintOptionsStyle));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
|
||||
@@ -4147,6 +4151,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
!originalNode->isLayoutTreeEqualToNode(*node);
|
||||
node->setLayoutDoesLegacyFlagAffectsLayout(neededLegacyStretchBehaviour);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (originalNode->getConfig()->printTree) {
|
||||
YGNodePrint(
|
||||
originalNode,
|
||||
@@ -4154,6 +4159,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||
YGPrintOptionsStyle));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
YGConfigFreeRecursive(originalNode);
|
||||
YGNodeFreeRecursive(originalNode);
|
||||
|
Reference in New Issue
Block a user