Implements blurOnSubmit

Summary: The default value (to retain current behavior) is set to `true`. Setting the value to `false` will prevent the textField from blurring but still fire the `onSubmitEditing` callback. However, the `onEndEditing` callback will not be fired.

Addresses issue: https://github.com/facebook/react-native/issues/2129
Closes https://github.com/facebook/react-native/pull/2149

Reviewed By: svcscm

Differential Revision: D2619822

Pulled By: nicklockwood

fb-gh-sync-id: 9a61152892f4afb5c6c53e7b38dffae13bc7e13f
This commit is contained in:
Dave Sibiski
2015-11-04 21:01:49 -08:00
committed by facebook-github-bot-6
parent 66f7feda4d
commit 7af752403e
5 changed files with 94 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
@property (nonatomic, assign) BOOL caretHidden;
@property (nonatomic, assign) BOOL autoCorrect;
@property (nonatomic, assign) BOOL selectTextOnFocus;
@property (nonatomic, assign) BOOL blurOnSubmit;
@property (nonatomic, assign) UIEdgeInsets contentInset;
@property (nonatomic, strong) UIColor *placeholderTextColor;
@property (nonatomic, assign) NSInteger mostRecentEventCount;
@@ -26,5 +27,6 @@
- (void)textFieldDidChange;
- (void)sendKeyValueForString:(NSString *)string;
- (BOOL)textFieldShouldEndEditing:(RCTTextField *)textField;
@end

View File

@@ -20,6 +20,7 @@
NSMutableArray<UIView *> *_reactSubviews;
BOOL _jsRequestingFirstResponder;
NSInteger _nativeEventCount;
BOOL _submitted;
}
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
@@ -165,6 +166,7 @@ static void RCTUpdatePlaceholder(RCTTextField *self)
}
- (void)textFieldSubmitEditing
{
_submitted = YES;
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeSubmit
reactTag:self.reactTag
text:self.text
@@ -186,6 +188,15 @@ static void RCTUpdatePlaceholder(RCTTextField *self)
eventCount:_nativeEventCount];
}
- (BOOL)textFieldShouldEndEditing:(RCTTextField *)textField
{
if (_submitted) {
_submitted = NO;
return _blurOnSubmit;
}
return YES;
}
- (BOOL)becomeFirstResponder
{
_jsRequestingFirstResponder = YES;

View File

@@ -69,6 +69,11 @@ RCT_EXPORT_MODULE()
return YES;
}
- (BOOL)textFieldShouldEndEditing:(RCTTextField *)textField
{
return [textField textFieldShouldEndEditing:textField];
}
RCT_EXPORT_VIEW_PROPERTY(caretHidden, BOOL)
RCT_EXPORT_VIEW_PROPERTY(autoCorrect, BOOL)
RCT_REMAP_VIEW_PROPERTY(editable, enabled, BOOL)
@@ -79,6 +84,7 @@ RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(clearButtonMode, UITextFieldViewMode)
RCT_REMAP_VIEW_PROPERTY(clearTextOnFocus, clearsOnBeginEditing, BOOL)
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType)
RCT_EXPORT_VIEW_PROPERTY(returnKeyType, UIReturnKeyType)
RCT_EXPORT_VIEW_PROPERTY(enablesReturnKeyAutomatically, BOOL)