Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Revert "[Android] Send connectionClosed message when keyboard becomes invisible to ensure framework focus state is correct." #41211

Merged
merged 1 commit into from
Apr 14, 2023
Merged
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 @@ -367,14 +367,6 @@ public void performPrivateCommand(
"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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
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
Expand Down Expand Up @@ -56,7 +54,6 @@ class ImeSyncDeferringInsetsCallback {
private WindowInsets lastWindowInsets;
private AnimationCallback animationCallback;
private InsetsListener insetsListener;
private ImeVisibleListener imeVisibleListener;

// True when an animation that matches deferredInsetTypes is active.
//
Expand Down Expand Up @@ -91,11 +88,6 @@ void remove() {
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;
Expand All @@ -106,11 +98,6 @@ WindowInsetsAnimation.Callback getAnimationCallback() {
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.
Expand All @@ -128,20 +115,6 @@ public void onPrepare(WindowInsetsAnimation animation) {
}
}

@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) {
Expand Down Expand Up @@ -226,9 +199,4 @@ public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
return view.onApplyWindowInsets(windowInsets);
}
}

// Listener for IME visibility changes.
public interface ImeVisibleListener {
void onImeVisibleChanged(boolean visible);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ public TextInputPlugin(
WindowInsets.Type.ime() // Deferred, insets that will animate
);
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;
Expand Down Expand Up @@ -849,8 +838,4 @@ public void autofill(@NonNull SparseArray<AutofillValue> values) {
textInputChannel.updateEditingStateWithTag(inputTarget.id, editingValues);
}
// -------- End: Autofill -------

public void onConnectionClosed() {
textInputChannel.onConnectionClosed(inputTarget.id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2118,19 +2118,6 @@ public void ime_windowInsetsSync() {
assertEquals(0, viewportMetricsCaptor.getValue().viewInsetTop);
}

@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);
}
Expand Down