File tree Expand file tree Collapse file tree 5 files changed +94
-1
lines changed
Expand file tree Collapse file tree 5 files changed +94
-1
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,60 @@ class RewriteExample extends React.Component {
120120 }
121121}
122122
123+ var BlurOnSubmitExample = React . createClass ( {
124+ focusNextField ( nextField ) {
125+ this . refs [ nextField ] . focus ( )
126+ } ,
127+
128+ render : function ( ) {
129+ return (
130+ < View >
131+ < TextInput
132+ ref = '1'
133+ style = { styles . default }
134+ placeholder = 'blurOnSubmit = false'
135+ returnKeyType = 'next'
136+ blurOnSubmit = { false }
137+ onSubmitEditing = { ( ) => this . focusNextField ( '2' ) }
138+ />
139+ < TextInput
140+ ref = '2'
141+ style = { styles . default }
142+ keyboardType = 'email-address'
143+ placeholder = 'blurOnSubmit = false'
144+ returnKeyType = 'next'
145+ blurOnSubmit = { false }
146+ onSubmitEditing = { ( ) => this . focusNextField ( '3' ) }
147+ />
148+ < TextInput
149+ ref = '3'
150+ style = { styles . default }
151+ keyboardType = 'url'
152+ placeholder = 'blurOnSubmit = false'
153+ returnKeyType = 'next'
154+ blurOnSubmit = { false }
155+ onSubmitEditing = { ( ) => this . focusNextField ( '4' ) }
156+ />
157+ < TextInput
158+ ref = '4'
159+ style = { styles . default }
160+ keyboardType = 'numeric'
161+ placeholder = 'blurOnSubmit = false'
162+ blurOnSubmit = { false }
163+ onSubmitEditing = { ( ) => this . focusNextField ( '5' ) }
164+ />
165+ < TextInput
166+ ref = '5'
167+ style = { styles . default }
168+ keyboardType = 'numbers-and-punctuation'
169+ placeholder = 'blurOnSubmit = true'
170+ returnKeyType = 'done'
171+ />
172+ </ View >
173+ ) ;
174+ }
175+ } ) ;
176+
123177var styles = StyleSheet . create ( {
124178 page : {
125179 paddingBottom : 300 ,
@@ -443,5 +497,9 @@ exports.examples = [
443497 </ View >
444498 ) ;
445499 }
446- }
500+ } ,
501+ {
502+ title : 'Blur on submit' ,
503+ render : function ( ) : ReactElement { return < BlurOnSubmitExample / > ; } ,
504+ } ,
447505] ;
Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ if (Platform.OS === 'android') {
4747 var RCTTextField = requireNativeComponent ( 'RCTTextField' , null ) ;
4848}
4949
50+ type DefaultProps = {
51+ blurOnSubmit : boolean ;
52+ } ;
53+
5054type Event = Object ;
5155
5256/**
@@ -283,6 +287,12 @@ var TextInput = React.createClass({
283287 * @platform ios
284288 */
285289 selectTextOnFocus : PropTypes . bool ,
290+ /**
291+ * If true, the text field will blur when submitted.
292+ * The default value is true.
293+ * @platform ios
294+ */
295+ blurOnSubmit : PropTypes . bool ,
286296 /**
287297 * Styles
288298 */
@@ -298,6 +308,12 @@ var TextInput = React.createClass({
298308 underlineColorAndroid : PropTypes . string ,
299309 } ,
300310
311+ getDefaultProps : function ( ) : DefaultProps {
312+ return {
313+ blurOnSubmit : true ,
314+ } ;
315+ } ,
316+
301317 /**
302318 * `NativeMethodsMixin` will look for this when invoking `setNativeProps`. We
303319 * make `this` look like an actual native component class.
Original file line number Diff line number Diff line change 1616@property (nonatomic , assign ) BOOL caretHidden;
1717@property (nonatomic , assign ) BOOL autoCorrect;
1818@property (nonatomic , assign ) BOOL selectTextOnFocus;
19+ @property (nonatomic , assign ) BOOL blurOnSubmit;
1920@property (nonatomic , assign ) UIEdgeInsets contentInset;
2021@property (nonatomic , strong ) UIColor *placeholderTextColor;
2122@property (nonatomic , assign ) NSInteger mostRecentEventCount;
2627
2728- (void )textFieldDidChange ;
2829- (void )sendKeyValueForString : (NSString *)string ;
30+ - (BOOL )textFieldShouldEndEditing : (RCTTextField *)textField ;
2931
3032@end
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ @implementation RCTTextField
2020 NSMutableArray <UIView *> *_reactSubviews;
2121 BOOL _jsRequestingFirstResponder;
2222 NSInteger _nativeEventCount;
23+ BOOL _submitted;
2324}
2425
2526- (instancetype )initWithEventDispatcher : (RCTEventDispatcher *)eventDispatcher
@@ -165,6 +166,7 @@ - (void)textFieldEndEditing
165166}
166167- (void )textFieldSubmitEditing
167168{
169+ _submitted = YES ;
168170 [_eventDispatcher sendTextEventWithType: RCTTextEventTypeSubmit
169171 reactTag: self .reactTag
170172 text: self .text
@@ -186,6 +188,15 @@ - (void)textFieldBeginEditing
186188 eventCount: _nativeEventCount];
187189}
188190
191+ - (BOOL )textFieldShouldEndEditing : (RCTTextField *)textField
192+ {
193+ if (_submitted) {
194+ _submitted = NO ;
195+ return _blurOnSubmit;
196+ }
197+ return YES ;
198+ }
199+
189200- (BOOL )becomeFirstResponder
190201{
191202 _jsRequestingFirstResponder = YES ;
Original file line number Diff line number Diff line change @@ -69,6 +69,11 @@ - (BOOL)keyboardInputShouldDelete:(RCTTextField *)textField
6969 return YES ;
7070}
7171
72+ - (BOOL )textFieldShouldEndEditing : (RCTTextField *)textField
73+ {
74+ return [textField textFieldShouldEndEditing: textField];
75+ }
76+
7277RCT_EXPORT_VIEW_PROPERTY (caretHidden, BOOL )
7378RCT_EXPORT_VIEW_PROPERTY(autoCorrect, BOOL )
7479RCT_REMAP_VIEW_PROPERTY(editable, enabled, BOOL )
@@ -79,6 +84,7 @@ - (BOOL)keyboardInputShouldDelete:(RCTTextField *)textField
7984RCT_EXPORT_VIEW_PROPERTY(clearButtonMode, UITextFieldViewMode)
8085RCT_REMAP_VIEW_PROPERTY(clearTextOnFocus, clearsOnBeginEditing, BOOL )
8186RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL )
87+ RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL )
8288RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType)
8389RCT_EXPORT_VIEW_PROPERTY(returnKeyType, UIReturnKeyType)
8490RCT_EXPORT_VIEW_PROPERTY(enablesReturnKeyAutomatically, BOOL )
You can’t perform that action at this time.
0 commit comments