mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Multiline <TextInput> was fixed to match layout logic of singlelined one
Summary: Now padding, border and intinsic sizes are computed same way as for singlelined text input. Reviewed By: mmmulani Differential Revision: D5075880 fbshipit-source-id: 1bc2fd479c13a003c717b1fc3d9c69f4639d4444
This commit is contained in:
committed by
Facebook Github Bot
parent
4e40521620
commit
48650226e8
@@ -10,6 +10,7 @@
|
||||
#import "RCTUITextView.h"
|
||||
|
||||
#import <React/UIView+React.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
@implementation RCTUITextView
|
||||
{
|
||||
@@ -123,6 +124,21 @@ static UIColor *defaultPlaceholderTextColor()
|
||||
}
|
||||
|
||||
- (CGSize)sizeThatFits:(CGSize)size
|
||||
{
|
||||
// Returned fitting size depends on text size and placeholder size.
|
||||
CGSize textSize = [self fixedSizeThatFits:size];
|
||||
|
||||
UIEdgeInsets padddingInsets = self.textContainerInset;
|
||||
NSString *placeholderText = self.placeholderText ?: @"";
|
||||
CGSize placeholderSize = [placeholderText sizeWithAttributes:@{NSFontAttributeName: self.font ?: defaultPlaceholderFont()}];
|
||||
placeholderSize = CGSizeMake(RCTCeilPixelValue(placeholderSize.width), RCTCeilPixelValue(placeholderSize.height));
|
||||
placeholderSize.width += padddingInsets.left + padddingInsets.right;
|
||||
placeholderSize.height += padddingInsets.top + padddingInsets.bottom;
|
||||
|
||||
return CGSizeMake(MAX(textSize.width, placeholderSize.width), MAX(textSize.height, placeholderSize.height));
|
||||
}
|
||||
|
||||
- (CGSize)fixedSizeThatFits:(CGSize)size
|
||||
{
|
||||
// UITextView on iOS 8 has a bug that automatically scrolls to the top
|
||||
// when calling `sizeThatFits:`. Use a copy so that self is not screwed up.
|
||||
|
||||
Reference in New Issue
Block a user