Skip to content

Commit

Permalink
Re-render views when direction changes
Browse files Browse the repository at this point in the history
Summary:
This is required for D5874536, wherein I'll be introducing direction-aware props for borders.

When a view's border changes due to a direction update, only the frames of its children update. Therefore, only the children `UIView`s get a chance to be re-rendered. This is incorrect because the view that's had its borders changed also needs to re-render. So, I keep a track of the layout direction in a property on all shadow views. Then, when I update that prop within `applyLayoutNode`, I push shadow views into the `viewsWithNewFrames` set.

Reviewed By: mmmulani

Differential Revision: D5944488

fbshipit-source-id: 3f23e9973f3555612920703cdb6cec38e6360d2d
  • Loading branch information
RSNara authored and facebook-github-bot committed Oct 2, 2017
1 parent 53a339a commit 9bbc70c
Show file tree
Hide file tree
Showing 6 changed files with 623 additions and 435 deletions.
12 changes: 6 additions & 6 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ @implementation RCTShadowText
CGFloat _cachedTextStorageWidthMode;
NSAttributedString *_cachedAttributedString;
CGFloat _effectiveLetterSpacing;
UIUserInterfaceLayoutDirection _cachedEffectiveLayoutDirection;
UIUserInterfaceLayoutDirection _cachedLayoutDirection;
}

static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode)
Expand Down Expand Up @@ -72,7 +72,7 @@ - (instancetype)init
_fontSizeMultiplier = 1.0;
_textAlign = NSTextAlignmentNatural;
_writingDirection = NSWritingDirectionNatural;
_cachedEffectiveLayoutDirection = UIUserInterfaceLayoutDirectionLeftToRight;
_cachedLayoutDirection = UIUserInterfaceLayoutDirectionLeftToRight;

YGNodeSetMeasureFunc(self.yogaNode, RCTMeasure);

Expand Down Expand Up @@ -198,7 +198,7 @@ - (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(YGMeasureM
_cachedTextStorage &&
(width == _cachedTextStorageWidth || (isnan(width) && isnan(_cachedTextStorageWidth))) &&
widthMode == _cachedTextStorageWidthMode &&
_cachedEffectiveLayoutDirection == self.effectiveLayoutDirection
_cachedLayoutDirection == self.layoutDirection
) {
return _cachedTextStorage;
}
Expand Down Expand Up @@ -272,12 +272,12 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
if (
![self isTextDirty] &&
_cachedAttributedString &&
_cachedEffectiveLayoutDirection == self.effectiveLayoutDirection
_cachedLayoutDirection == self.layoutDirection
) {
return _cachedAttributedString;
}

_cachedEffectiveLayoutDirection = self.effectiveLayoutDirection;
_cachedLayoutDirection = self.layoutDirection;

if (_fontSize && !isnan(_fontSize)) {
fontSize = @(_fontSize);
Expand Down Expand Up @@ -419,7 +419,7 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
// Text alignment
NSTextAlignment textAlign = _textAlign;
if (textAlign == NSTextAlignmentRight || textAlign == NSTextAlignmentLeft) {
if (_cachedEffectiveLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
if (_cachedLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
if (textAlign == NSTextAlignmentRight) {
textAlign = NSTextAlignmentLeft;
} else {
Expand Down
Loading

0 comments on commit 9bbc70c

Please sign in to comment.