You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2018/06/27 07:23:09 UTC

incubator-weex git commit: [WEEX-434][iOS] Fix the input cannot move down to original position. Also fix issue that keyboard covers part of input when there is no navigation bar.

Repository: incubator-weex
Updated Branches:
  refs/heads/master aa77c9fa5 -> 049d19f29


[WEEX-434][iOS]  Fix the input cannot move down to original position. Also fix issue that keyboard covers part of input when there is no navigation bar.


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/049d19f2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/049d19f2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/049d19f2

Branch: refs/heads/master
Commit: 049d19f29b918509b9f99514e444837b08bbf64f
Parents: aa77c9f
Author: 神漠 <qi...@alipay.com>
Authored: Wed Jun 27 13:36:35 2018 +0800
Committer: Adam Feng <cx...@gmail.com>
Committed: Wed Jun 27 15:23:01 2018 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/049d19f2/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
index d4f2488..b8b27c3 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
@@ -73,6 +73,9 @@
 // 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 @@ WX_EXPORT_METHOD(@selector(setTextFormatter:))
         _returnEvent = NO;
         _clickEvent = NO;
         _keyboardEvent = NO;
+        _keyboardHidden = YES;
         // handle attributes
         _autofocus = [attributes[@"autofocus"] boolValue];
         _disabled = [attributes[@"disabled"] boolValue];
@@ -220,6 +224,7 @@ WX_EXPORT_METHOD(@selector(setTextFormatter:))
 -(void)blur
 {
     if(self.view) {
+        [[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil];
         [self.view resignFirstResponder];
     }
 }
@@ -659,7 +664,7 @@ WX_EXPORT_METHOD(@selector(setTextFormatter:))
     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 @@ WX_EXPORT_METHOD(@selector(setTextFormatter:))
     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 @@ WX_EXPORT_METHOD(@selector(setTextFormatter:))
     if (_keyboardEvent) {
         [self fireEvent:@"keyboard" params:@{ @"isShow": @NO }];
     }
+    
+    _keyboardHidden = YES;
 }
 
 - (void)closeKeyboard
 {
+    [[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil];
     [self.view resignFirstResponder];
 }