Skip to content

Commit

Permalink
Added placeholderTextColor property for TextInput class
Browse files Browse the repository at this point in the history
Summary:
Closes #997
Github Author: Maksim Bunkow <bimawa@gmail.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
  • Loading branch information
bimawa committed Apr 27, 2015
1 parent 826b56a commit bae4e44
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions Libraries/Components/TextInput/TextInput.js
Expand Up @@ -445,6 +445,7 @@ var TextInput = React.createClass({
onSubmitEditing={this.props.onSubmitEditing}
onSelectionChangeShouldSetResponder={() => true}
placeholder={this.props.placeholder}
placeholderTextColor={this.props.placeholderTextColor}
text={this.state.bufferedValue}
autoCapitalize={autoCapitalize}
autoCorrect={this.props.autoCorrect}
Expand Down
1 change: 1 addition & 0 deletions React/Views/RCTTextField.h
Expand Up @@ -17,6 +17,7 @@
@property (nonatomic, assign) BOOL autoCorrect;
@property (nonatomic, assign) BOOL selectTextOnFocus;
@property (nonatomic, assign) UIEdgeInsets contentInset;
@property (nonatomic, strong) UIColor *placeholderTextColor;

- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;

Expand Down
22 changes: 22 additions & 0 deletions React/Views/RCTTextField.m
Expand Up @@ -42,6 +42,28 @@ - (void)setText:(NSString *)text
}
}

static void RCTUpdatePlaceholder(RCTTextField *self)
{
if (self.placeholder.length > 0 && self.placeholderTextColor) {
self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder
attributes:@{
NSForegroundColorAttributeName : self.placeholderTextColor
}];
} else if (self.placeholder.length) {
self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder];
}
}

- (void)setPlaceholderTextColor:(UIColor *)placeholderTextColor {
_placeholderTextColor = placeholderTextColor;
RCTUpdatePlaceholder(self);
}

- (void)setPlaceholder:(NSString *)placeholder {
super.placeholder = placeholder;
RCTUpdatePlaceholder(self);
}

- (NSArray *)reactSubviews
{
// TODO: do we support subviews of textfield in React?
Expand Down
2 changes: 1 addition & 1 deletion React/Views/RCTTextFieldManager.m
Expand Up @@ -10,7 +10,6 @@
#import "RCTTextFieldManager.h"

#import "RCTBridge.h"
#import "RCTConvert.h"
#import "RCTShadowView.h"
#import "RCTSparseArray.h"
#import "RCTTextField.h"
Expand All @@ -28,6 +27,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(autoCorrect, BOOL)
RCT_EXPORT_VIEW_PROPERTY(enabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
RCT_EXPORT_VIEW_PROPERTY(placeholderTextColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
RCT_EXPORT_VIEW_PROPERTY(clearButtonMode, UITextFieldViewMode)
RCT_REMAP_VIEW_PROPERTY(clearTextOnFocus, clearsOnBeginEditing, BOOL)
Expand Down

0 comments on commit bae4e44

Please sign in to comment.