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

Commit

Permalink
[iOS] Add upriseOffset for edit component.
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor committed Dec 11, 2018
1 parent 654b398 commit 4f88492
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ios/sdk/WeexSDK/Sources/Component/WXEditComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#import "WXComponent+Layout.h"

@interface WXEditComponent()
{
CGFloat _upriseOffset; // additional space when edit is lifted by keyboard
}

//@property (nonatomic, strong) WXTextInputView *inputView;
@property (nonatomic, strong) WXDatePickerManager *datePickerManager;
Expand Down Expand Up @@ -108,6 +111,12 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict
_disabled = [attributes[@"disabled"] boolValue];
_value = [WXConvert NSString:attributes[@"value"]]?:@"";
_placeholderString = [WXConvert NSString:attributes[@"placeholder"]]?:@"";
_upriseOffset = 20; // 20 for better appearance

if (attributes[@"upriseOffset"]) {
_upriseOffset = [WXConvert CGFloat:attributes[@"upriseOffset"]];
}

if(attributes[@"type"]) {
_inputType = [WXConvert NSString:attributes[@"type"]];
_attr = attributes;
Expand Down Expand Up @@ -460,6 +469,9 @@ - (void)updateAttributes:(NSDictionary *)attributes
_rows = 2;
[self setRows:_rows];
}
if (attributes[@"upriseOffset"]) {
_upriseOffset = [WXConvert CGFloat:attributes[@"upriseOffset"]];
}
}

#pragma mark - upate styles
Expand Down Expand Up @@ -702,7 +714,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) + 20;
CGFloat offset = inputFrame.origin.y-(rootViewFrame.size.height-_keyboardSize.height-inputFrame.size.height) + _upriseOffset;
if (offset > 0) {
rect = (CGRect){
.origin.x = 0.f,
Expand Down

0 comments on commit 4f88492

Please sign in to comment.