Skip to content

Commit cc9f083

Browse files
committed
KeyboardInput - fix NPE in CustomKeyboardLayout (#1709)
* KeyboardInput - fix NPE in CustomKeyboardLayout * KeyboardInput - do not send promise if there is no acticity (cherry picked from commit 8c3327e)
1 parent b8d645f commit cc9f083

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/CustomKeyboardLayout.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.wix.reactnativeuilib.keyboardinput;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.view.View;
56
import android.view.Window;
@@ -89,14 +90,17 @@ public void forceReset(final Promise promise) {
8990
runOnUIThread(new Runnable() {
9091
@Override
9192
public void run() {
92-
final View focusedView = getCurrentActivity().getCurrentFocus();
93-
if (focusedView instanceof EditText) {
94-
showSoftKeyboard();
95-
} else {
96-
hideCustomKeyboardContent();
97-
clearKeyboardOverlayMode();
93+
Activity currentActivity = getCurrentActivity();
94+
if (currentActivity != null) {
95+
final View focusedView = currentActivity.getCurrentFocus();
96+
if (focusedView instanceof EditText) {
97+
showSoftKeyboard();
98+
} else {
99+
hideCustomKeyboardContent();
100+
clearKeyboardOverlayMode();
101+
}
102+
promise.resolve(null);
98103
}
99-
promise.resolve(null);
100104
}
101105
});
102106
}
@@ -105,9 +109,12 @@ public void clearFocusedView() {
105109
runOnUIThread(new Runnable() {
106110
@Override
107111
public void run() {
108-
final View focusedView = getCurrentActivity().getCurrentFocus();
109-
if (focusedView != null) {
110-
focusedView.clearFocus();
112+
Activity currentActivity = getCurrentActivity();
113+
if (currentActivity != null) {
114+
final View focusedView = currentActivity.getCurrentFocus();
115+
if (focusedView != null) {
116+
focusedView.clearFocus();
117+
}
111118
}
112119
}
113120
});

0 commit comments

Comments
 (0)