Skip to content

Commit

Permalink
feat(ios): add onKeyboardWillHide callback for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg authored and zoomchan-cxj committed Mar 17, 2023
1 parent 78fa119 commit c363ab6
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 55 deletions.
4 changes: 2 additions & 2 deletions docs/en-us/hippy-react/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,13 @@ For more details, please refer to the Android development documentation.
| editable | If false, the text box is not editable. `default: true` | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer` |
| keyboardType | Determines which type of soft keyboard pops up. Note:`password` only takes effect in a single-line text box with the attribute `multiple=false`. | `enum (default, numeric, password, email, phone-pad)` | `Android、iOS、hippy-react-web、Web-Renderer` |
| maxLength | Limits the maximum number of characters in a text box. Use this property instead of Javascript to avoid flickering. | `number` | `Android、iOS、hippy-react-web、Web-Renderer` |
| multiline | If `true` , multiple lines of text can be entered in the text box. Due to native characteristics. | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer` |
| multiline | If `true` , multiple lines of text can be entered in the text box. | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer` |
| numberOfLines | Set the maximum number of lines displayed by `TextInput`. If `TextInput` does not explicitly set the height, it will calculate the height according to `numberOfLines` and expand. When using it, you must also set the `multiline` parameter to `true`. | `number` | `Android、hippy-react-web、Web-Renderer` |
| onBlur | This callback function is called when the text box is blurred. | `Function` | `Android、iOS、hippy-react-web、Web-Renderer` | |
| onFocus | This callback function is called when the text box is focused. | `Function` | `Android、iOS` |
| onChangeText | This callback function is called when the text box content changes. The changed text content is passed as a parameter. | `Function` | `Android、iOS、hippy-react-web、Web-Renderer` |
| onKeyboardWillShow | This callback function is called when the input method keyboard pops up. The return value contains the keyboard height`keyboardHeight`, style is as follow`{ keyboardHeight: 260 }`. | `Function` | `Android、iOS、hippy-react-web` |
| onKeyboardWillHide | This callback function is called when the input keyboard is hidden. | `Function` | `Android` |
| onKeyboardWillHide | This callback function is called when the input keyboard is hidden. `Supported from version 2.16.0 on iOS` | `Function` | `Android、iOS` |
| onEndEditing | This callback function is called when the text input ends. | `Function` | `Android、iOS、hippy-react-web、Web-Renderer` |
| onLayout | This callback function is called when the component is mounted or the layout changes. The parameter is `nativeEvent: { layout: { x, y, width, height } }`, where `x` and `y` are the coordinates relative to the parent element. | `Function` | `Android、iOS、hippy-react-web、Web-Renderer` |
| onSelectionChange | This callback function is called when the range of the selected text in the input box is changed, and the return parameter is in the form of `nativeEvent: { selection: { start, end } }`. | `Function` | `Android、iOS、Web-Renderer` |
Expand Down
2 changes: 1 addition & 1 deletion docs/en-us/hippy-vue/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ Please refer to the Android development documentation for details.
| focus | Called when the text box is focused. | `Function` | `Android、iOS` |
| change | Called when the contents of the text box change. The changed text is passed as a parameter. | `Function` | `Android、iOS、Web-Renderer` |
| keyboardWillShow | Called when the input keyboard pops-up, the return value contains the keyboard height `keyboardHeight`, style such as `{keyboardHeight: 260 }`| `Function` | `Android、iOS` |
| keyboardWillHide | Called when hiding input keyboard.| `Function` | `Android` |
| keyboardWillHide | Called when hiding input keyboard. `Supported from version 2.16.0 on iOS`| `Function` | `Android、iOS` |
| endEditing | Called when the text input is complete. | `Function` | `Android、iOS、Web-Renderer` |
| layout | Called when an element is mounted or the layout changes. The argument is: `nativeEvent: { layout: { x, y, width, height } }`, where `x` and `y` are coordinates relative to the parent element | `Function` | `Android、iOS、Web-Renderer` |
| selectionChange | Called when the range of the input box selection text is changed.The style of the return parameters such as `{nativeEvent: { selection: { start, end } } }` | `Function` | `Android、iOS、Web-Renderer` |
Expand Down
4 changes: 2 additions & 2 deletions docs/hippy-react/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,13 @@ import icon from './qb_icon_new.png';
| editable | 如果为 false,文本框是不可编辑的。 `default: true` | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer` |
| keyboardType | 决定弹出的何种软键盘的。 注意,`password`仅在属性 `multiline=false` 单行文本框时生效。 | `enum (default, numeric, password, email, phone-pad)` | `Android、iOS、hippy-react-web、Web-Renderer` |
| maxLength | 限制文本框中最多的字符数。使用这个属性而不用JS 逻辑去实现,可以避免闪烁的现象。 | `number` | `Android、iOS、hippy-react-web、Web-Renderer` |
| multiline | 如果为 `true` ,文本框中可以输入多行文字。 由于终端特性。 | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer` |
| multiline | 如果为 `true` ,文本框中可以输入多行文字。 | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer` |
| numberOfLines | 设置 `TextInput` 最大显示行数,如果 `TextInput` 没有显式设置高度,会根据 `numberOfLines` 来计算高度撑开。在使用的时候必需同时设置 `multiline` 参数为 `true`| `number` | `Android、hippy-react-web、Web-Renderer` |
| onBlur | 当文本框失去焦点的时候调用此回调函数。 | `Function` | `Android、iOS、hippy-react-web、Web-Renderer` |
| onFocus | 当文本框获得焦点的时候调用此回调函数。 | `Function` | `Android、iOS` |
| onChangeText | 当文本框内容变化时调用此回调函数。改变后的文字内容会作为参数传递。 | `Function` | `Android、iOS、hippy-react-web、Web-Renderer` |
| onKeyboardWillShow | 在弹出输入法键盘时候会触发此回调函数,返回值包含键盘高度 `keyboardHeight`,样式如 `{ keyboardHeight: 260 }`| `Function` | `Android、iOS、hippy-react-web` |
| onKeyboardWillHide | 在隐藏输入法键盘时候会触发此回调函数 | `Function` | `Android` |
| onKeyboardWillHide | 在隐藏输入法键盘时候会触发此回调函数 `iOS最低支持版本2.16.0` | `Function` | `Android、iOS` |
| onKeyboardHeightChanged | 在输入法键盘高度改变时触发此回调函数,返回值包含键盘高度 `keyboardHeight`,样式如 `{ keyboardHeight: 260 }`, `最低支持版本2.14.0`| `Function` | `iOS` |
| onEndEditing | 当文本输入结束后调用此回调函数。 | `Function` | `Android、iOS、hippy-react-web、Web-Renderer` |
| onLayout | 当组件挂载或者布局变化的时候调用,参数为`nativeEvent: { layout: { x, y, width, height } }`,其中 `x``y` 为相对父元素的坐标位置。 | `Function` | `Android、iOS、hippy-react-web、Web-Renderer` |
Expand Down
4 changes: 2 additions & 2 deletions docs/hippy-vue/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@
| focus | 当文本框获得焦点的时候调用此回调函数。 | `Function` | `Android、iOS` |
| change | 当文本框内容变化时调用此回调函数。改变后的文字内容会作为参数传递。 | `Function` | `Android、iOS` |
| keyboardWillShow | 在弹出输入法键盘时候会触发此回调函数,返回值包含键盘高度 `keyboardHeight`,样式如 `{ keyboardHeight: 260 }`| `Function` | `Android、iOS` |
| keyboardWillHide | 在隐藏输入法键盘时候会触发此回调函数 | `Function` | `Android` |
| keyboardHeightChanged | 在输入法键盘高度改变时触发此回调函数,返回值包含键盘高度 `keyboardHeight`,样式如 `{ keyboardHeight: 260 }`, `最低支持版本2.14.0`| `Function` | `iOS` |
| keyboardWillHide | 在隐藏输入法键盘时候会触发此回调函数 `iOS最低支持版本2.16.0` | `Function` | `Android、iOS` |
| keyboardHeightChanged | 在输入法键盘高度改变时触发此回调函数,返回值包含键盘高度 `keyboardHeight`,样式如 `{ keyboardHeight: 260 }`, `最低支持版本2.14.0`| `Function` | `iOS` |
| endEditing | 当文本输入结束后调用此回调函数。 | `Function` | `Android、iOS、Web-Renderer` |
| layout | 当元素挂载或者布局改变的时候调用,参数为: `nativeEvent: { layout: { x, y, width, height } }`,其中 `x``y` 为相对父元素的坐标位置。 | `Function` | `Android、iOS、Web-Renderer` |
| selectionChange | 当输入框选择文字的范围被改变时调用。返回参数的样式如 `{ nativeEvent: { selection: { start, end } } }`| `Function` | `Android、iOS、Web-Renderer` |
Expand Down
14 changes: 7 additions & 7 deletions ios/sdk/HippyLibrary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1229,17 +1229,17 @@
isa = PBXGroup;
children = (
F4C929B5291C9B4E0078351C /* HippyBaseTextInput.h */,
F4C929B6291C9B4E0078351C /* HippyTextView.mm */,
F4C929BC291C9B4E0078351C /* HippyBaseTextInput.m */,
F4C929BB291C9B4E0078351C /* HippyTextViewManager.h */,
F4C929B7291C9B4E0078351C /* HippyTextViewManager.mm */,
F4C929B8291C9B4E0078351C /* HippyTextField.h */,
F4C929BE291C9B4E0078351C /* HippyTextView.h */,
F4C929B6291C9B4E0078351C /* HippyTextView.mm */,
F4C929BD291C9B4E0078351C /* HippyShadowTextView.h */,
F4C929B9291C9B4E0078351C /* HippyShadowTextView.mm */,
F4C929B8291C9B4E0078351C /* HippyTextField.h */,
F4C929C0291C9B4E0078351C /* HippyTextField.m */,
F4C929BA291C9B4E0078351C /* HippyTextSelection.h */,
F4C929BB291C9B4E0078351C /* HippyTextViewManager.h */,
F4C929BC291C9B4E0078351C /* HippyBaseTextInput.m */,
F4C929BD291C9B4E0078351C /* HippyShadowTextView.h */,
F4C929BE291C9B4E0078351C /* HippyTextView.h */,
F4C929BF291C9B4E0078351C /* HippyTextSelection.m */,
F4C929C0291C9B4E0078351C /* HippyTextField.m */,
);
path = textinput;
sourceTree = "<group>";
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/component/textinput/HippyBaseTextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- (void)blur;
- (void)clearText;
- (void)keyboardWillShow:(NSNotification *)aNotification;
- (void)keyboardWillHide:(NSNotification *)aNotification;
- (void)keyboardHeightChanged:(NSNotification *)aNotification;

@end
3 changes: 3 additions & 0 deletions ios/sdk/component/textinput/HippyBaseTextInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ - (void)blur {
- (void)clearText {
// base method, should be override
}
- (void)keyboardWillHide:(NSNotification *)aNotification {
// base method, should be override
}
- (void)keyboardWillShow:(NSNotification *)aNotification {
// base method, should be override
}
Expand Down
9 changes: 2 additions & 7 deletions ios/sdk/component/textinput/HippyTextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,17 @@

@property (nonatomic, copy) HippyDirectEventBlock onChangeText;

// focus/blur
- (void)focus;
- (void)blur;
- (void)keyboardWillShow:(NSNotification *)aNotification;
- (void)keyboardHeightChanged:(NSNotification *)aNotification;

@property (nonatomic, copy) HippyDirectEventBlock onBlur;
@property (nonatomic, copy) HippyDirectEventBlock onFocus;
@property (nonatomic, copy) HippyDirectEventBlock onEndEditing;
@property (nonatomic, copy) HippyDirectEventBlock onKeyboardWillShow;
@property (nonatomic, copy) HippyDirectEventBlock onKeyboardWillHide;
@property (nonatomic, copy) HippyDirectEventBlock onKeyboardHeightChanged;

@property (nonatomic, copy) NSString *value;
@property (nonatomic, strong) NSNumber *fontSize;
@property (nonatomic, strong) NSString *defaultValue;
@property (nonatomic, copy) NSString *text;
@property (nonatomic, strong) UIColor *textColor;
- (void)clearText;

@end
7 changes: 7 additions & 0 deletions ios/sdk/component/textinput/HippyTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ - (void)keyboardWillShow:(NSNotification *)aNotification {
}
}

- (void)keyboardWillHide:(NSNotification *)aNotification {
[super keyboardWillHide:aNotification];
if (_onKeyboardWillHide) {
_onKeyboardWillHide(@{});
}
}

-(void)keyboardHeightChanged:(NSNotification *)aNotification {
[super keyboardHeightChanged:aNotification];
NSDictionary *userInfo = [aNotification userInfo];
Expand Down
6 changes: 1 addition & 5 deletions ios/sdk/component/textinput/HippyTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,8 @@
@property (nonatomic, copy) HippyDirectEventBlock onBlur;
@property (nonatomic, copy) HippyDirectEventBlock onFocus;
@property (nonatomic, copy) HippyDirectEventBlock onKeyboardWillShow;
@property (nonatomic, copy) HippyDirectEventBlock onKeyboardWillHide;
@property (nonatomic, copy) HippyDirectEventBlock onKeyboardHeightChanged;

- (void)focus;
- (void)blur;
- (void)keyboardWillShow:(NSNotification *)aNotification;
- (void)keyboardHeightChanged:(NSNotification *)aNotification;
- (void)clearText;
- (void)updateFrames;
@end
16 changes: 12 additions & 4 deletions ios/sdk/component/textinput/HippyTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ @implementation HippyTextView {
BOOL _viewDidCompleteInitialLayout;
}

//当键盘出现或改变时调用
#pragma mark - Keyboard Events

- (void)keyboardWillShow:(NSNotification *)aNotification {
[super keyboardWillShow:aNotification];
//获取键盘的高度
Expand All @@ -116,6 +117,13 @@ - (void)keyboardWillShow:(NSNotification *)aNotification {
}
}

- (void)keyboardWillHide:(NSNotification *)aNotification {
[super keyboardWillHide:aNotification];
if (_onKeyboardWillHide) {
_onKeyboardWillHide(@{});
}
}

- (void)keyboardHeightChanged:(NSNotification *)aNotification {
[super keyboardHeightChanged:aNotification];
NSDictionary *userInfo = [aNotification userInfo];
Expand All @@ -129,7 +137,6 @@ - (void)keyboardHeightChanged:(NSNotification *)aNotification {

- (instancetype)init {
if ((self = [super initWithFrame:CGRectZero])) {
// _contentInset = UIEdgeInsetsZero;
[self setContentInset:UIEdgeInsetsZero];
_placeholderTextColor = [self defaultPlaceholderTextColor];
_blurOnSubmit = NO;
Expand All @@ -146,9 +153,10 @@ - (instancetype)init {
_scrollView.scrollsToTop = NO;
[_scrollView addSubview:_textView];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldEditChanged:) name:UITextViewTextDidChangeNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(textFieldEditChanged:)
name:UITextViewTextDidChangeNotification
object:_textView];

[self addSubview:_scrollView];
}
return self;
Expand Down

0 comments on commit c363ab6

Please sign in to comment.