Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[WEEX-434][iOS] Fix the input cannot move down to original position. …
Browse files Browse the repository at this point in the history
…Also fix issue that keyboard covers part of input when there is no navigation bar.
  • Loading branch information
神漠 authored and cxfeng1 committed Jun 27, 2018
1 parent aa77c9f commit 049d19f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -220,6 +224,7 @@ -(void)focus
-(void)blur
{
if(self.view) {
[[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil];
[self.view resignFirstResponder];
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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];
}

Expand Down

0 comments on commit 049d19f

Please sign in to comment.