Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[useAnimatedKeyboard][Android] Filter keyboard events #5740

Merged
merged 9 commits into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class KeyboardAnimationCallback extends WindowInsetsAnimationCompat.Callback {
private final Keyboard mKeyboard;
private final NotifyAboutKeyboardChangeFunction mNotifyAboutKeyboardChange;
private static final int CONTENT_TYPE_MASK = WindowInsetsCompat.Type.ime();

public KeyboardAnimationCallback(
Keyboard keyboard, NotifyAboutKeyboardChangeFunction notifyAboutKeyboardChange) {
Expand All @@ -21,6 +22,9 @@ public KeyboardAnimationCallback(
public WindowInsetsAnimationCompat.BoundsCompat onStart(
@NonNull WindowInsetsAnimationCompat animation,
@NonNull WindowInsetsAnimationCompat.BoundsCompat bounds) {
if (!isKeyboardAnimation(animation)) {
return bounds;
}
mKeyboard.onAnimationStart();
mNotifyAboutKeyboardChange.call();
return super.onStart(animation, bounds);
Expand All @@ -31,14 +35,29 @@ public WindowInsetsAnimationCompat.BoundsCompat onStart(
public WindowInsetsCompat onProgress(
@NonNull WindowInsetsCompat insets,
@NonNull List<WindowInsetsAnimationCompat> runningAnimations) {
mKeyboard.updateHeight(insets);
mNotifyAboutKeyboardChange.call();
boolean isAnyKeyboardAnimationRunning = false;
for (WindowInsetsAnimationCompat animation : runningAnimations) {
if (isKeyboardAnimation(animation)) {
isAnyKeyboardAnimationRunning = true;
break;
}
}
if (isAnyKeyboardAnimationRunning) {
mKeyboard.updateHeight(insets);
mNotifyAboutKeyboardChange.call();
}
return insets;
}

@Override
public void onEnd(@NonNull WindowInsetsAnimationCompat animation) {
mKeyboard.onAnimationEnd();
mNotifyAboutKeyboardChange.call();
if (isKeyboardAnimation(animation)) {
mKeyboard.onAnimationEnd();
mNotifyAboutKeyboardChange.call();
}
}

private static boolean isKeyboardAnimation(@NonNull WindowInsetsAnimationCompat animation) {
return (animation.getTypeMask() & CONTENT_TYPE_MASK) != 0;
}
}
Loading