Skip to content

Commit 38b5506

Browse files
RSNarafacebook-github-bot
authored andcommitted
iOS: Forward RN start/end styles to Yoga
Reviewed By: mmmulani Differential Revision: D5853589 fbshipit-source-id: 9acee0993a25dce5f4b1ce506746b789b1c4c763
1 parent 98547d4 commit 38b5506

4 files changed

Lines changed: 55 additions & 3 deletions

File tree

Libraries/StyleSheet/LayoutPropTypes.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ var LayoutPropTypes = {
5959
ReactPropTypes.string,
6060
]),
6161

62+
/**
63+
* When the direction is `ltr`, `start` is equivalent to `left`.
64+
* When the direction is `rtl`, `start` is equivalent to `right`.
65+
*
66+
* This style takes precedence over the `left`, `right`, and `end` styles.
67+
*/
68+
start: ReactPropTypes.oneOfType([
69+
ReactPropTypes.number,
70+
ReactPropTypes.string,
71+
]),
72+
73+
/**
74+
* When the direction is `ltr`, `end` is equivalent to `right`.
75+
* When the direction is `rtl`, `end` is equivalent to `left`.
76+
*
77+
* This style takes precedence over the `left` and `right` styles.
78+
*/
79+
end: ReactPropTypes.oneOfType([
80+
ReactPropTypes.number,
81+
ReactPropTypes.string,
82+
]),
83+
6284
/** `top` is the number of logical pixels to offset the top edge of
6385
* this component.
6486
*

React/Views/RCTShadowView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
9797
@property (nonatomic, assign) YGValue left;
9898
@property (nonatomic, assign) YGValue bottom;
9999
@property (nonatomic, assign) YGValue right;
100+
@property (nonatomic, assign) YGValue start;
101+
@property (nonatomic, assign) YGValue end;
100102

101103
@property (nonatomic, assign) YGValue width;
102104
@property (nonatomic, assign) YGValue height;

React/Views/RCTShadowView.m

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import "RCTUtils.h"
1515
#import "UIView+Private.h"
1616
#import "UIView+React.h"
17+
#import "RCTI18nUtil.h"
1718

1819
typedef void (^RCTActionBlock)(RCTShadowView *shadowViewSelf, id value);
1920
typedef void (^RCTResetActionBlock)(RCTShadowView *shadowViewSelf);
@@ -600,10 +601,35 @@ - (YGValue)getProp \
600601
return YGNodeStyleGetPosition(_yogaNode, edge); \
601602
}
602603

604+
603605
RCT_POSITION_PROPERTY(Top, top, YGEdgeTop)
604-
RCT_POSITION_PROPERTY(Right, right, YGEdgeEnd)
605606
RCT_POSITION_PROPERTY(Bottom, bottom, YGEdgeBottom)
606-
RCT_POSITION_PROPERTY(Left, left, YGEdgeStart)
607+
RCT_POSITION_PROPERTY(Start, start, YGEdgeStart)
608+
RCT_POSITION_PROPERTY(End, end, YGEdgeEnd)
609+
610+
- (void)setLeft:(YGValue)value
611+
{
612+
YGEdge edge = [[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles] ? YGEdgeStart : YGEdgeLeft;
613+
RCT_SET_YGVALUE(value, YGNodeStyleSetPosition, _yogaNode, edge);
614+
[self dirtyText];
615+
}
616+
- (YGValue)left
617+
{
618+
YGEdge edge = [[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles] ? YGEdgeStart : YGEdgeLeft;
619+
return YGNodeStyleGetPosition(_yogaNode, edge);
620+
}
621+
622+
- (void)setRight:(YGValue)value
623+
{
624+
YGEdge edge = [[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles] ? YGEdgeEnd : YGEdgeRight;
625+
RCT_SET_YGVALUE(value, YGNodeStyleSetPosition, _yogaNode, edge);
626+
[self dirtyText];
627+
}
628+
- (YGValue)right
629+
{
630+
YGEdge edge = [[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles] ? YGEdgeEnd : YGEdgeRight;
631+
return YGNodeStyleGetPosition(_yogaNode, edge);
632+
}
607633

608634
// Size
609635

React/Views/RCTViewManager.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,10 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDictio
269269

270270
RCT_EXPORT_SHADOW_PROPERTY(top, YGValue)
271271
RCT_EXPORT_SHADOW_PROPERTY(right, YGValue)
272+
RCT_EXPORT_SHADOW_PROPERTY(start, YGValue)
273+
RCT_EXPORT_SHADOW_PROPERTY(end, YGValue)
272274
RCT_EXPORT_SHADOW_PROPERTY(bottom, YGValue)
273-
RCT_EXPORT_SHADOW_PROPERTY(left, YGValue);
275+
RCT_EXPORT_SHADOW_PROPERTY(left, YGValue)
274276

275277
RCT_EXPORT_SHADOW_PROPERTY(width, YGValue)
276278
RCT_EXPORT_SHADOW_PROPERTY(height, YGValue)

0 commit comments

Comments
 (0)