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 a…
Browse files Browse the repository at this point in the history
…nd the toolbar of keyboard cover the input component when on bottom
  • Loading branch information
Sidney Li committed Jun 6, 2018
1 parent 78e1000 commit 6250566
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ -(void)focus
-(void)blur
{
if(self.view) {
[[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil];
[self.view resignFirstResponder];
}
}
Expand Down Expand Up @@ -658,15 +659,32 @@ - (void)setViewMovedUp:(BOOL)movedUp
CGRect rect = self.weexInstance.frame;
CGRect rootViewFrame = rootView.frame;
CGRect inputFrame = [self.view.superview convertRect:self.view.frame toView:rootView];
// WXRootView offset, iPhone X is 10, others is 20
CGFloat offsetY = 0.f;
// reset to the original y, iPhone X is 44, others is 20
CGFloat originY = 0.f;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
originY = screenSize.height == 812.0f ? 44 : 20;
offsetY = screenSize.height == 812.0f ? 10 : 20;
}
CGFloat offset = inputFrame.origin.y-(rootViewFrame.size.height-_keyboardSize.height-inputFrame.size.height - offsetY);
if (movedUp) {
CGFloat offset = inputFrame.origin.y-(rootViewFrame.size.height-_keyboardSize.height-inputFrame.size.height);
if (offset > 0) {
rect = (CGRect){
.origin.x = 0.f,
.origin.y = rect.origin.y - offset,
.size = rootViewFrame.size
};
}
} else {
if (offset > 0) {
rect = (CGRect){
.origin.x = 0.f,
.origin.y = originY,
.size = rootViewFrame.size
};
}
}
self.weexInstance.rootView.frame = rect;
}
Expand Down Expand Up @@ -910,6 +928,7 @@ - (void)keyboardWillHide:(NSNotification*)notification

- (void)closeKeyboard
{
[[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil];
[self.view resignFirstResponder];
}

Expand Down

0 comments on commit 6250566

Please sign in to comment.