Closed
Conversation
chirag04
pushed a commit
that referenced
this pull request
Jan 25, 2016
Closed
ekrivopaltsev
pushed a commit
to ekrivopaltsev/react-native
that referenced
this pull request
Mar 25, 2016
Some keyboard types does not have buttons correspondent for keyReturnType such as Next, Done. It is observable on IPhone for numeric keyboard types. That prevents traversing forms with "number" input fields and impacts end-user experience. The improvement allows application for adding extra buttons via inputAccessoryView. Because RCTText is not a project exposed to React application calling all methods to add a handler is done using selectors. Here is a code fragment which has an example on how to achieve it: Within application: facebook#1 Create a keyboard Handle KeyboardAccessory keyboardHandler = ^UIView *(UITextField *textField) { ReactTextAdapter *kAdapter = [[ReactTextAdapter alloc] init:textField]; return [kAdapter getInputAccessory]; }; 2. Register an adapter Class clz = NSClassFromString(@"RCTTextField"); SEL selector = NSSelectorFromString(@"registerForKeyboardType:handler:"); if ([clz respondsToSelector:selector]) { [ clz performSelector:selector withObject:[NSNumber numberWithInt:UIKeyboardTypeNumberPad] withObject:keyboardHandler]; } facebook#3 Example of Keyboard Adapter @interface ReactTextAdapter :UIToolbar -(instancetype) init:(UITextField *)textField; -(UIView *)getInputAccessory; @EnD // // ReactTextAdapter.m // KeyboardTest // // Created by Krivopaltsev, Eugene on 3/11/16. // #import "ReactTextAdapter.h" @interface ReactTextAdapter() @Property (nonatomic) UITextField *textField; //@Property (nonatomic)UIToolbar *toolBar; @Property (nonatomic)UIBarButtonItem *flexible; @EnD @implementation ReactTextAdapter -(instancetype) init:(UITextField *)textField { self = [super init]; if (self) { self.textField = textField; [self setBarStyle:UIBarStyleDefault]; self.translatesAutoresizingMaskIntoConstraints = NO; self.flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; // since there is a next field, add a NEXT button to the picker if (self. textField. returnKeyType == UIReturnKeyNext) { NSString *nextText = @"Next"; UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:nextText style:UIBarButtonItemStyleDone target:self action:@selector(next)]; self.items = [[NSArray alloc] initWithObjects: self.flexible, nextButton, nil]; }else if (self.textField. returnKeyType == UIReturnKeyContinue) { NSString *continueText = @"Continue"; UIBarButtonItem *contButton = [[UIBarButtonItem alloc] initWithTitle:continueText style:UIBarButtonItemStyleDone target:self action:@selector(next)]; self.items = [[NSArray alloc] initWithObjects: self.flexible, contButton, nil]; } else if (self. textField.returnKeyType == UIReturnKeyDone) { NSString *doneText = @"Done"; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:doneText style:UIBarButtonItemStyleDone target:self action:@selector(done)]; doneButton.enabled = YES; self.items = [[NSArray alloc] initWithObjects: self.flexible, doneButton, nil]; } } return self; } -(void) done { [self passToReactNative]; [self.textField resignFirstResponder]; } -(void) next { [self passToReactNative]; } -(void) passToReactNative { SEL selector = @selector(textFieldSubmitEditing); if ([self.textField respondsToSelector:selector]) { [self.textField performSelector:selector withObject:nil]; } } -(UIView *)getInputAccessory { return self; }
ekrivopaltsev
pushed a commit
to ekrivopaltsev/react-native
that referenced
this pull request
Mar 25, 2016
Some keyboard types does not have buttons correspondent for keyReturnType such as Next, Done. It is observable on IPhone for numeric keyboard types. That prevents traversing forms with "number" input fields and impacts end-user experience. The improvement allows application for adding extra buttons via inputAccessoryView. Because RCTText is not a project exposed to React application calling all methods to add a handler is done using selectors. Here is a code fragment which has an example on how to achieve it: Within application: facebook#1 Create a keyboard Handle KeyboardAccessory keyboardHandler = ^UIView *(UITextField *textField) { ReactTextAdapter *kAdapter = [[ReactTextAdapter alloc] init:textField]; return [kAdapter getInputAccessory]; }; 2. Register an adapter Class clz = NSClassFromString(@"RCTTextField"); SEL selector = NSSelectorFromString(@"registerForKeyboardType:handler:"); if ([clz respondsToSelector:selector]) { [ clz performSelector:selector withObject:[NSNumber numberWithInt:UIKeyboardTypeNumberPad] withObject:keyboardHandler]; } facebook#3 Example of Keyboard Adapter @interface ReactTextAdapter :UIToolbar -(instancetype) init:(UITextField *)textField; -(UIView *)getInputAccessory; @EnD // // ReactTextAdapter.m // KeyboardTest // // Created by Krivopaltsev, Eugene on 3/11/16. // #import "ReactTextAdapter.h" @interface ReactTextAdapter() @Property (nonatomic) UITextField *textField; //@Property (nonatomic)UIToolbar *toolBar; @Property (nonatomic)UIBarButtonItem *flexible; @EnD @implementation ReactTextAdapter -(instancetype) init:(UITextField *)textField { self = [super init]; if (self) { self.textField = textField; [self setBarStyle:UIBarStyleDefault]; self.translatesAutoresizingMaskIntoConstraints = NO; self.flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; // since there is a next field, add a NEXT button to the picker if (self. textField. returnKeyType == UIReturnKeyNext) { NSString *nextText = @"Next"; UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:nextText style:UIBarButtonItemStyleDone target:self action:@selector(next)]; self.items = [[NSArray alloc] initWithObjects: self.flexible, nextButton, nil]; }else if (self.textField. returnKeyType == UIReturnKeyContinue) { NSString *continueText = @"Continue"; UIBarButtonItem *contButton = [[UIBarButtonItem alloc] initWithTitle:continueText style:UIBarButtonItemStyleDone target:self action:@selector(next)]; self.items = [[NSArray alloc] initWithObjects: self.flexible, contButton, nil]; } else if (self. textField.returnKeyType == UIReturnKeyDone) { NSString *doneText = @"Done"; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:doneText style:UIBarButtonItemStyleDone target:self action:@selector(done)]; doneButton.enabled = YES; self.items = [[NSArray alloc] initWithObjects: self.flexible, doneButton, nil]; } } return self; } -(void) done { [self passToReactNative]; [self.textField resignFirstResponder]; } -(void) next { [self passToReactNative]; } -(void) passToReactNative { SEL selector = @selector(textFieldSubmitEditing); if ([self.textField respondsToSelector:selector]) { [self.textField performSelector:selector withObject:nil]; } } -(UIView *)getInputAccessory { return self; }
Contributor
|
@robz updated the pull request. |
Closed
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.