Revert "Close connection on keyboard close (#41500)" (flutter/engine#49366)
Related issue: https://github.com/flutter/flutter/issues/140508
This commit is contained in:
@@ -367,14 +367,6 @@ public class TextInputChannel {
|
||||
"TextInputClient.performPrivateCommand", Arrays.asList(inputClientId, json));
|
||||
}
|
||||
|
||||
/** Instructs Flutter to execute a "onConnectionClosed" action. */
|
||||
public void onConnectionClosed(int inputClientId) {
|
||||
Log.v(TAG, "Sending 'onConnectionClosed' message.");
|
||||
channel.invokeMethod(
|
||||
"TextInputClient.onConnectionClosed",
|
||||
Arrays.asList(inputClientId, "TextInputClient.onConnectionClosed"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link TextInputMethodHandler} which receives all events and requests that are parsed
|
||||
* from the underlying platform channel.
|
||||
|
||||
@@ -14,8 +14,6 @@ import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import java.util.List;
|
||||
|
||||
// Loosely based off of
|
||||
@@ -43,9 +41,7 @@ import java.util.List;
|
||||
// a no-op. When onEnd indicates the end of the animation, the deferred call is
|
||||
// dispatched again, this time avoiding any flicker since the animation is now
|
||||
// complete.
|
||||
|
||||
// This class should have "package private" visibility cause it's called from TextInputPlugin.
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
||||
@VisibleForTesting
|
||||
@TargetApi(30)
|
||||
@RequiresApi(30)
|
||||
@SuppressLint({"NewApi", "Override"})
|
||||
@@ -56,7 +52,6 @@ class ImeSyncDeferringInsetsCallback {
|
||||
private WindowInsets lastWindowInsets;
|
||||
private AnimationCallback animationCallback;
|
||||
private InsetsListener insetsListener;
|
||||
private ImeVisibleListener imeVisibleListener;
|
||||
|
||||
// True when an animation that matches deferredInsetTypes is active.
|
||||
//
|
||||
@@ -94,11 +89,6 @@ class ImeSyncDeferringInsetsCallback {
|
||||
view.setOnApplyWindowInsetsListener(null);
|
||||
}
|
||||
|
||||
// Set a listener to be notified when the IME visibility changes.
|
||||
void setImeVisibleListener(ImeVisibleListener imeVisibleListener) {
|
||||
this.imeVisibleListener = imeVisibleListener;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
View.OnApplyWindowInsetsListener getInsetsListener() {
|
||||
return insetsListener;
|
||||
@@ -109,11 +99,6 @@ class ImeSyncDeferringInsetsCallback {
|
||||
return animationCallback;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ImeVisibleListener getImeVisibleListener() {
|
||||
return imeVisibleListener;
|
||||
}
|
||||
|
||||
// WindowInsetsAnimation.Callback was introduced in API level 30. The callback
|
||||
// subclass is separated into an inner class in order to avoid warnings from
|
||||
// the Android class loader on older platforms.
|
||||
@@ -131,20 +116,6 @@ class ImeSyncDeferringInsetsCallback {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public WindowInsetsAnimation.Bounds onStart(
|
||||
@NonNull WindowInsetsAnimation animation, @NonNull WindowInsetsAnimation.Bounds bounds) {
|
||||
// Observe changes to software keyboard visibility and notify listener when animation start.
|
||||
// See https://developer.android.com/develop/ui/views/layout/sw-keyboard.
|
||||
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(view);
|
||||
if (insets != null && imeVisibleListener != null) {
|
||||
boolean imeVisible = insets.isVisible(WindowInsetsCompat.Type.ime());
|
||||
imeVisibleListener.onImeVisibleChanged(imeVisible);
|
||||
}
|
||||
return super.onStart(animation, bounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindowInsets onProgress(
|
||||
WindowInsets insets, List<WindowInsetsAnimation> runningAnimations) {
|
||||
@@ -229,9 +200,4 @@ class ImeSyncDeferringInsetsCallback {
|
||||
return view.onApplyWindowInsets(windowInsets);
|
||||
}
|
||||
}
|
||||
|
||||
// Listener for IME visibility changes.
|
||||
public interface ImeVisibleListener {
|
||||
void onImeVisibleChanged(boolean visible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,17 +81,6 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
imeSyncCallback = new ImeSyncDeferringInsetsCallback(view);
|
||||
imeSyncCallback.install();
|
||||
|
||||
// When the IME is hidden, we need to notify the framework that close connection.
|
||||
imeSyncCallback.setImeVisibleListener(
|
||||
new ImeSyncDeferringInsetsCallback.ImeVisibleListener() {
|
||||
@Override
|
||||
public void onImeVisibleChanged(boolean visible) {
|
||||
if (!visible) {
|
||||
onConnectionClosed();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.textInputChannel = textInputChannel;
|
||||
@@ -844,8 +833,4 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
|
||||
textInputChannel.updateEditingStateWithTag(inputTarget.id, editingValues);
|
||||
}
|
||||
// -------- End: Autofill -------
|
||||
|
||||
public void onConnectionClosed() {
|
||||
textInputChannel.onConnectionClosed(inputTarget.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2367,19 +2367,6 @@ public class TextInputPluginTest {
|
||||
assertEquals(0, viewportMetricsCaptor.getValue().viewPaddingBottom);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TargetApi(30)
|
||||
@Config(sdk = 30)
|
||||
public void onConnectionClosed_imeInvisible() {
|
||||
View testView = new View(ctx);
|
||||
TextInputChannel textInputChannel = spy(new TextInputChannel(mock(DartExecutor.class)));
|
||||
TextInputPlugin textInputPlugin =
|
||||
new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class));
|
||||
ImeSyncDeferringInsetsCallback imeSyncCallback = textInputPlugin.getImeSyncCallback();
|
||||
imeSyncCallback.getImeVisibleListener().onImeVisibleChanged(false);
|
||||
verify(textInputChannel, times(1)).onConnectionClosed(anyInt());
|
||||
}
|
||||
|
||||
interface EventHandler {
|
||||
void sendAppPrivateCommand(View view, String action, Bundle data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user