diff --git a/Libraries/StyleSheet/LayoutPropTypes.js b/Libraries/StyleSheet/LayoutPropTypes.js index df0fb87ef..a8ab32c07 100644 --- a/Libraries/StyleSheet/LayoutPropTypes.js +++ b/Libraries/StyleSheet/LayoutPropTypes.js @@ -27,6 +27,13 @@ var ReactPropTypes = require('React').PropTypes; * algorithm and affect the positioning and sizing of views. */ var LayoutPropTypes = { + /** `display` sets the display type of this component. + * + * It works similarly to `display` in CSS, but only support 'flex' and 'none'. + * 'flex' is the default. + */ + display: ReactPropTypes.string, + /** `width` sets the width of this component. * * It works similarly to `width` in CSS, but in React Native you diff --git a/React/Base/RCTConvert.h b/React/Base/RCTConvert.h index 57e8333df..dbd4d1f7b 100644 --- a/React/Base/RCTConvert.h +++ b/React/Base/RCTConvert.h @@ -112,6 +112,7 @@ typedef id NSPropertyList; typedef BOOL css_backface_visibility_t; + (YGOverflow)YGOverflow:(id)json; ++ (YGDisplay)YGDisplay:(id)json; + (css_backface_visibility_t)css_backface_visibility_t:(id)json; + (YGFlexDirection)YGFlexDirection:(id)json; + (YGJustify)YGJustify:(id)json; diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 89409e932..256fd854b 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -645,6 +645,11 @@ RCT_ENUM_CONVERTER(YGOverflow, (@{ @"scroll": @(YGOverflowScroll), }), YGOverflowVisible, intValue) +RCT_ENUM_CONVERTER(YGDisplay, (@{ + @"flex": @(YGDisplayFlex), + @"none": @(YGDisplayNone), +}), YGDisplayFlex, intValue) + RCT_ENUM_CONVERTER(YGFlexDirection, (@{ @"row": @(YGFlexDirectionRow), @"row-reverse": @(YGFlexDirectionRowReverse), diff --git a/React/Views/RCTShadowView.h b/React/Views/RCTShadowView.h index 3895985bb..bc15bfe59 100644 --- a/React/Views/RCTShadowView.h +++ b/React/Views/RCTShadowView.h @@ -133,6 +133,7 @@ typedef void (^RCTApplierBlock)(NSDictionary *viewRegistry @property (nonatomic, assign) YGAlign alignContent; @property (nonatomic, assign) YGPositionType position; @property (nonatomic, assign) YGWrap flexWrap; +@property (nonatomic, assign) YGDisplay display; @property (nonatomic, assign) float flexGrow; @property (nonatomic, assign) float flexShrink; diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index a45c47a1b..c50f38281 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -704,6 +704,7 @@ RCT_STYLE_PROPERTY(AlignContent, alignContent, AlignContent, YGAlign) RCT_STYLE_PROPERTY(Position, position, PositionType, YGPositionType) RCT_STYLE_PROPERTY(FlexWrap, flexWrap, FlexWrap, YGWrap) RCT_STYLE_PROPERTY(Overflow, overflow, Overflow, YGOverflow) +RCT_STYLE_PROPERTY(Display, display, Display, YGDisplay) RCT_STYLE_PROPERTY(Direction, direction, Direction, YGDirection) RCT_STYLE_PROPERTY(AspectRatio, aspectRatio, AspectRatio, float) diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index 792f6cc87..7bbc97410 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -310,6 +310,7 @@ RCT_EXPORT_SHADOW_PROPERTY(position, YGPositionType) RCT_EXPORT_SHADOW_PROPERTY(aspectRatio, float) RCT_EXPORT_SHADOW_PROPERTY(overflow, YGOverflow) +RCT_EXPORT_SHADOW_PROPERTY(display, YGDisplay) RCT_EXPORT_SHADOW_PROPERTY(onLayout, RCTDirectEventBlock) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java index d526b7d39..3f5020e3a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java @@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReadableType; import com.facebook.yoga.YogaAlign; import com.facebook.yoga.YogaConstants; +import com.facebook.yoga.YogaDisplay; import com.facebook.yoga.YogaFlexDirection; import com.facebook.yoga.YogaJustify; import com.facebook.yoga.YogaOverflow; @@ -311,6 +312,15 @@ public class LayoutShadowNode extends ReactShadowNode { overflow.toUpperCase(Locale.US).replace("-", "_"))); } + @ReactProp(name = ViewProps.DISPLAY) + public void setDisplay(@Nullable String display) { + if (isVirtual()) { + return; + } + setDisplay(display == null ? YogaDisplay.FLEX : YogaDisplay.valueOf( + display.toUpperCase(Locale.US).replace("-", "_"))); + } + @ReactPropGroup(names = { ViewProps.MARGIN, ViewProps.MARGIN_VERTICAL, diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java index e1278b14c..2cad696e5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.ArrayList; import com.facebook.yoga.YogaAlign; +import com.facebook.yoga.YogaDisplay; import com.facebook.yoga.YogaEdge; import com.facebook.yoga.YogaConstants; import com.facebook.yoga.YogaDirection; @@ -662,6 +663,10 @@ public class ReactShadowNode { mYogaNode.setOverflow(overflow); } + public void setDisplay(YogaDisplay display) { + mYogaNode.setDisplay(display); + } + public void setMargin(int spacingType, float margin) { mYogaNode.setMargin(YogaEdge.fromInt(spacingType), margin); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java index 4d60d3add..67265436a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java @@ -27,6 +27,7 @@ public class ViewProps { public static final String ALIGN_SELF = "alignSelf"; public static final String ALIGN_CONTENT = "alignContent"; public static final String OVERFLOW = "overflow"; + public static final String DISPLAY = "display"; public static final String BOTTOM = "bottom"; public static final String COLLAPSABLE = "collapsable"; public static final String FLEX = "flex"; @@ -124,6 +125,7 @@ public class ViewProps { JUSTIFY_CONTENT, OVERFLOW, ALIGN_CONTENT, + DISPLAY, /* position */ POSITION,