Skip to content

Commit 368932b

Browse files
authored
Allow setting windowSoftInputMode (#1462)
* Allow setting windowSoftInputMode * Extract method
1 parent bc6e9ff commit 368932b

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class CustomKeyboardLayout implements ReactSoftKeyboardMonitor.Listener,
2424
private final InputMethodManager mInputMethodManager;
2525
private final ReactSoftKeyboardMonitor mKeyboardMonitor;
2626
private WeakReference<CustomKeyboardRootViewShadow> mShadowNode = new WeakReference<>(null);
27+
private int mSoftInputMode;
28+
private boolean mIsShown = false;
2729

2830
public CustomKeyboardLayout(ReactContext reactContext, ReactSoftKeyboardMonitor keyboardMonitor, ReactScreenMonitor screenMonitor) {
2931
mKeyboardMonitor = keyboardMonitor;
@@ -33,6 +35,18 @@ public CustomKeyboardLayout(ReactContext reactContext, ReactSoftKeyboardMonitor
3335
screenMonitor.addListener(this);
3436
}
3537

38+
public void setShown(boolean isShown) {
39+
mIsShown = isShown;
40+
Window window = getWindow();
41+
if (window != null) {
42+
if (mIsShown) {
43+
mSoftInputMode = window.getAttributes().softInputMode;
44+
} else {
45+
window.setSoftInputMode(mSoftInputMode);
46+
}
47+
}
48+
}
49+
3650
@Override
3751
public void onSoftKeyboardVisible(boolean distinct) {
3852
if (distinct) {
@@ -167,16 +181,19 @@ private int getHeightForCustomContent() {
167181
}
168182

169183
private void setKeyboardOverlayMode() {
170-
Window window = getWindow();
171-
if (window != null) {
172-
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
173-
}
184+
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
174185
}
175186

176187
private void clearKeyboardOverlayMode() {
177-
Window window = getWindow();
178-
if (window != null) {
179-
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
188+
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
189+
}
190+
191+
private void setSoftInputMode(int softInputMode) {
192+
if (mIsShown) {
193+
Window window = getWindow();
194+
if (window != null) {
195+
window.setSoftInputMode(softInputMode);
196+
}
180197
}
181198
}
182199

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,16 @@ public void onViewAdded(View child) {
2424
}
2525
super.onViewAdded(child);
2626
}
27+
28+
@Override
29+
protected void onAttachedToWindow() {
30+
super.onAttachedToWindow();
31+
mLayout.setShown(true);
32+
}
33+
34+
@Override
35+
protected void onDetachedFromWindow() {
36+
mLayout.setShown(false);
37+
super.onDetachedFromWindow();
38+
}
2739
}

0 commit comments

Comments
 (0)