Skip to content
Draft
Show file tree
Hide file tree
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 @@ -75,8 +75,12 @@ public WindowInsetsAnimationCompat.BoundsCompat onStart(
@NonNull WindowInsetsAnimationCompat animation,
@NonNull WindowInsetsAnimationCompat.BoundsCompat bounds
) {
boolean showingKeyboard = ViewCompat.getRootWindowInsets(rootView).isVisible(WindowInsetsCompat.Type.ime());
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
if (insets == null) {
return super.onStart(animation, bounds);
}

boolean showingKeyboard = insets.isVisible(WindowInsetsCompat.Type.ime());
int imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
DisplayMetrics dm = activity.getResources().getDisplayMetrics();
final float density = dm.density;
Expand All @@ -85,27 +89,35 @@ public WindowInsetsAnimationCompat.BoundsCompat onStart(
possiblyResizeChildOfContent(showingKeyboard);
}

if (showingKeyboard) {
keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_SHOW, Math.round(imeHeight / density));
} else {
keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_HIDE, 0);
if (keyboardEventListener != null) {
if (showingKeyboard) {
keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_SHOW, Math.round(imeHeight / density));
} else {
keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_HIDE, 0);
}
}
return super.onStart(animation, bounds);
}

@Override
public void onEnd(@NonNull WindowInsetsAnimationCompat animation) {
super.onEnd(animation);
boolean showingKeyboard = ViewCompat.getRootWindowInsets(rootView).isVisible(WindowInsetsCompat.Type.ime());
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
if (insets == null || keyboardEventListener == null) {
return;
}

boolean showingKeyboard = insets.isVisible(WindowInsetsCompat.Type.ime());
int imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
DisplayMetrics dm = activity.getResources().getDisplayMetrics();
final float density = dm.density;

if (showingKeyboard) {
keyboardEventListener.onKeyboardEvent(EVENT_KB_DID_SHOW, Math.round(imeHeight / density));
} else {
keyboardEventListener.onKeyboardEvent(EVENT_KB_DID_HIDE, 0);
if (keyboardEventListener != null) {
if (showingKeyboard) {
keyboardEventListener.onKeyboardEvent(EVENT_KB_DID_SHOW, Math.round(imeHeight / density));
} else {
keyboardEventListener.onKeyboardEvent(EVENT_KB_DID_HIDE, 0);
}
}
}
}
Expand All @@ -115,6 +127,13 @@ public void onEnd(@NonNull WindowInsetsAnimationCompat animation) {
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}

public void destroy() {
if (rootView != null) {
ViewCompat.setWindowInsetsAnimationCallback(rootView, null);
rootView = null;
}
}

public void show() {
((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(activity.getCurrentFocus(), 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ void onKeyboardEvent(String event, int size) {

@Override
protected void handleOnDestroy() {
implementation.setKeyboardEventListener(null);
if (implementation != null) {
implementation.destroy();
implementation.setKeyboardEventListener(null);
}
}
}