Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ internal class ReactProgressBarViewManager :

override fun measure(
context: Context,
localData: ReadableMap,
props: ReadableMap,
state: ReadableMap,
localData: ReadableMap?,
props: ReadableMap?,
state: ReadableMap?,
width: Float,
widthMode: YogaMeasureMode,
height: Float,
heightMode: YogaMeasureMode,
attachmentsPositions: FloatArray?,
): Long {
val style = getStyleFromString(props.getString(PROP_STYLE))
val style = getStyleFromString(props?.getString(PROP_STYLE))
val value =
measuredStyles.getOrPut(style) {
val progressBar = createProgressBar(context, style)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public abstract class YogaConfig {

public abstract fun setErrata(errata: YogaErrata)

/**
* Sets the errata bitmask directly from an [Int]. Use this when combining multiple [YogaErrata]
* values (e.g., `YogaErrata.CLASSIC.intValue() and
* YogaErrata.STRETCH_FLEX_BASIS.intValue().inv()`) — the [YogaErrata] enum cannot represent
* arbitrary bitmask combinations.
*/
public abstract fun setErrata(errata: Int)

public abstract fun getErrata(): YogaErrata

public abstract fun setLogger(logger: YogaLogger?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ private constructor(@JvmField protected var nativePointer: Long) : YogaConfig()
YogaNative.jni_YGConfigSetErrataJNI(nativePointer, errata.intValue())
}

public override fun setErrata(errata: Int) {
YogaNative.jni_YGConfigSetErrataJNI(nativePointer, errata)
}

public override fun getErrata(): YogaErrata =
YogaErrata.fromInt(YogaNative.jni_YGConfigGetErrataJNI(nativePointer))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum class YogaErrata(public val intValue: Int) {
STRETCH_FLEX_BASIS(1),
ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING(2),
ABSOLUTE_PERCENT_AGAINST_INNER_SIZE(4),
MIN_SIZE_UNDEFINED_INSTEAD_OF_AUTO(8),
ALL(2147483647),
CLASSIC(2147483646);

Expand All @@ -27,6 +28,7 @@ public enum class YogaErrata(public val intValue: Int) {
1 -> STRETCH_FLEX_BASIS
2 -> ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING
4 -> ABSOLUTE_PERCENT_AGAINST_INNER_SIZE
8 -> MIN_SIZE_UNDEFINED_INSTEAD_OF_AUTO
2147483647 -> ALL
2147483646 -> CLASSIC
else -> throw IllegalArgumentException("Unknown enum value: $value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,22 @@ public object YogaNative {
@JvmStatic
public external fun jni_YGNodeSetHasMeasureFuncJNI(nativePointer: Long, hasMeasureFunc: Boolean)

@JvmStatic
public external fun jni_YGNodeSetHasMinContentMeasureFuncJNI(
nativePointer: Long,
hasMinContentMeasureFunc: Boolean,
)

@JvmStatic
public external fun jni_YGNodeSetMinContentWidthJNI(nativePointer: Long, minContentWidth: Float)

@JvmStatic
public external fun jni_YGNodeSetMinContentHeightJNI(nativePointer: Long, minContentHeight: Float)

@JvmStatic public external fun jni_YGNodeGetMinContentWidthJNI(nativePointer: Long): Float

@JvmStatic public external fun jni_YGNodeGetMinContentHeightJNI(nativePointer: Long): Float

@JvmStatic
public external fun jni_YGNodeSetHasBaselineFuncJNI(nativePointer: Long, hasMeasureFunc: Boolean)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ public abstract class YogaNode : YogaProps {

abstract override fun setMeasureFunction(measureFunction: YogaMeasureFunction?)

abstract override fun setMinContentMeasureFunction(measureFunction: YogaMeasureFunction?)

abstract override fun setMinContentWidth(minContentWidth: Float)

abstract override fun setMinContentHeight(minContentHeight: Float)

abstract override fun getMinContentWidth(): Float

abstract override fun getMinContentHeight(): Float

abstract override fun setBaselineFunction(yogaBaselineFunction: YogaBaselineFunction?)

public abstract val isMeasureDefined: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public abstract class YogaNodeJNIBase : YogaNode, Cloneable {
private var config: YogaConfig? = null
private var children: MutableList<YogaNodeJNIBase>? = null
private var measureFunction: YogaMeasureFunction? = null
private var minContentMeasureFunction: YogaMeasureFunction? = null
private var baselineFunction: YogaBaselineFunction? = null
protected var nativePointer: Long = 0

Expand Down Expand Up @@ -46,6 +47,7 @@ public abstract class YogaNodeJNIBase : YogaNode, Cloneable {

override fun reset() {
measureFunction = null
minContentMeasureFunction = null
baselineFunction = null
data = null
arr = null
Expand Down Expand Up @@ -524,6 +526,25 @@ public abstract class YogaNodeJNIBase : YogaNode, Cloneable {
YogaNative.jni_YGNodeSetHasMeasureFuncJNI(nativePointer, measureFunction != null)
}

override fun setMinContentMeasureFunction(measureFunction: YogaMeasureFunction?) {
this.minContentMeasureFunction = measureFunction
YogaNative.jni_YGNodeSetHasMinContentMeasureFuncJNI(nativePointer, measureFunction != null)
}

override fun setMinContentWidth(minContentWidth: Float) {
YogaNative.jni_YGNodeSetMinContentWidthJNI(nativePointer, minContentWidth)
}

override fun setMinContentHeight(minContentHeight: Float) {
YogaNative.jni_YGNodeSetMinContentHeightJNI(nativePointer, minContentHeight)
}

override fun getMinContentWidth(): Float =
YogaNative.jni_YGNodeGetMinContentWidthJNI(nativePointer)

override fun getMinContentHeight(): Float =
YogaNative.jni_YGNodeGetMinContentHeightJNI(nativePointer)

override fun setAlwaysFormsContainingBlock(alwaysFormsContainingBlock: Boolean) {
YogaNative.jni_YGNodeSetAlwaysFormsContainingBlockJNI(
nativePointer,
Expand All @@ -547,6 +568,27 @@ public abstract class YogaNodeJNIBase : YogaNode, Cloneable {
)
}

// Native callback invoked by Yoga during the CSS Flexbox §4.5 auto-min
// probe when a min-content measure function is registered. Mirrors
// [measure]; see that method's note on non-overridability.
@DoNotStrip
public fun measureMinContent(
width: Float,
widthMode: Int,
height: Float,
heightMode: Int,
): Long {
val mf =
checkNotNull(minContentMeasureFunction) { "Min-content measure function isn't defined!" }
return mf.measure(
this,
width,
YogaMeasureMode.fromInt(widthMode),
height,
YogaMeasureMode.fromInt(heightMode),
)
}

override fun setBaselineFunction(yogaBaselineFunction: YogaBaselineFunction?) {
baselineFunction = yogaBaselineFunction
YogaNative.jni_YGNodeSetHasBaselineFuncJNI(nativePointer, yogaBaselineFunction != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@ public interface YogaProps {

public fun setMeasureFunction(measureFunction: YogaMeasureFunction?)

public fun setMinContentMeasureFunction(measureFunction: YogaMeasureFunction?)

/**
* Sets the static min-content width used by the CSS Flexbox §4.5 automatic minimum sizing probe.
* Pass `YogaConstants.UNDEFINED` to clear. See `YGNodeSetMinContentWidth` in the Yoga C API for
* full precedence rules.
*/
public fun setMinContentWidth(minContentWidth: Float)

/**
* Sets the static min-content height used by the CSS Flexbox §4.5 automatic minimum sizing probe.
* Pass `YogaConstants.UNDEFINED` to clear. See `YGNodeSetMinContentHeight` in the Yoga C API for
* full precedence rules.
*/
public fun setMinContentHeight(minContentHeight: Float)

/** Returns the static min-content width, or `YogaConstants.UNDEFINED` if not set. */
public fun getMinContentWidth(): Float

/** Returns the static min-content height, or `YogaConstants.UNDEFINED` if not set. */
public fun getMinContentHeight(): Float

public fun setBaselineFunction(yogaBaselineFunction: YogaBaselineFunction?)

/* Mutable properties - getter and setter with matching types */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,83 @@ static void jni_YGNodeSetHasMeasureFuncJNI(
static_cast<bool>(hasMeasureFunc) ? YGJNIMeasureFunc : nullptr);
}

static YGSize YGJNIMinContentMeasureFunc(
YGNodeConstRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
if (auto obj = YGNodeJobject(node)) {
YGTransferLayoutDirection(node, obj.get());
JNIEnv* env = getCurrentEnv();
auto objectClass = facebook::yoga::vanillajni::make_local_ref(
env, env->GetObjectClass(obj.get()));
// NOLINTNEXTLINE(misc-misplaced-const)
static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId(
env, objectClass.get(), "measureMinContent", "(FIFI)J");
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
const auto measureResult = facebook::yoga::vanillajni::callLongMethod(
env, obj.get(), methodId, width, widthMode, height, heightMode);

uint32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
uint32_t hBits = 0xFFFFFFFF & measureResult;
auto measuredWidth = std::bit_cast<float>(wBits);
auto measuredHeight = std::bit_cast<float>(hBits);

return YGSize{measuredWidth, measuredHeight};
} else {
return YGSize{
widthMode == YGMeasureModeUndefined ? 0 : width,
heightMode == YGMeasureModeUndefined ? 0 : height,
};
}
}

static void jni_YGNodeSetHasMinContentMeasureFuncJNI(
JNIEnv* /*env*/,
jobject /*obj*/,
jlong nativePointer,
jboolean hasMinContentMeasureFunc) {
YGNodeSetMinContentMeasureFunc(
_jlong2YGNodeRef(nativePointer),
static_cast<bool>(hasMinContentMeasureFunc) ? YGJNIMinContentMeasureFunc
: nullptr);
}

static void jni_YGNodeSetMinContentWidthJNI(
JNIEnv* /*env*/,
jobject /*obj*/,
jlong nativePointer,
jfloat minContentWidth) {
YGNodeSetMinContentWidth(
_jlong2YGNodeRef(nativePointer), static_cast<float>(minContentWidth));
}

static void jni_YGNodeSetMinContentHeightJNI(
JNIEnv* /*env*/,
jobject /*obj*/,
jlong nativePointer,
jfloat minContentHeight) {
YGNodeSetMinContentHeight(
_jlong2YGNodeRef(nativePointer), static_cast<float>(minContentHeight));
}

static jfloat jni_YGNodeGetMinContentWidthJNI(
JNIEnv* /*env*/,
jobject /*obj*/,
jlong nativePointer) {
return static_cast<jfloat>(
YGNodeGetMinContentWidth(_jlong2YGNodeRef(nativePointer)));
}

static jfloat jni_YGNodeGetMinContentHeightJNI(
JNIEnv* /*env*/,
jobject /*obj*/,
jlong nativePointer) {
return static_cast<jfloat>(
YGNodeGetMinContentHeight(_jlong2YGNodeRef(nativePointer)));
}

static float YGJNIBaselineFunc(YGNodeConstRef node, float width, float height) {
if (auto obj = YGNodeJobject(node)) {
JNIEnv* env = getCurrentEnv();
Expand Down Expand Up @@ -1058,6 +1135,23 @@ static JNINativeMethod methods[] = {
{"jni_YGNodeSetHasMeasureFuncJNI",
"(JZ)V",
(void*)jni_YGNodeSetHasMeasureFuncJNI},
// NOLINTBEGIN(cppcoreguidelines-pro-type-cstyle-cast)
{"jni_YGNodeSetHasMinContentMeasureFuncJNI",
"(JZ)V",
(void*)jni_YGNodeSetHasMinContentMeasureFuncJNI},
{"jni_YGNodeSetMinContentWidthJNI",
"(JF)V",
(void*)jni_YGNodeSetMinContentWidthJNI},
{"jni_YGNodeSetMinContentHeightJNI",
"(JF)V",
(void*)jni_YGNodeSetMinContentHeightJNI},
{"jni_YGNodeGetMinContentWidthJNI",
"(J)F",
(void*)jni_YGNodeGetMinContentWidthJNI},
{"jni_YGNodeGetMinContentHeightJNI",
"(J)F",
(void*)jni_YGNodeGetMinContentHeightJNI},
// NOLINTEND(cppcoreguidelines-pro-type-cstyle-cast)
{"jni_YGNodeStyleGetGapJNI", "(JI)J", (void*)jni_YGNodeStyleGetGapJNI},
{"jni_YGNodeStyleSetGapJNI", "(JIF)V", (void*)jni_YGNodeStyleSetGapJNI},
{"jni_YGNodeStyleSetGapPercentJNI",
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ const char* YGErrataToString(const YGErrata value) {
return "absolute-position-without-insets-excludes-padding";
case YGErrataAbsolutePercentAgainstInnerSize:
return "absolute-percent-against-inner-size";
case YGErrataMinSizeUndefinedInsteadOfAuto:
return "min-size-undefined-instead-of-auto";
case YGErrataAll:
return "all";
case YGErrataClassic:
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/ReactCommon/yoga/yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ YG_ENUM_DECL(
YGErrataStretchFlexBasis = 1,
YGErrataAbsolutePositionWithoutInsetsExcludesPadding = 2,
YGErrataAbsolutePercentAgainstInnerSize = 4,
YGErrataMinSizeUndefinedInsteadOfAuto = 8,
YGErrataAll = 2147483647,
YGErrataClassic = 2147483646)
YG_DEFINE_ENUM_FLAG_OPERATORS(YGErrata)
Expand Down
26 changes: 26 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,32 @@ bool YGNodeHasMeasureFunc(YGNodeConstRef node) {
return resolveRef(node)->hasMeasureFunc();
}

void YGNodeSetMinContentMeasureFunc(
YGNodeRef node,
YGMinContentMeasureFunc minContentMeasureFunc) {
resolveRef(node)->setMinContentMeasureFunc(minContentMeasureFunc);
}

bool YGNodeHasMinContentMeasureFunc(YGNodeConstRef node) {
return resolveRef(node)->hasMinContentMeasureFunc();
}

void YGNodeSetMinContentWidth(YGNodeRef node, float minContentWidth) {
resolveRef(node)->setMinContentWidth(FloatOptional{minContentWidth});
}

void YGNodeSetMinContentHeight(YGNodeRef node, float minContentHeight) {
resolveRef(node)->setMinContentHeight(FloatOptional{minContentHeight});
}

float YGNodeGetMinContentWidth(YGNodeConstRef node) {
return resolveRef(node)->getMinContentWidth().unwrapOrDefault(YGUndefined);
}

float YGNodeGetMinContentHeight(YGNodeConstRef node) {
return resolveRef(node)->getMinContentHeight().unwrapOrDefault(YGUndefined);
}

void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc) {
resolveRef(node)->setBaselineFunc(baselineFunc);
}
Expand Down
Loading
Loading