Skip to content

Commit

Permalink
fixbug:兼容讯飞输入法动态皮肤导致自定义键盘无法弹出
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoliu committed Nov 14, 2018
1 parent d021569 commit aedd25a
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.inputmethod.InputMethodManager;

import android.widget.RelativeLayout;
Expand Down Expand Up @@ -37,6 +39,7 @@ public class RNCustomKeyboardModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;
public static ReactInstanceManager rnInstanceManager;

private String mDefaultInputMethodPkg;
private Method setShowSoftInputOnFocusMethod;
private Method setSoftInputShownOnFocusMethod;

Expand All @@ -49,6 +52,7 @@ public RNCustomKeyboardModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
initReflectMethod();
readDefaultInputMethodPkgName(reactContext);
}

private void initReflectMethod () {
Expand All @@ -67,6 +71,21 @@ private void initReflectMethod () {
}
}


private void readDefaultInputMethodPkgName(ReactApplicationContext context) {
if (context != null) {
String mDefaultInputMethodCls = Settings.Secure.getString(
context.getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD);
//输入法类名信息
if (!TextUtils.isEmpty(mDefaultInputMethodCls)) {
//输入法包名
mDefaultInputMethodPkg = mDefaultInputMethodCls.split("/")[0];
Log.d(TAG, "mDefaultInputMethodPkg=" + mDefaultInputMethodPkg);
}
}
}

private ReactEditText getEditById(int id) throws IllegalViewOperationException{
UIViewOperationQueue uii = this.getReactApplicationContext().getNativeModule(UIManagerModule.class).getUIImplementation().getUIViewOperationQueue();
return (ReactEditText) uii.getNativeViewHierarchyManager().resolveView(id);
Expand All @@ -77,7 +96,8 @@ private void showKeyboard (final Activity activity, final ReactEditText edit) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
// Log.i(TAG, "showKeyboard ------ resultCode=" + resultCode);
if (resultCode == InputMethodManager.RESULT_UNCHANGED_HIDDEN || resultCode == InputMethodManager.RESULT_HIDDEN) {
if ((resultCode == InputMethodManager.RESULT_UNCHANGED_HIDDEN || resultCode == InputMethodManager.RESULT_HIDDEN) ||
(resultCode == InputMethodManager.RESULT_UNCHANGED_SHOWN && "com.iflytek.inputmethod".equals(mDefaultInputMethodPkg))) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
Expand All @@ -92,6 +112,7 @@ public void run() {
}
};

// 这里必须延时一下,不然可能键盘无法正常关闭
mHandler.post(new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit aedd25a

Please sign in to comment.