77
88#include " jni.h"
99#include " YGJNIVanilla.h"
10- #include < yoga/YGNode.h>
1110#include < cstring>
1211#include " YGJNI.h"
1312#include " common.h"
1413#include " YGJTypesVanilla.h"
15- #include < yoga/log.h>
1614#include < iostream>
1715#include < memory>
1816#include " YogaJniException.h"
1917
18+ // TODO: Reconcile missing layoutContext functionality from callbacks in the C
19+ // API and use that
20+ #include < yoga/YGNode.h>
21+
2022using namespace facebook ::yoga::vanillajni;
21- using facebook::yoga::detail::Log;
2223
2324static inline ScopedLocalRef<jobject> YGNodeJobject (
2425 YGNodeRef node,
@@ -84,18 +85,6 @@ static void jni_YGConfigSetPointScaleFactorJNI(
8485 YGConfigSetPointScaleFactor (config, pixelsInPoint);
8586}
8687
87- static void YGPrint (YGNodeRef node, void * layoutContext) {
88- if (auto obj = YGNodeJobject (node, layoutContext)) {
89- // TODO cout << obj.get()->toString() << endl;
90- } else {
91- Log::log (
92- node,
93- YGLogLevelError,
94- nullptr ,
95- " Java YGNode was GCed during layout calculation\n " );
96- }
97- }
98-
9988static void jni_YGConfigSetUseLegacyStretchBehaviourJNI (
10089 JNIEnv* env,
10190 jobject obj,
@@ -127,8 +116,7 @@ static jint jni_YGConfigGetErrataJNI(
127116
128117static jlong jni_YGNodeNewJNI (JNIEnv* env, jobject obj) {
129118 const YGNodeRef node = YGNodeNew ();
130- node->setContext (YGNodeContext{}.asVoidPtr );
131- node->setPrintFunc (YGPrint);
119+ YGNodeSetContext (node, YGNodeContext{}.asVoidPtr );
132120 return reinterpret_cast <jlong>(node);
133121}
134122
@@ -137,7 +125,7 @@ static jlong jni_YGNodeNewWithConfigJNI(
137125 jobject obj,
138126 jlong configPointer) {
139127 const YGNodeRef node = YGNodeNewWithConfig (_jlong2YGConfigRef (configPointer));
140- node-> setContext ( YGNodeContext{}.asVoidPtr );
128+ YGNodeSetContext (node, YGNodeContext{}.asVoidPtr );
141129 return reinterpret_cast <jlong>(node);
142130}
143131
@@ -221,9 +209,9 @@ static void jni_YGNodeFreeJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
221209
222210static void jni_YGNodeResetJNI (JNIEnv* env, jobject obj, jlong nativePointer) {
223211 const YGNodeRef node = _jlong2YGNodeRef (nativePointer);
224- void * context = node-> getContext ( );
212+ void * context = YGNodeGetContext (node );
225213 YGNodeReset (node);
226- node-> setContext ( context);
214+ YGNodeSetContext (node, context);
227215}
228216
229217static void jni_YGNodeInsertChildJNI (
@@ -262,12 +250,12 @@ static jboolean jni_YGNodeIsReferenceBaselineJNI(
262250 return YGNodeIsReferenceBaseline (_jlong2YGNodeRef (nativePointer));
263251}
264252
265- static void jni_YGNodeClearChildrenJNI (
253+ static void jni_YGNodeRemoveAllChildrenJNI (
266254 JNIEnv* env,
267255 jobject obj,
268256 jlong nativePointer) {
269257 const YGNodeRef node = _jlong2YGNodeRef (nativePointer);
270- node-> clearChildren ( );
258+ YGNodeRemoveAllChildren (node );
271259}
272260
273261static void jni_YGNodeRemoveChildJNI (
@@ -284,16 +272,11 @@ static void YGTransferLayoutOutputsRecursive(
284272 jobject thiz,
285273 YGNodeRef root,
286274 void * layoutContext) {
287- if (!root-> getHasNewLayout ( )) {
275+ if (!YGNodeGetHasNewLayout (root )) {
288276 return ;
289277 }
290278 auto obj = YGNodeJobject (root, layoutContext);
291279 if (!obj) {
292- Log::log (
293- root,
294- YGLogLevelError,
295- nullptr ,
296- " Java YGNode was GCed during layout calculation\n " );
297280 return ;
298281 }
299282
@@ -354,7 +337,7 @@ static void YGTransferLayoutOutputsRecursive(
354337 env->SetFloatArrayRegion (arrFinal.get (), 0 , arrSize, arr);
355338 env->SetObjectField (obj.get (), arrField, arrFinal.get ());
356339
357- root-> setHasNewLayout ( false );
340+ YGNodeSetHasNewLayout (root, false );
358341
359342 for (uint32_t i = 0 ; i < YGNodeGetChildCount (root); i++) {
360343 YGTransferLayoutOutputsRecursive (
@@ -420,7 +403,7 @@ static jboolean jni_YGNodeIsDirtyJNI(
420403 JNIEnv* env,
421404 jobject obj,
422405 jlong nativePointer) {
423- return (jboolean) _jlong2YGNodeRef (nativePointer)-> isDirty ( );
406+ return (jboolean) YGNodeIsDirty ( _jlong2YGNodeRef (nativePointer));
424407}
425408
426409static void jni_YGNodeCopyStyleJNI (
@@ -677,11 +660,6 @@ static YGSize YGJNIMeasureFunc(
677660
678661 return YGSize{*measuredWidth, *measuredHeight};
679662 } else {
680- Log::log (
681- node,
682- YGLogLevelError,
683- nullptr ,
684- " Java YGNode was GCed during layout calculation\n " );
685663 return YGSize{
686664 widthMode == YGMeasureModeUndefined ? 0 : width,
687665 heightMode == YGMeasureModeUndefined ? 0 : height,
@@ -737,7 +715,7 @@ static void jni_YGNodePrintJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
737715static jlong jni_YGNodeCloneJNI (JNIEnv* env, jobject obj, jlong nativePointer) {
738716 auto node = _jlong2YGNodeRef (nativePointer);
739717 const YGNodeRef clonedYogaNode = YGNodeClone (node);
740- clonedYogaNode-> setContext (node-> getContext ( ));
718+ YGNodeSetContext ( clonedYogaNode, YGNodeGetContext (node));
741719
742720 return reinterpret_cast <jlong>(clonedYogaNode);
743721}
@@ -801,7 +779,9 @@ static JNINativeMethod methods[] = {
801779 {" jni_YGNodeIsReferenceBaselineJNI" ,
802780 " (J)Z" ,
803781 (void *) jni_YGNodeIsReferenceBaselineJNI},
804- {" jni_YGNodeClearChildrenJNI" , " (J)V" , (void *) jni_YGNodeClearChildrenJNI},
782+ {" jni_YGNodeRemoveAllChildrenJNI" ,
783+ " (J)V" ,
784+ (void *) jni_YGNodeRemoveAllChildrenJNI},
805785 {" jni_YGNodeRemoveChildJNI" , " (JJ)V" , (void *) jni_YGNodeRemoveChildJNI},
806786 {" jni_YGNodeCalculateLayoutJNI" ,
807787 " (JFF[J[Lcom/facebook/yoga/YogaNodeJNIBase;)V" ,
0 commit comments