Added support for text padding

This commit is contained in:
Nick Lockwood 2015-03-27 09:36:33 -07:00
Родитель a925082d2e
Коммит 698988017c
8 изменённых файлов: 31 добавлений и 6 удалений

Просмотреть файл

@ -71,6 +71,15 @@ exports.examples = [
</Text>
);
},
}, {
title: 'Padding',
render: function() {
return (
<Text style={{padding: 10}}>
This text is indented by 10px padding on all sides.
</Text>
);
},
}, {
title: 'Font Family',
render: function() {

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 253 KiB

После

Ширина:  |  Высота:  |  Размер: 260 KiB

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
};
}