Skip to content

Commit

Permalink
placeholderText was renamed to just placeholder in RCTTextView
Browse files Browse the repository at this point in the history
Summary: We have to have RCTTextView and RCTTextInput as much unified as possible, and this is a small step in this direction.

Reviewed By: javache

Differential Revision: D5143877

fbshipit-source-id: ee8fcab6093fe5d994c85110b07ea16e64fed262
  • Loading branch information
shergin authored and facebook-github-bot committed Jun 27, 2017
1 parent 719f000 commit 2bf4167
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions Libraries/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,23 @@ - (void)setText:(NSString *)text

- (NSString *)placeholder
{
return _textView.placeholderText;
return _textView.placeholder;
}

- (void)setPlaceholder:(NSString *)placeholder
{
_textView.placeholderText = placeholder;
_textView.placeholder = placeholder;
[self setNeedsLayout];
}

- (UIColor *)placeholderTextColor
- (UIColor *)placeholderColor
{
return _textView.placeholderTextColor;
return _textView.placeholderColor;
}

- (void)setPlaceholderTextColor:(UIColor *)placeholderTextColor
- (void)setPlaceholderColor:(UIColor *)placeholderColor
{
_textView.placeholderTextColor = placeholderTextColor;
_textView.placeholderColor = placeholderColor;
}

- (void)setAutocorrectionType:(UITextAutocorrectionType)autocorrectionType
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Text/RCTTextViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
RCT_EXPORT_VIEW_PROPERTY(placeholderTextColor, UIColor)
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, placeholderColor, UIColor)
RCT_REMAP_VIEW_PROPERTY(returnKeyType, textView.returnKeyType, UIReturnKeyType)
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, textView.secureTextEntry, BOOL)
RCT_REMAP_VIEW_PROPERTY(selectionColor, tintColor, UIColor)
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Text/RCTUITextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;

@property (nonatomic, assign, readonly) BOOL textWasPasted;
@property (nonatomic, copy, nullable) NSString *placeholderText;
@property (nonatomic, assign, nullable) UIColor *placeholderTextColor;
@property (nonatomic, copy, nullable) NSString *placeholder;
@property (nonatomic, strong, nullable) UIColor *placeholderColor;

@end

Expand Down
26 changes: 13 additions & 13 deletions Libraries/Text/RCTUITextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ @implementation RCTUITextView
return [UIFont systemFontOfSize:17];
}

static UIColor *defaultPlaceholderTextColor()
static UIColor *defaultPlaceholderColor()
{
// Default placeholder color from UITextField.
return [UIColor colorWithRed:0 green:0 blue:0.0980392 alpha:0.22];
Expand All @@ -40,7 +40,7 @@ - (instancetype)initWithFrame:(CGRect)frame
_placeholderView = [[UILabel alloc] initWithFrame:self.bounds];
_placeholderView.isAccessibilityElement = NO;
_placeholderView.numberOfLines = 0;
_placeholderView.textColor = defaultPlaceholderTextColor();
_placeholderView.textColor = defaultPlaceholderColor();
[self addSubview:_placeholderView];
}

Expand All @@ -61,28 +61,28 @@ - (NSString *)accessibilityLabel
[accessibilityLabel appendString:superAccessibilityLabel];
}

if (self.placeholderText.length > 0 && self.text.length == 0) {
if (self.placeholder.length > 0 && self.text.length == 0) {
if (accessibilityLabel.length > 0) {
[accessibilityLabel appendString:@" "];
}
[accessibilityLabel appendString:self.placeholderText];
[accessibilityLabel appendString:self.placeholder];
}

return accessibilityLabel;
}

#pragma mark - Properties

- (void)setPlaceholderText:(NSString *)placeholderText
- (void)setPlaceholder:(NSString *)placeholder
{
_placeholderText = placeholderText;
_placeholderView.text = _placeholderText;
_placeholder = placeholder;
_placeholderView.text = _placeholder;
}

- (void)setPlaceholderTextColor:(UIColor *)placeholderTextColor
- (void)setPlaceholderColor:(UIColor *)placeholderColor
{
_placeholderTextColor = placeholderTextColor;
_placeholderView.textColor = _placeholderTextColor ?: defaultPlaceholderTextColor();
_placeholderColor = placeholderColor;
_placeholderView.textColor = _placeholderColor ?: defaultPlaceholderColor();
}

- (void)textDidChange
Expand Down Expand Up @@ -148,8 +148,8 @@ - (CGSize)sizeThatFits:(CGSize)size
CGSize textSize = [self fixedSizeThatFits:size];

UIEdgeInsets padddingInsets = self.textContainerInset;
NSString *placeholderText = self.placeholderText ?: @"";
CGSize placeholderSize = [placeholderText sizeWithAttributes:@{NSFontAttributeName: self.font ?: defaultPlaceholderFont()}];
NSString *placeholder = self.placeholder ?: @"";
CGSize placeholderSize = [placeholder 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;
Expand Down Expand Up @@ -186,7 +186,7 @@ - (CGSize)fixedSizeThatFits:(CGSize)size

- (void)invalidatePlaceholderVisibility
{
BOOL isVisible = _placeholderText.length != 0 && self.text.length == 0;
BOOL isVisible = _placeholder.length != 0 && self.text.length == 0;
_placeholderView.hidden = !isVisible;
}

Expand Down

0 comments on commit 2bf4167

Please sign in to comment.