Skip to content

Commit eb5ff17

Browse files
feat: added support for keyboards with no animations
1 parent 8d0300e commit eb5ff17

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.Activity;
44
import android.view.View;
5+
import java.util.List;
56

67
import androidx.core.graphics.Insets;
78
import androidx.core.view.ViewCompat;
@@ -10,21 +11,48 @@
1011

1112
public class SoftInputAssist {
1213

14+
private boolean animationRunning = false;
15+
1316
public SoftInputAssist(Activity activity) {
1417
View contentView = activity.findViewById(android.R.id.content);
1518

19+
ViewCompat.setOnApplyWindowInsetsListener(contentView, (v, insets) -> {
20+
21+
if (!animationRunning) {
22+
Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime());
23+
Insets nav = insets.getInsets(WindowInsetsCompat.Type.navigationBars());
24+
25+
int keyboardHeight = Math.max(0, ime.bottom - nav.bottom);
26+
27+
v.setPadding(0, 0, 0, keyboardHeight);
28+
}
29+
30+
return insets;
31+
});
32+
1633
ViewCompat.setWindowInsetsAnimationCallback(
1734
contentView,
1835
new WindowInsetsAnimationCompat.Callback(
1936
WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE
2037
) {
38+
39+
@Override
40+
public void onPrepare(WindowInsetsAnimationCompat animation) {
41+
animationRunning = true;
42+
}
43+
44+
@Override
45+
public void onEnd(WindowInsetsAnimationCompat animation) {
46+
animationRunning = false;
47+
}
48+
2149
@Override
2250
public WindowInsetsCompat onProgress(
2351
WindowInsetsCompat insets,
24-
java.util.List<WindowInsetsAnimationCompat> runningAnimations) {
52+
List<WindowInsetsAnimationCompat> runningAnimations) {
2553

2654
Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime());
27-
Insets nav = insets.getInsets(WindowInsetsCompat.Type.systemBars());
55+
Insets nav = insets.getInsets(WindowInsetsCompat.Type.navigationBars());
2856

2957
int keyboardHeight = Math.max(0, ime.bottom - nav.bottom);
3058

0 commit comments

Comments
 (0)