wqyfavor closed pull request #1297: [WEEX-434][iOS] Fix the input cannot move down to original position.… URL: https://github.com/apache/incubator-weex/pull/1297
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm index d4f2488558..b8b27c312b 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm @@ -73,6 +73,9 @@ @interface WXEditComponent() // disable move rootView up as the keyboard show up. @property (nonatomic, assign) BOOL disableMoveViewUp; +// avoid keyboardWillHide executes twice +@property (nonatomic, assign) BOOL keyboardHidden; + @end @implementation WXEditComponent @@ -98,6 +101,7 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict _returnEvent = NO; _clickEvent = NO; _keyboardEvent = NO; + _keyboardHidden = YES; // handle attributes _autofocus = [attributes[@"autofocus"] boolValue]; _disabled = [attributes[@"disabled"] boolValue]; @@ -220,6 +224,7 @@ -(void)focus -(void)blur { if(self.view) { + [[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil]; [self.view resignFirstResponder]; } } @@ -659,7 +664,7 @@ - (void)setViewMovedUp:(BOOL)movedUp CGRect rootViewFrame = rootView.frame; CGRect inputFrame = [self.view.superview convertRect:self.view.frame toView:rootView]; if (movedUp) { - CGFloat offset = inputFrame.origin.y-(rootViewFrame.size.height-_keyboardSize.height-inputFrame.size.height); + CGFloat offset = inputFrame.origin.y-(rootViewFrame.size.height-_keyboardSize.height-inputFrame.size.height) + 20; if (offset > 0) { rect = (CGRect){ .origin.x = 0.f, @@ -889,11 +894,13 @@ - (void)keyboardWasShown:(NSNotification*)notification if (_keyboardEvent) { [self fireEvent:@"keyboard" params:@{ @"isShow": @YES }]; } + + _keyboardHidden = NO; } - (void)keyboardWillHide:(NSNotification*)notification { - if (![self.view isFirstResponder]) { + if (![self.view isFirstResponder] || _keyboardHidden) { return; } if (!_disableMoveViewUp) { @@ -906,10 +913,13 @@ - (void)keyboardWillHide:(NSNotification*)notification if (_keyboardEvent) { [self fireEvent:@"keyboard" params:@{ @"isShow": @NO }]; } + + _keyboardHidden = YES; } - (void)closeKeyboard { + [[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil]; [self.view resignFirstResponder]; } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services