diff --git a/Examples/UIExplorer/TextExample.ios.js b/Examples/UIExplorer/TextExample.ios.js index e88bc4a0c0..d2b3ced41d 100644 --- a/Examples/UIExplorer/TextExample.ios.js +++ b/Examples/UIExplorer/TextExample.ios.js @@ -71,6 +71,15 @@ exports.examples = [ ); }, +}, { + title: 'Padding', + render: function() { + return ( + + This text is indented by 10px padding on all sides. + + ); + }, }, { title: 'Font Family', render: function() { diff --git a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTextExampleSnapshot_1@2x.png b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTextExampleSnapshot_1@2x.png index 044576efc9..5b71135b97 100644 Binary files a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTextExampleSnapshot_1@2x.png and b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTextExampleSnapshot_1@2x.png differ diff --git a/Libraries/Text/RCTText.h b/Libraries/Text/RCTText.h index bb9fb6dfcb..59b15668a7 100644 --- a/Libraries/Text/RCTText.h +++ b/Libraries/Text/RCTText.h @@ -14,5 +14,6 @@ @property (nonatomic, copy) NSAttributedString *attributedText; @property (nonatomic, assign) NSLineBreakMode lineBreakMode; @property (nonatomic, assign) NSUInteger numberOfLines; +@property (nonatomic, assign) UIEdgeInsets contentInset; @end diff --git a/Libraries/Text/RCTText.m b/Libraries/Text/RCTText.m index 457079bcbf..a2f7f11cc7 100644 --- a/Libraries/Text/RCTText.m +++ b/Libraries/Text/RCTText.m @@ -72,20 +72,26 @@ [self setNeedsDisplay]; } +- (CGRect)textFrame +{ + return UIEdgeInsetsInsetRect(self.bounds, _contentInset); +} + - (void)layoutSubviews { [super layoutSubviews]; // The header comment for `size` says that a height of 0.0 should be enough, // but it isn't. - _textContainer.size = CGSizeMake(self.bounds.size.width, CGFLOAT_MAX); + _textContainer.size = CGSizeMake([self textFrame].size.width, CGFLOAT_MAX); } - (void)drawRect:(CGRect)rect { + CGPoint origin = [self textFrame].origin; NSRange glyphRange = [_layoutManager glyphRangeForTextContainer:_textContainer]; - [_layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:CGPointZero]; - [_layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:CGPointZero]; + [_layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:origin]; + [_layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:origin]; } - (NSNumber *)reactTagAtPoint:(CGPoint)point diff --git a/Libraries/Text/RCTTextManager.m b/Libraries/Text/RCTTextManager.m index 95896fd058..8df67e59ef 100644 --- a/Libraries/Text/RCTTextManager.m +++ b/Libraries/Text/RCTTextManager.m @@ -124,4 +124,13 @@ RCT_CUSTOM_SHADOW_PROPERTY(numberOfLines, NSInteger, RCTShadowText) }; } +- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView +{ + NSNumber *reactTag = shadowView.reactTag; + UIEdgeInsets padding = shadowView.paddingAsInsets; + return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + ((RCTText *)viewRegistry[reactTag]).contentInset = padding; + }; +} + @end diff --git a/React/Views/RCTTextField.h b/React/Views/RCTTextField.h index 99b5b7cba3..47d76ad528 100644 --- a/React/Views/RCTTextField.h +++ b/React/Views/RCTTextField.h @@ -15,7 +15,7 @@ @property (nonatomic, assign) BOOL caretHidden; @property (nonatomic, assign) BOOL autoCorrect; -@property (nonatomic, assign) UIEdgeInsets paddingEdgeInsets; // TODO: contentInset +@property (nonatomic, assign) UIEdgeInsets contentInset; - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER; diff --git a/React/Views/RCTTextField.m b/React/Views/RCTTextField.m index 1ccf17d7f5..5fb0960058 100644 --- a/React/Views/RCTTextField.m +++ b/React/Views/RCTTextField.m @@ -71,7 +71,7 @@ - (CGRect)textRectForBounds:(CGRect)bounds { CGRect rect = [super textRectForBounds:bounds]; - return UIEdgeInsetsInsetRect(rect, _paddingEdgeInsets); + return UIEdgeInsetsInsetRect(rect, _contentInset); } - (CGRect)editingRectForBounds:(CGRect)bounds diff --git a/React/Views/RCTTextFieldManager.m b/React/Views/RCTTextFieldManager.m index 087dc5b264..7385b49ad1 100644 --- a/React/Views/RCTTextFieldManager.m +++ b/React/Views/RCTTextFieldManager.m @@ -53,7 +53,7 @@ RCT_CUSTOM_VIEW_PROPERTY(fontFamily, NSString, RCTTextField) NSNumber *reactTag = shadowView.reactTag; UIEdgeInsets padding = shadowView.paddingAsInsets; return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { - ((RCTTextField *)viewRegistry[reactTag]).paddingEdgeInsets = padding; + ((RCTTextField *)viewRegistry[reactTag]).contentInset = padding; }; }