Compare commits
4 Commits
v1.12.0-pr
...
v1.13.0
Author | SHA1 | Date | |
---|---|---|---|
|
6d271c05f6 | ||
|
a9bddf87ff | ||
|
88994129ae | ||
|
888892885e |
@@ -6,7 +6,7 @@
|
|||||||
#
|
#
|
||||||
Pod::Spec.new do |spec|
|
Pod::Spec.new do |spec|
|
||||||
spec.name = 'Yoga'
|
spec.name = 'Yoga'
|
||||||
spec.version = '1.9.0'
|
spec.version = '1.12.0-pre.1'
|
||||||
spec.license = { :type => 'MIT', :file => "LICENSE" }
|
spec.license = { :type => 'MIT', :file => "LICENSE" }
|
||||||
spec.homepage = 'https://yogalayout.com/'
|
spec.homepage = 'https://yogalayout.com/'
|
||||||
spec.documentation_url = 'https://yogalayout.com/docs'
|
spec.documentation_url = 'https://yogalayout.com/docs'
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
org.gradle.jvmargs=-Xmx1536M
|
org.gradle.jvmargs=-Xmx1536M
|
||||||
|
|
||||||
VERSION_NAME=1.12.0-SNAPSHOT
|
VERSION_NAME=1.13.0
|
||||||
POM_URL=https://github.com/facebook/yoga
|
POM_URL=https://github.com/facebook/yoga
|
||||||
POM_SCM_URL=https://github.com/facebook/yoga.git
|
POM_SCM_URL=https://github.com/facebook/yoga.git
|
||||||
POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git
|
POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git
|
||||||
|
@@ -29,7 +29,7 @@ add_compile_options(
|
|||||||
-Wall
|
-Wall
|
||||||
-std=c++11)
|
-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
|
target_include_directories(yoga PRIVATE
|
||||||
${libfb_DIR}/include
|
${libfb_DIR}/include
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "YGJTypes.h"
|
||||||
|
|
||||||
using namespace facebook::jni;
|
using namespace facebook::jni;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using facebook::yoga::detail::Log;
|
using facebook::yoga::detail::Log;
|
||||||
@@ -58,14 +60,6 @@ enum YGStyleInput {
|
|||||||
IsReferenceBaseline,
|
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 {
|
class PtrJNodeMap {
|
||||||
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
||||||
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
||||||
@@ -250,10 +244,7 @@ static float YGJNIBaselineFunc(
|
|||||||
float height,
|
float height,
|
||||||
void* layoutContext) {
|
void* layoutContext) {
|
||||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||||
static auto baselineFunc =
|
return obj->baseline(width, height);
|
||||||
findClassStatic("com/facebook/yoga/YogaNodeJNI")
|
|
||||||
->getMethod<jfloat(jfloat, jfloat)>("baseline");
|
|
||||||
return baselineFunc(obj, width, height);
|
|
||||||
} else {
|
} else {
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
@@ -275,13 +266,9 @@ static YGSize YGJNIMeasureFunc(
|
|||||||
YGMeasureMode heightMode,
|
YGMeasureMode heightMode,
|
||||||
void* layoutContext) {
|
void* layoutContext) {
|
||||||
if (auto obj = YGNodeJobject(node, 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);
|
YGTransferLayoutDirection(node, obj);
|
||||||
const auto measureResult =
|
const auto measureResult =
|
||||||
measureFunc(obj, width, widthMode, height, heightMode);
|
obj->measure(width, widthMode, height, heightMode);
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
sizeof(measureResult) == 8,
|
sizeof(measureResult) == 8,
|
||||||
@@ -307,10 +294,6 @@ static YGSize YGJNIMeasureFunc(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct JYogaLogLevel : public JavaClass<JYogaLogLevel> {
|
|
||||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
|
||||||
};
|
|
||||||
|
|
||||||
static int YGJNILogFunc(
|
static int YGJNILogFunc(
|
||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
@@ -322,24 +305,14 @@ static int YGJNILogFunc(
|
|||||||
std::vector<char> buffer(1 + result);
|
std::vector<char> buffer(1 + result);
|
||||||
vsnprintf(buffer.data(), buffer.size(), format, args);
|
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 =
|
auto jloggerPtr =
|
||||||
static_cast<global_ref<jobject>*>(YGConfigGetContext(config));
|
static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config));
|
||||||
if (jloggerPtr != nullptr) {
|
if (jloggerPtr != nullptr) {
|
||||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||||
logFunc(
|
(*jloggerPtr)
|
||||||
*jloggerPtr,
|
->log(
|
||||||
obj,
|
obj,
|
||||||
logLevelFromInt(
|
JYogaLogLevel::fromInt(level),
|
||||||
JYogaLogLevel::javaClassStatic(), static_cast<jint>(level)),
|
|
||||||
Environment::current()->NewStringUTF(buffer.data()));
|
Environment::current()->NewStringUTF(buffer.data()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -479,14 +452,6 @@ void jni_YGNodeCopyStyle(jlong dstNativePointer, jlong srcNativePointer) {
|
|||||||
_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(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) \
|
#define YG_NODE_JNI_STYLE_PROP(javatype, type, name) \
|
||||||
javatype jni_YGNodeStyleGet##name(jlong nativePointer) { \
|
javatype jni_YGNodeStyleGet##name(jlong nativePointer) { \
|
||||||
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \
|
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \
|
||||||
@@ -605,8 +570,8 @@ jlong jni_YGConfigNew(alias_ref<jobject>) {
|
|||||||
void jni_YGConfigFree(alias_ref<jobject>, jlong nativePointer) {
|
void jni_YGConfigFree(alias_ref<jobject>, jlong nativePointer) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
// unique_ptr will destruct the underlying global_ref, if present.
|
// unique_ptr will destruct the underlying global_ref, if present.
|
||||||
auto context = std::unique_ptr<global_ref<jobject>>{
|
auto context = std::unique_ptr<global_ref<JYogaLogger>>{
|
||||||
static_cast<global_ref<jobject>*>(YGConfigGetContext(config))};
|
static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config))};
|
||||||
YGConfigFree(config);
|
YGConfigFree(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,14 +631,15 @@ void jni_YGConfigSetLogger(
|
|||||||
alias_ref<jobject> logger) {
|
alias_ref<jobject> logger) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
auto context =
|
auto context =
|
||||||
reinterpret_cast<global_ref<jobject>*>(YGConfigGetContext(config));
|
reinterpret_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config));
|
||||||
|
|
||||||
if (logger) {
|
if (logger) {
|
||||||
if (context == nullptr) {
|
if (context == nullptr) {
|
||||||
context = new global_ref<jobject>{};
|
context = new global_ref<JYogaLogger>{};
|
||||||
YGConfigSetContext(config, context);
|
YGConfigSetContext(config, context);
|
||||||
}
|
}
|
||||||
*context = make_global(logger);
|
|
||||||
|
*context = make_global(static_ref_cast<JYogaLogger::javaobject>(logger));
|
||||||
config->setLogger(YGJNILogFunc);
|
config->setLogger(YGJNILogFunc);
|
||||||
} else {
|
} else {
|
||||||
if (context != nullptr) {
|
if (context != nullptr) {
|
||||||
@@ -789,18 +755,17 @@ static void YGNodeSetStyleInputs(
|
|||||||
YGNodeStyleSetDisplay(node, static_cast<YGDisplay>(*styleInputs++));
|
YGNodeStyleSetDisplay(node, static_cast<YGDisplay>(*styleInputs++));
|
||||||
break;
|
break;
|
||||||
case Margin: {
|
case Margin: {
|
||||||
float edge = *styleInputs++;
|
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||||
float marginValue = *styleInputs++;
|
float marginValue = *styleInputs++;
|
||||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= MARGIN;
|
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= MARGIN;
|
||||||
YGNodeStyleSetMargin(node, static_cast<YGEdge>(edge), marginValue);
|
YGNodeStyleSetMargin(node, edge, marginValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MarginPercent: {
|
case MarginPercent: {
|
||||||
float edge = *styleInputs++;
|
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||||
float marginPercent = *styleInputs++;
|
float marginPercent = *styleInputs++;
|
||||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= MARGIN;
|
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= MARGIN;
|
||||||
YGNodeStyleSetMarginPercent(
|
YGNodeStyleSetMarginPercent(node, edge, marginPercent);
|
||||||
node, static_cast<YGEdge>(edge), marginPercent);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MarginAuto: {
|
case MarginAuto: {
|
||||||
@@ -809,38 +774,36 @@ static void YGNodeSetStyleInputs(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Padding: {
|
case Padding: {
|
||||||
float edge = *styleInputs++;
|
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||||
float paddingValue = *styleInputs++;
|
float paddingValue = *styleInputs++;
|
||||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= PADDING;
|
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= PADDING;
|
||||||
YGNodeStyleSetPadding(node, static_cast<YGEdge>(edge), paddingValue);
|
YGNodeStyleSetPadding(node, edge, paddingValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PaddingPercent: {
|
case PaddingPercent: {
|
||||||
float edge = *styleInputs++;
|
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||||
float paddingPercent = *styleInputs++;
|
float paddingPercent = *styleInputs++;
|
||||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= PADDING;
|
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= PADDING;
|
||||||
YGNodeStyleSetPaddingPercent(
|
YGNodeStyleSetPaddingPercent(node, edge, paddingPercent);
|
||||||
node, static_cast<YGEdge>(edge), paddingPercent);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Border: {
|
case Border: {
|
||||||
float edge = *styleInputs++;
|
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||||
float borderValue = *styleInputs++;
|
float borderValue = *styleInputs++;
|
||||||
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= BORDER;
|
ygNodeRefToYGNodeContext(node)->edgeSetFlag |= BORDER;
|
||||||
YGNodeStyleSetBorder(node, static_cast<YGEdge>(edge), borderValue);
|
YGNodeStyleSetBorder(node, edge, borderValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Position: {
|
case Position: {
|
||||||
float edge = *styleInputs++;
|
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||||
float positionValue = *styleInputs++;
|
float positionValue = *styleInputs++;
|
||||||
YGNodeStyleSetPosition(node, static_cast<YGEdge>(edge), positionValue);
|
YGNodeStyleSetPosition(node, edge, positionValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PositionPercent: {
|
case PositionPercent: {
|
||||||
float edge = *styleInputs++;
|
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||||
float positionPercent = *styleInputs++;
|
float positionPercent = *styleInputs++;
|
||||||
YGNodeStyleSetPositionPercent(
|
YGNodeStyleSetPositionPercent(node, edge, positionPercent);
|
||||||
node, static_cast<YGEdge>(edge), positionPercent);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IsReferenceBaseline: {
|
case IsReferenceBaseline: {
|
||||||
@@ -955,9 +918,7 @@ void jni_YGNodeStyleSetBorder(jlong nativePointer, jint edge, jfloat border) {
|
|||||||
|
|
||||||
jint JNI_OnLoad(JavaVM* vm, void*) {
|
jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||||
return initialize(vm, [] {
|
return initialize(vm, [] {
|
||||||
registerNatives(
|
JYogaNode::javaClassStatic()->registerNatives({
|
||||||
"com/facebook/yoga/YogaNodeJNI",
|
|
||||||
{
|
|
||||||
YGMakeNativeMethod(jni_YGNodeNew),
|
YGMakeNativeMethod(jni_YGNodeNew),
|
||||||
YGMakeNativeMethod(jni_YGNodeNewWithConfig),
|
YGMakeNativeMethod(jni_YGNodeNewWithConfig),
|
||||||
YGMakeNativeMethod(jni_YGNodeFree),
|
YGMakeNativeMethod(jni_YGNodeFree),
|
||||||
|
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);
|
||||||
|
}
|
42
java/jni/YGJTypes.h
Normal file
42
java/jni/YGJTypes.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* 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/YogaNodeJNI;";
|
||||||
|
|
||||||
|
jfloat baseline(jfloat width, jfloat height);
|
||||||
|
jlong measure(jfloat width, jint widthMode, jfloat height, jint heightMode);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JYogaConfig : public facebook::jni::JavaClass<JYogaConfig> {
|
||||||
|
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaConfig;";
|
||||||
|
};
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user