Skip to content

Commit 1e77d1e

Browse files
duom青源duom青源
authored andcommitted
feat: fix android focus bug
1 parent 3d35104 commit 1e77d1e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

android/src/main/java/com/variabletextinput/VariableTextInputViewManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.variabletextinput;
2+
import android.util.Log;
23
import android.view.inputmethod.EditorInfo;
34
import android.widget.EditText;
45
import androidx.annotation.NonNull;
@@ -161,7 +162,7 @@ public void setKeyboardType(VariableTextInput view, String keyboardType) {
161162
@Override
162163
public Map<String, Integer> getCommandsMap() {
163164
Map<String,Integer> map = new HashMap<>();
164-
map.put(RNTONATIVEMETHOD.focus.name,0);
165+
map.put(RNTONATIVEMETHOD.focus.name,5);
165166
map.put(RNTONATIVEMETHOD.blur.name, 1);
166167
map.put(RNTONATIVEMETHOD.insertEmoji.name, 2);
167168
map.put(RNTONATIVEMETHOD.insertMentions.name, 3);
@@ -178,7 +179,7 @@ public Map<String, Integer> getCommandsMap() {
178179
public void receiveCommand(VariableTextInput root, int commandId, @Nullable ReadableArray args) {
179180

180181
switch (commandId){
181-
case 0:
182+
case 5:
182183
//focus打开键盘
183184
root.focus();
184185
break;

android/src/main/java/com/variabletextinput/view/VariableTextInput.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ previously we used setEnabled(false), but this would make text unselectable when
199199

200200
public void focus() {
201201
editText.requestFocus();
202+
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
203+
imm.showSoftInput(editText,InputMethodManager.SHOW_IMPLICIT);
202204
}
203205

204206
public void blur() {

0 commit comments

Comments
 (0)