Skip to content

Commit

Permalink
feat(android,doc): returnKeyType,keyboardType not change singleLi…
Browse files Browse the repository at this point in the history
…ne (#3601)

* feat(android,doc): `returnKeyType`,`keyboardType` not change singleLine

* refactor(android): remove unnecessary comment

---------

Co-authored-by: siguangli <[email protected]>
  • Loading branch information
iPel and siguangli authored Nov 16, 2023
1 parent f4fcc99 commit fc6976c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/api/hippy-react/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ import icon from './qb_icon_new.png';
| onSelectionChange | 当输入框选择文字的范围被改变时调用。返回参数的样式如 `nativeEvent: { selection: { start, end } }`| `Function` | `Android、iOS、Web-Renderer、Voltron` |
| placeholder | 如果没有任何文字输入,会显示此字符串。 | `string` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| placeholderTextColor | 占位字符串显示的文字颜色。(也可设置为 Style 属性)`最低支持版本2.13.4` | [`color`](api/style/color.md) | `Android、iOS、Web-Renderer、Voltron` |
| returnKeyType | 指定软键盘的回车键显示的样式。 | `enum (done, go, next, search, send)` | `Android、iOS、Web-Renderer、Voltron` |
| returnKeyType | 指定软键盘的回车键显示的样式。(其中部分样式仅`multiline=false`时有效) | `enum (done, go, next, search, send)` | `Android、iOS、Web-Renderer、Voltron` |
| underlineColorAndroid | `TextInput` 下底线的颜色。 可以设置为 'transparent' 来去掉下底线。(也可设置为 Style 属性) | [`color`](api/style/color.md) | `Android` |
| value | 指定 `TextInput` 组件的值。 | `string` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
| autoFocus | 组件渲染时自动获得焦点。 | `boolean` | `Android、iOS、hippy-react-web、Web-Renderer、Voltron` |
Expand Down
2 changes: 1 addition & 1 deletion docs/api/hippy-vue/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
| placeholder | 如果没有任何文字输入,会显示此字符串。 | `string` | `Android、iOS、Web-Renderer、Voltron` |
| placeholder-text-color | 占位字符串显示的文字颜色。(也可设置为 Style 属性) `最低支持版本2.13.4` | [`color`](api/style/color.md) | `Android、iOS、Web-Renderer、Voltron` |
| underline-color-android | `input` 下底线的颜色。 可以设置为 'transparent' 来去掉下底线。(也可设置为 Style 属性) `最低支持版本2.13.4` | [`color`](api/style/color.md) | `Android` |
| returnKeyType | 指定软键盘的回车键显示的样式。 | `enum(done, go, next, search, send)` | `Android、iOS、Web-Renderer` |
| returnKeyType | 指定软键盘的回车键显示的样式。(其中部分样式仅对单行文本组件有效) | `enum(done, go, next, search, send)` | `Android、iOS、Web-Renderer` |
| value | 指定 `input` 组件的值。 | `string` | `Android、iOS、Web-Renderer、Voltron` |
| break-strategy* | 设置Android API 23及以上系统的文本换行策略。`default: simple` | `enum(simple, high_quality, balanced)` | `Android(版本 2.14.2以上)` |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
public class HippyTextInput extends AppCompatEditText implements HippyViewBase,
TextView.OnEditorActionListener, View.OnFocusChangeListener {

private static final String TAG = "HippyTextInput";
boolean mHasAddWatcher = false;
private String mPreviousText = "";
TextWatcher mTextWatcher = null;
Expand Down Expand Up @@ -272,7 +273,7 @@ private int getScreenHeight() {
}

} catch (SecurityException e) {
LogUtils.d("HippyTextInput", "getScreenHeight: " + e.getMessage());
LogUtils.d(TAG, "getScreenHeight: " + e.getMessage());
}
return -1;
}
Expand Down Expand Up @@ -616,12 +617,25 @@ public void setCursorColor(int color) {
}
break;
} catch (Throwable e) {
LogUtils.d("HippyTextInput", "setCursorColor: " + e.getMessage());
LogUtils.d(TAG, "setCursorColor: " + e.getMessage());
}
editorClass = editorClass.getSuperclass(); //继续往上反射父亲
}
} catch (Throwable e) {
LogUtils.d("HippyTextInput", "setCursorColor: " + e.getMessage());
LogUtils.d(TAG, "setCursorColor: " + e.getMessage());
}
}
}

public void refreshSoftInput() {
InputMethodManager imm = getInputMethodManager();
if (imm.isActive(this)) { // refresh the showing soft keyboard
try {
imm.hideSoftInputFromWindow(getWindowToken(), 0);
imm.restartInput(this);
imm.showSoftInput(this, 0, null);
} catch (Exception e) {
LogUtils.e(TAG, "refreshSoftInput error", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;

import android.view.inputmethod.InputMethodManager;
import androidx.annotation.NonNull;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -162,30 +163,26 @@ public void setReturnKeyType(HippyTextInput view, String returnKeyType) {
break;
case "next":
returnKeyFlag = EditorInfo.IME_ACTION_NEXT;
view.setSingleLine(true);
break;
case "none":
returnKeyFlag = EditorInfo.IME_ACTION_NONE;
break;
case "previous":
returnKeyFlag = EditorInfo.IME_ACTION_PREVIOUS;
view.setSingleLine(true);
break;
case "search":
returnKeyFlag = EditorInfo.IME_ACTION_SEARCH;
view.setSingleLine(true);
break;
case "send":
returnKeyFlag = EditorInfo.IME_ACTION_SEND;
view.setSingleLine(true);
break;
case "done":
returnKeyFlag = EditorInfo.IME_ACTION_DONE;
view.setSingleLine(true);
break;
}
}
view.setImeOptions(returnKeyFlag | EditorInfo.IME_FLAG_NO_FULLSCREEN);
view.refreshSoftInput();
}

@HippyControllerProps(name = "keyboardType", defaultType = HippyControllerProps.STRING)
Expand All @@ -201,8 +198,14 @@ public void setKeyboardType(HippyTextInput hippyTextInput, String keyboardType)
flagsToSet = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
hippyTextInput.setTransformationMethod(PasswordTransformationMethod.getInstance());
}

boolean multiline = (hippyTextInput.getInputType() & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0;
if (multiline) {
flagsToSet |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
} else {
flagsToSet &= ~InputType.TYPE_TEXT_FLAG_MULTI_LINE;
}
hippyTextInput.setInputType(flagsToSet);
hippyTextInput.refreshSoftInput();
}

private static int parseFontWeight(String fontWeightString) {
Expand Down

0 comments on commit fc6976c

Please sign in to comment.