move yg node new and ygnode new with config
Summary: YGNode creation methods to vanilla JNI Reviewed By: amir-shalem Differential Revision: D17714230 fbshipit-source-id: 74e14e876ab7efc67771d92091c2a78f09072b83
This commit is contained in:
committed by
Facebook Github Bot
parent
34739ec652
commit
22a60e82b0
@@ -12,6 +12,7 @@
|
||||
#include "common.h"
|
||||
#include "YGJTypesVanilla.h"
|
||||
#include <yoga/log.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace facebook::yoga::vanillajni;
|
||||
using facebook::yoga::detail::Log;
|
||||
@@ -90,6 +91,18 @@ static void jni_YGConfigSetPointScaleFactorJNI(
|
||||
YGConfigSetPointScaleFactor(config, pixelsInPoint);
|
||||
}
|
||||
|
||||
static void YGPrint(YGNodeRef node, void* layoutContext) {
|
||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||
// TODO cout << obj.get()->toString() << endl;
|
||||
} else {
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelError,
|
||||
nullptr,
|
||||
"Java YGNode was GCed during layout calculation\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void jni_YGConfigSetUseLegacyStretchBehaviourJNI(
|
||||
JNIEnv* env,
|
||||
jobject obj,
|
||||
@@ -99,6 +112,22 @@ static void jni_YGConfigSetUseLegacyStretchBehaviourJNI(
|
||||
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
|
||||
}
|
||||
|
||||
static jlong jni_YGNodeNewJNI(JNIEnv* env, jobject obj) {
|
||||
const YGNodeRef node = YGNodeNew();
|
||||
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||
node->setPrintFunc(YGPrint);
|
||||
return reinterpret_cast<jlong>(node);
|
||||
}
|
||||
|
||||
static jlong jni_YGNodeNewWithConfigJNI(
|
||||
JNIEnv* env,
|
||||
jobject obj,
|
||||
jlong configPointer) {
|
||||
const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer));
|
||||
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||
return reinterpret_cast<jlong>(node);
|
||||
}
|
||||
|
||||
static void jni_YGNodeFreeJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
|
||||
if (nativePointer == 0) {
|
||||
return;
|
||||
@@ -558,6 +587,8 @@ static JNINativeMethod methods[] = {
|
||||
"(JZ)V",
|
||||
(void*) jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI},
|
||||
// {"jni_YGConfigSetLoggerJNI", "(JO)V", (void*) jni_YGConfigSetLoggerJNI},
|
||||
{"jni_YGNodeNewJNI", "()J", (void*) jni_YGNodeNewJNI},
|
||||
{"jni_YGNodeNewWithConfigJNI", "(J)J", (void*) jni_YGNodeNewWithConfigJNI},
|
||||
{"jni_YGNodeFreeJNI", "(J)V", (void*) jni_YGNodeFreeJNI},
|
||||
{"jni_YGNodeResetJNI", "(J)V", (void*) jni_YGNodeResetJNI},
|
||||
{"jni_YGNodeInsertChildJNI", "(JJI)V", (void*) jni_YGNodeInsertChildJNI},
|
||||
|
Reference in New Issue
Block a user