Skip to content

Commit

Permalink
Update YGNodeStyleGetGap to return YGValue
Browse files Browse the repository at this point in the history
Summary:
Gap can be styled using both `points` and `percentages`, but YGNodeStyleGetGap currently returns a float value.

To maintain alignment with the `padding` and `margin` functionalities and allow it to be handled in bridging code, this function has been updated to return YGValue.

X-link: facebook/yoga#1753

Reviewed By: joevilches

Differential Revision: D66513236

Pulled By: NickGerleman
  • Loading branch information
heoblitz authored and facebook-github-bot committed Dec 3, 2024
1 parent fa8a25e commit c71eacb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 32 deletions.
6 changes: 3 additions & 3 deletions packages/react-native/React/Views/RCTShadowView.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry

@property (nonatomic, assign) float flex;
@property (nonatomic, assign) float flexGrow;
@property (nonatomic, assign) float rowGap;
@property (nonatomic, assign) float columnGap;
@property (nonatomic, assign) float gap;
@property (nonatomic, assign) YGValue rowGap;
@property (nonatomic, assign) YGValue columnGap;
@property (nonatomic, assign) YGValue gap;
@property (nonatomic, assign) float flexShrink;
@property (nonatomic, assign) YGValue flexBasis;

Expand Down
26 changes: 13 additions & 13 deletions packages/react-native/React/Views/RCTShadowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -642,19 +642,19 @@ - (YGValue)flexBasis
return YGNodeStyleGetFlexBasis(_yogaNode);
}

#define RCT_GAP_PROPERTY(setProp, getProp, cssProp, type, gap) \
-(void)set##setProp : (type)value \
{ \
YGNodeStyleSet##cssProp(_yogaNode, gap, value); \
} \
-(type)getProp \
{ \
return YGNodeStyleGet##cssProp(_yogaNode, gap); \
}

RCT_GAP_PROPERTY(RowGap, rowGap, Gap, float, YGGutterRow);
RCT_GAP_PROPERTY(ColumnGap, columnGap, Gap, float, YGGutterColumn);
RCT_GAP_PROPERTY(Gap, gap, Gap, float, YGGutterAll);
#define RCT_GAP_PROPERTY(setProp, getProp, cssProp, gutter) \
-(void)set##setProp : (YGValue)value \
{ \
RCT_SET_YGVALUE(value, YGNodeStyleSetGap, _yogaNode, gutter); \
} \
-(YGValue)getProp \
{ \
return YGNodeStyleGet##cssProp(_yogaNode, gutter); \
}

RCT_GAP_PROPERTY(RowGap, rowGap, Gap, YGGutterRow);
RCT_GAP_PROPERTY(ColumnGap, columnGap, Gap, YGGutterColumn);
RCT_GAP_PROPERTY(Gap, gap, Gap, YGGutterAll);

#define RCT_STYLE_PROPERTY(setProp, getProp, cssProp, type) \
-(void)set##setProp : (type)value \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class YogaNative {
static native void jni_YGNodeStyleSetMaxHeightPercentJNI(long nativePointer, float percent);
static native float jni_YGNodeStyleGetAspectRatioJNI(long nativePointer);
static native void jni_YGNodeStyleSetAspectRatioJNI(long nativePointer, float aspectRatio);
static native float jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter);
static native long jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter);
static native void jni_YGNodeStyleSetGapJNI(long nativePointer, int gutter, float gapLength);
static native void jni_YGNodeStyleSetGapPercentJNI(long nativePointer, int gutter, float gapLength);
static native void jni_YGNodeSetHasMeasureFuncJNI(long nativePointer, boolean hasMeasureFunc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public interface Inputs {

public abstract void setAspectRatio(float aspectRatio);

public abstract float getGap(YogaGutter gutter);
public abstract YogaValue getGap(YogaGutter gutter);

public abstract void setGap(YogaGutter gutter, float gapLength);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ public void markLayoutSeen() {
}

@Override
public float getGap(YogaGutter gutter) {
return YogaNative.jni_YGNodeStyleGetGapJNI(mNativePointer, gutter.intValue());
public YogaValue getGap(YogaGutter gutter) {
return valueFromLong(YogaNative.jni_YGNodeStyleGetGapJNI(mNativePointer, gutter.intValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,13 @@ jni_YGNodeCloneJNI(JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) {
return reinterpret_cast<jlong>(clonedYogaNode);
}

static jfloat jni_YGNodeStyleGetGapJNI(
static jlong jni_YGNodeStyleGetGapJNI(
JNIEnv* /*env*/,
jobject /*obj*/,
jlong nativePointer,
jint gutter) {
return (jfloat)YGNodeStyleGetGap(
_jlong2YGNodeRef(nativePointer), static_cast<YGGutter>(gutter));
return YogaValue::asJavaLong(YGNodeStyleGetGap(
_jlong2YGNodeRef(nativePointer), static_cast<YGGutter>(gutter)));
}

static void jni_YGNodeStyleSetGapJNI(
Expand Down Expand Up @@ -972,7 +972,7 @@ static JNINativeMethod methods[] = {
{"jni_YGNodeSetHasMeasureFuncJNI",
"(JZ)V",
(void*)jni_YGNodeSetHasMeasureFuncJNI},
{"jni_YGNodeStyleGetGapJNI", "(JI)F", (void*)jni_YGNodeStyleGetGapJNI},
{"jni_YGNodeStyleGetGapJNI", "(JI)J", (void*)jni_YGNodeStyleGetGapJNI},
{"jni_YGNodeStyleSetGapJNI", "(JIF)V", (void*)jni_YGNodeStyleSetGapJNI},
{"jni_YGNodeStyleSetGapPercentJNI",
"(JIF)V",
Expand Down
9 changes: 2 additions & 7 deletions packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,8 @@ void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
node, scopedEnum(gutter), StyleLength::percent(percent));
}

float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
auto gapLength = resolveRef(node)->style().gap(scopedEnum(gutter));
if (gapLength.isUndefined() || gapLength.isAuto()) {
return YGUndefined;
}

return static_cast<YGValue>(gapLength).value;
YGValue YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
return (YGValue)resolveRef(node)->style().gap(scopedEnum(gutter));
}

void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ YG_EXPORT void
YGNodeStyleSetGap(YGNodeRef node, YGGutter gutter, float gapLength);
YG_EXPORT void
YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float gapLength);
YG_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter);
YG_EXPORT YGValue YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter);

YG_EXPORT void YGNodeStyleSetBoxSizing(YGNodeRef node, YGBoxSizing boxSizing);
YG_EXPORT YGBoxSizing YGNodeStyleGetBoxSizing(YGNodeConstRef node);
Expand Down

0 comments on commit c71eacb

Please sign in to comment.