Added support for text padding
This commit is contained in:
Родитель
a925082d2e
Коммит
698988017c
|
@ -71,6 +71,15 @@ exports.examples = [
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
title: 'Padding',
|
||||||
|
render: function() {
|
||||||
|
return (
|
||||||
|
<Text style={{padding: 10}}>
|
||||||
|
This text is indented by 10px padding on all sides.
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
title: 'Font Family',
|
title: 'Font Family',
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 253 KiB После Ширина: | Высота: | Размер: 260 KiB |
|
@ -14,5 +14,6 @@
|
||||||
@property (nonatomic, copy) NSAttributedString *attributedText;
|
@property (nonatomic, copy) NSAttributedString *attributedText;
|
||||||
@property (nonatomic, assign) NSLineBreakMode lineBreakMode;
|
@property (nonatomic, assign) NSLineBreakMode lineBreakMode;
|
||||||
@property (nonatomic, assign) NSUInteger numberOfLines;
|
@property (nonatomic, assign) NSUInteger numberOfLines;
|
||||||
|
@property (nonatomic, assign) UIEdgeInsets contentInset;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -72,20 +72,26 @@
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (CGRect)textFrame
|
||||||
|
{
|
||||||
|
return UIEdgeInsetsInsetRect(self.bounds, _contentInset);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)layoutSubviews
|
- (void)layoutSubviews
|
||||||
{
|
{
|
||||||
[super layoutSubviews];
|
[super layoutSubviews];
|
||||||
|
|
||||||
// The header comment for `size` says that a height of 0.0 should be enough,
|
// The header comment for `size` says that a height of 0.0 should be enough,
|
||||||
// but it isn't.
|
// 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
|
- (void)drawRect:(CGRect)rect
|
||||||
{
|
{
|
||||||
|
CGPoint origin = [self textFrame].origin;
|
||||||
NSRange glyphRange = [_layoutManager glyphRangeForTextContainer:_textContainer];
|
NSRange glyphRange = [_layoutManager glyphRangeForTextContainer:_textContainer];
|
||||||
[_layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:CGPointZero];
|
[_layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:origin];
|
||||||
[_layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:CGPointZero];
|
[_layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:origin];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSNumber *)reactTagAtPoint:(CGPoint)point
|
- (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
|
@end
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL caretHidden;
|
@property (nonatomic, assign) BOOL caretHidden;
|
||||||
@property (nonatomic, assign) BOOL autoCorrect;
|
@property (nonatomic, assign) BOOL autoCorrect;
|
||||||
@property (nonatomic, assign) UIEdgeInsets paddingEdgeInsets; // TODO: contentInset
|
@property (nonatomic, assign) UIEdgeInsets contentInset;
|
||||||
|
|
||||||
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
|
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
- (CGRect)textRectForBounds:(CGRect)bounds
|
- (CGRect)textRectForBounds:(CGRect)bounds
|
||||||
{
|
{
|
||||||
CGRect rect = [super textRectForBounds:bounds];
|
CGRect rect = [super textRectForBounds:bounds];
|
||||||
return UIEdgeInsetsInsetRect(rect, _paddingEdgeInsets);
|
return UIEdgeInsetsInsetRect(rect, _contentInset);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGRect)editingRectForBounds:(CGRect)bounds
|
- (CGRect)editingRectForBounds:(CGRect)bounds
|
||||||
|
|
|
@ -53,7 +53,7 @@ RCT_CUSTOM_VIEW_PROPERTY(fontFamily, NSString, RCTTextField)
|
||||||
NSNumber *reactTag = shadowView.reactTag;
|
NSNumber *reactTag = shadowView.reactTag;
|
||||||
UIEdgeInsets padding = shadowView.paddingAsInsets;
|
UIEdgeInsets padding = shadowView.paddingAsInsets;
|
||||||
return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
||||||
((RCTTextField *)viewRegistry[reactTag]).paddingEdgeInsets = padding;
|
((RCTTextField *)viewRegistry[reactTag]).contentInset = padding;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче