Skip to content

Commit 2ea0472

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Don't export private headers from Buck target (microsoft#1269)
Summary: X-link: facebook/yoga#1269 Pull Request resolved: facebook#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: 973984f8e9963a17cf9fefa5b024669ba9c6e9f7
1 parent 243a148 commit 2ea0472

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,
@@ -124,8 +113,7 @@ static jint jni_YGConfigGetErrataJNI(
124113

125114
static jlong jni_YGNodeNewJNI(JNIEnv* env, jobject obj) {
126115
const YGNodeRef node = YGNodeNew();
127-
node->setContext(YGNodeContext{}.asVoidPtr);
128-
node->setPrintFunc(YGPrint);
116+
YGNodeSetContext(node, YGNodeContext{}.asVoidPtr);
129117
return reinterpret_cast<jlong>(node);
130118
}
131119

@@ -134,7 +122,7 @@ static jlong jni_YGNodeNewWithConfigJNI(
134122
jobject obj,
135123
jlong configPointer) {
136124
const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer));
137-
node->setContext(YGNodeContext{}.asVoidPtr);
125+
YGNodeSetContext(node, YGNodeContext{}.asVoidPtr);
138126
return reinterpret_cast<jlong>(node);
139127
}
140128

@@ -218,9 +206,9 @@ static void jni_YGNodeFreeJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
218206

219207
static void jni_YGNodeResetJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
220208
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
221-
void* context = node->getContext();
209+
void* context = YGNodeGetContext(node);
222210
YGNodeReset(node);
223-
node->setContext(context);
211+
YGNodeSetContext(node, context);
224212
}
225213

226214
static void jni_YGNodeInsertChildJNI(
@@ -259,12 +247,12 @@ static jboolean jni_YGNodeIsReferenceBaselineJNI(
259247
return YGNodeIsReferenceBaseline(_jlong2YGNodeRef(nativePointer));
260248
}
261249

262-
static void jni_YGNodeClearChildrenJNI(
250+
static void jni_YGNodeRemoveAllChildrenJNI(
263251
JNIEnv* env,
264252
jobject obj,
265253
jlong nativePointer) {
266254
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
267-
node->clearChildren();
255+
YGNodeRemoveAllChildren(node);
268256
}
269257

270258
static void jni_YGNodeRemoveChildJNI(
@@ -281,16 +269,11 @@ static void YGTransferLayoutOutputsRecursive(
281269
jobject thiz,
282270
YGNodeRef root,
283271
void* layoutContext) {
284-
if (!root->getHasNewLayout()) {
272+
if (!YGNodeGetHasNewLayout(root)) {
285273
return;
286274
}
287275
auto obj = YGNodeJobject(root, layoutContext);
288276
if (!obj) {
289-
Log::log(
290-
root,
291-
YGLogLevelError,
292-
nullptr,
293-
"Java YGNode was GCed during layout calculation\n");
294277
return;
295278
}
296279

@@ -351,7 +334,7 @@ static void YGTransferLayoutOutputsRecursive(
351334
env->SetFloatArrayRegion(arrFinal.get(), 0, arrSize, arr);
352335
env->SetObjectField(obj.get(), arrField, arrFinal.get());
353336

354-
root->setHasNewLayout(false);
337+
YGNodeSetHasNewLayout(root, false);
355338

356339
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
357340
YGTransferLayoutOutputsRecursive(
@@ -417,7 +400,7 @@ static jboolean jni_YGNodeIsDirtyJNI(
417400
JNIEnv* env,
418401
jobject obj,
419402
jlong nativePointer) {
420-
return (jboolean) _jlong2YGNodeRef(nativePointer)->isDirty();
403+
return (jboolean) YGNodeIsDirty(_jlong2YGNodeRef(nativePointer));
421404
}
422405

423406
static void jni_YGNodeCopyStyleJNI(
@@ -674,11 +657,6 @@ static YGSize YGJNIMeasureFunc(
674657

675658
return YGSize{*measuredWidth, *measuredHeight};
676659
} else {
677-
Log::log(
678-
node,
679-
YGLogLevelError,
680-
nullptr,
681-
"Java YGNode was GCed during layout calculation\n");
682660
return YGSize{
683661
widthMode == YGMeasureModeUndefined ? 0 : width,
684662
heightMode == YGMeasureModeUndefined ? 0 : height,
@@ -734,7 +712,7 @@ static void jni_YGNodePrintJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
734712
static jlong jni_YGNodeCloneJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
735713
auto node = _jlong2YGNodeRef(nativePointer);
736714
const YGNodeRef clonedYogaNode = YGNodeClone(node);
737-
clonedYogaNode->setContext(node->getContext());
715+
YGNodeSetContext(clonedYogaNode, YGNodeGetContext(node));
738716

739717
return reinterpret_cast<jlong>(clonedYogaNode);
740718
}
@@ -798,7 +776,9 @@ static JNINativeMethod methods[] = {
798776
{"jni_YGNodeIsReferenceBaselineJNI",
799777
"(J)Z",
800778
(void*) jni_YGNodeIsReferenceBaselineJNI},
801-
{"jni_YGNodeClearChildrenJNI", "(J)V", (void*) jni_YGNodeClearChildrenJNI},
779+
{"jni_YGNodeRemoveAllChildrenJNI",
780+
"(J)V",
781+
(void*) jni_YGNodeRemoveAllChildrenJNI},
802782
{"jni_YGNodeRemoveChildJNI", "(JJ)V", (void*) jni_YGNodeRemoveChildJNI},
803783
{"jni_YGNodeCalculateLayoutJNI",
804784
"(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)