Skip to content

Commit d5dad06

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Don't export private headers from Buck target (#37127)
Summary: X-link: facebook/yoga#1269 Pull Request resolved: #37127 This prevents targets which include Yoga from using its private APIs. Instances of this have been mostly cleaned up in the past diffs, with the major exception of RN Fabric. To stage this without blocking on that, I added a `yoga-private-api` target for now to keep using these headers while making it unlikely new usages will show up. Reviewed By: javache Differential Revision: D45339425 fbshipit-source-id: eb7ef151ad2467d7c3370cd7c10d47e8db9496a0
1 parent 7e6f6aa commit d5dad06

File tree

5 files changed

+28
-44
lines changed

5 files changed

+28
-44
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNative.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class YogaNative {
3838
static native void jni_YGNodeSwapChildJNI(long nativePointer, long childPointer, int index);
3939
static native void jni_YGNodeSetIsReferenceBaselineJNI(long nativePointer, boolean isReferenceBaseline);
4040
static native boolean jni_YGNodeIsReferenceBaselineJNI(long nativePointer);
41-
static native void jni_YGNodeClearChildrenJNI(long nativePointer);
41+
static native void jni_YGNodeRemoveAllChildrenJNI(long nativePointer);
4242
static native void jni_YGNodeRemoveChildJNI(long nativePointer, long childPointer);
4343
static native void jni_YGNodeCalculateLayoutJNI(long nativePointer, float width, float height, long[] nativePointers, YogaNodeJNIBase[] nodes);
4444
static native void jni_YGNodeMarkDirtyJNI(long nativePointer);

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public YogaNodeJNIBase cloneWithoutChildren() {
155155

156156
private void clearChildren() {
157157
mChildren = null;
158-
YogaNative.jni_YGNodeClearChildrenJNI(mNativePointer);
158+
YogaNative.jni_YGNodeRemoveAllChildrenJNI(mNativePointer);
159159
}
160160

161161
public YogaNodeJNIBase removeChildAt(int i) {

packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#include <yoga/Yoga.h>
9+
810
const short int LAYOUT_EDGE_SET_FLAG_INDEX = 0;
911
const short int LAYOUT_WIDTH_INDEX = 1;
1012
const short int LAYOUT_HEIGHT_INDEX = 2;
@@ -36,14 +38,14 @@ class YGNodeEdges {
3638

3739
YGNodeEdges(YGNodeRef node) {
3840
auto context = YGNodeContext{};
39-
context.asVoidPtr = node->getContext();
41+
context.asVoidPtr = YGNodeGetContext(node);
4042
edges_ = context.edgesSet;
4143
}
4244

4345
void setOn(YGNodeRef node) {
4446
auto context = YGNodeContext{};
4547
context.edgesSet = edges_;
46-
node->setContext(context.asVoidPtr);
48+
YGNodeSetContext(node, context.asVoidPtr);
4749
}
4850

4951
bool has(Edge edge) { return (edges_ & edge) == edge; }

packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
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+
2022
using namespace facebook::yoga::vanillajni;
21-
using facebook::yoga::detail::Log;
2223

2324
static 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-
9988
static void jni_YGConfigSetUseLegacyStretchBehaviourJNI(
10089
JNIEnv* env,
10190
jobject obj,
@@ -127,8 +116,7 @@ static jint jni_YGConfigGetErrataJNI(
127116

128117
static 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

222210
static 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

229217
static 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

273261
static 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

426409
static 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) {
737715
static 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",

packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJTypesVanilla.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#include "jni.h"
9-
#include <yoga/YGValue.h>
10-
#include <yoga/Yoga.h>
118
#include <map>
9+
#include <vector>
10+
11+
#include <yoga/Yoga.h>
12+
1213
#include "common.h"
14+
#include "jni.h"
1315

1416
class PtrJNodeMapVanilla {
1517
std::map<YGNodeRef, size_t> ptrsToIdxs_;

0 commit comments

Comments
 (0)