Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java bindings for setAlwaysFormsContainingBlock #1540

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions java/com/facebook/yoga/YogaNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ public class YogaNative {
static native void jni_YGNodePrintJNI(long nativePointer);
static native void jni_YGNodeSetStyleInputsJNI(long nativePointer, float[] styleInputsArray, int size);
static native long jni_YGNodeCloneJNI(long nativePointer);
static native void jni_YGNodeSetAlwaysFormsContainingBlockJNI(long nativePointer, boolean alwaysFormContainingBlock);
}
2 changes: 2 additions & 0 deletions java/com/facebook/yoga/YogaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,6 @@ public interface Inputs {
public abstract YogaNode cloneWithoutChildren();

public abstract YogaNode cloneWithChildren();

public abstract void setAlwaysFormsContainingBlock(boolean alwaysFormsContainingBlock);
}
5 changes: 5 additions & 0 deletions java/com/facebook/yoga/YogaNodeJNIBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ public void setMeasureFunction(YogaMeasureFunction measureFunction) {
YogaNative.jni_YGNodeSetHasMeasureFuncJNI(mNativePointer, measureFunction != null);
}

@Override
public void setAlwaysFormsContainingBlock(boolean alwaysFormsContainingBlock) {
YogaNative.jni_YGNodeSetAlwaysFormsContainingBlockJNI(mNativePointer, alwaysFormsContainingBlock);
}

// Implementation Note: Why this method needs to stay final
//
// We cache the jmethodid for this method in Yoga code. This means that even if a subclass
Expand Down
12 changes: 12 additions & 0 deletions java/jni/YGJNIVanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,15 @@ static void jni_YGNodeSetHasBaselineFuncJNI(
hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
}

static void jni_YGNodeSetAlwaysFormsContainingBlockJNI(
JNIEnv* /*env*/,
jobject /*obj*/,
jlong nativePointer,
jboolean alwaysFormsContainingBlock) {
YGNodeSetAlwaysFormsContainingBlock(
_jlong2YGNodeRef(nativePointer), alwaysFormsContainingBlock);
}

static void
jni_YGNodePrintJNI(JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) {
#ifdef DEBUG
Expand Down Expand Up @@ -958,6 +967,9 @@ static JNINativeMethod methods[] = {
{"jni_YGNodeSetHasBaselineFuncJNI",
"(JZ)V",
(void*)jni_YGNodeSetHasBaselineFuncJNI},
{"jni_YGNodeSetAlwaysFormsContainingBlockJNI",
"(JZ)V",
(void*)jni_YGNodeSetAlwaysFormsContainingBlockJNI},
{"jni_YGNodePrintJNI", "(J)V", (void*)jni_YGNodePrintJNI},
{"jni_YGNodeCloneJNI", "(J)J", (void*)jni_YGNodeCloneJNI},
};
Expand Down
6 changes: 6 additions & 0 deletions yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) {
resolveRef(node)->setPrintFunc(printFunc);
}

void YGNodeSetAlwaysFormsContainingBlock(
YGNodeRef node,
bool alwaysFormsContainingBlock) {
resolveRef(node)->setAlwaysFormsContainingBlock(alwaysFormsContainingBlock);
}

#ifdef DEBUG
void YGNodePrint(const YGNodeConstRef node, const YGPrintOptions options) {
yoga::print(resolveRef(node), scopedEnum(options));
Expand Down
11 changes: 11 additions & 0 deletions yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ typedef void (*YGPrintFunc)(YGNodeConstRef node);
*/
YG_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);

/**
* Make it so that this node will always form a containing block for any
* descendant nodes. This is useful for when a node has a property outside of
* of Yoga that will form a containing block. For example, transforms or some of
* the others listed in
* https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block
*/
YG_EXPORT void YGNodeSetAlwaysFormsContainingBlock(
YGNodeRef node,
bool alwaysFormsContainingBlock);

/**
* Print a node to log output.
*/
Expand Down
4 changes: 3 additions & 1 deletion yoga/algorithm/AbsoluteLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ void layoutAbsoluteDescendants(
if (needsTrailingPosition(crossAxis)) {
setChildTrailingPosition(currentNode, child, crossAxis);
}
} else if (child->getStyle().positionType() == PositionType::Static) {
} else if (
child->getStyle().positionType() == PositionType::Static &&
!child->alwaysFormsContainingBlock()) {
const Direction childDirection =
child->resolveDirection(currentNodeDirection);
const float childMainOffsetFromContainingBlock =
Expand Down
2 changes: 1 addition & 1 deletion yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ static void calculateLayoutImpl(
// Let the containing block layout its absolute descendants. By definition
// the containing block will not be static unless we are at the root.
if (node->getStyle().positionType() != PositionType::Static ||
depth == 1) {
node->alwaysFormsContainingBlock() || depth == 1) {
layoutAbsoluteDescendants(
node,
node,
Expand Down
9 changes: 9 additions & 0 deletions yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class YG_EXPORT Node : public ::YGNode {
return context_;
}

bool alwaysFormsContainingBlock() const {
return alwaysFormsContainingBlock_;
}

void print();

bool getHasNewLayout() const {
Expand Down Expand Up @@ -242,6 +246,10 @@ class YG_EXPORT Node : public ::YGNode {
context_ = context;
}

void setAlwaysFormsContainingBlock(bool alwaysFormsContainingBlock) {
alwaysFormsContainingBlock_ = alwaysFormsContainingBlock;
}

void setPrintFunc(YGPrintFunc printFunc) {
printFunc_ = printFunc;
}
Expand Down Expand Up @@ -369,6 +377,7 @@ class YG_EXPORT Node : public ::YGNode {
bool hasNewLayout_ : 1 = true;
bool isReferenceBaseline_ : 1 = false;
bool isDirty_ : 1 = false;
bool alwaysFormsContainingBlock_ : 1 = false;
NodeType nodeType_ : bitCount<NodeType>() = NodeType::Default;
void* context_ = nullptr;
YGMeasureFunc measureFunc_ = {nullptr};
Expand Down
Loading