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

Commit e314c3d

Browse files
author
Emmanuel Garcia
committed
refactor
1 parent 75a21bb commit e314c3d

File tree

7 files changed

+334
-85
lines changed

7 files changed

+334
-85
lines changed

shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,18 @@ private void resize(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
147147
(double) resizeArgs.get("width"),
148148
(double) resizeArgs.get("height"));
149149
try {
150-
final PlatformViewBufferSize sz = handler.resize(resizeRequest);
151-
if (sz == null) {
152-
result.error("error", "Failed to resize the platform view", null);
153-
} else {
154-
final Map<String, Object> response = new HashMap<>();
155-
response.put("width", (double) sz.width);
156-
response.put("height", (double) sz.height);
157-
result.success(response);
158-
}
150+
handler.resize(
151+
resizeRequest,
152+
(PlatformViewBufferSize bufferSize) -> {
153+
if (bufferSize == null) {
154+
result.error("error", "Failed to resize the platform view", null);
155+
} else {
156+
final Map<String, Object> response = new HashMap<>();
157+
response.put("width", (double) bufferSize.width);
158+
response.put("height", (double) bufferSize.height);
159+
result.success(response);
160+
}
161+
});
159162
} catch (IllegalStateException exception) {
160163
result.error("error", detailedExceptionString(exception), null);
161164
}
@@ -298,9 +301,11 @@ public interface PlatformViewsHandler {
298301
* The Flutter application would like to resize an existing Android {@code View}.
299302
*
300303
* @param request The request to resize the platform view.
301-
* @return The buffer size where the platform view pixels are written to.
304+
* @param onComplete Once the resize is completed, this is the handler to notify the size of the
305+
* platform view buffer.
302306
*/
303-
PlatformViewBufferSize resize(@NonNull PlatformViewResizeRequest request);
307+
void resize(
308+
@NonNull PlatformViewResizeRequest request, @NonNull PlatformViewBufferResized onComplete);
304309

305310
/**
306311
* The Flutter application would like to change the offset of an existing Android {@code View}.
@@ -418,6 +423,11 @@ public PlatformViewBufferSize(int width, int height) {
418423
}
419424
}
420425

426+
/** Allows to notify when a platform view buffer has been resized. */
427+
public interface PlatformViewBufferResized {
428+
void run(@Nullable PlatformViewBufferSize bufferSize);
429+
}
430+
421431
/** The state of a touch event in Flutter within a platform view. */
422432
public static class PlatformViewTouch {
423433
/** The ID of the platform view as seen by the Flutter side. */

shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
5454
// Initialize the "last seen" text editing values to a non-null value.
5555
private TextEditState mLastKnownFrameworkTextEditingState;
5656

57+
// When true following calls to createInputConnection will return the cached lastInputConnection
58+
// if the input
59+
// target is a platform view. See the comments on lockPlatformViewInputConnection for more
60+
// details.
61+
private boolean isInputConnectionLocked;
62+
5763
@SuppressLint("NewApi")
5864
public TextInputPlugin(
5965
@NonNull View view,
@@ -176,6 +182,34 @@ ImeSyncDeferringInsetsCallback getImeSyncCallback() {
176182
return imeSyncCallback;
177183
}
178184

185+
/**
186+
* Use the current platform view input connection until unlockPlatformViewInputConnection is
187+
* called.
188+
*
189+
* <p>The current input connection instance is cached and any following call to @{link
190+
* createInputConnection} returns the cached connection until unlockPlatformViewInputConnection is
191+
* called.
192+
*
193+
* <p>This is a no-op if the current input target isn't a platform view.
194+
*
195+
* <p>This is used to preserve an input connection when moving a platform view from one virtual
196+
* display to another.
197+
*/
198+
public void lockPlatformViewInputConnection() {
199+
if (inputTarget.type == InputTarget.Type.PLATFORM_VIEW) {
200+
isInputConnectionLocked = true;
201+
}
202+
}
203+
204+
/**
205+
* Unlocks the input connection.
206+
*
207+
* <p>See also: @{link lockPlatformViewInputConnection}.
208+
*/
209+
public void unlockPlatformViewInputConnection() {
210+
isInputConnectionLocked = false;
211+
}
212+
179213
/**
180214
* Detaches the text input plugin from the platform views controller.
181215
*

shell/platform/android/io/flutter/plugin/platform/PlatformView.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,16 @@ default void onFlutterViewDetached() {}
6666
*
6767
* <p>This hook only exists for rare cases where the plugin relies on the state of the input
6868
* connection. This probably doesn't need to be implemented.
69-
*
70-
* <p>This method is deprecated, and will be removed in a future release.
7169
*/
7270
@SuppressLint("NewApi")
73-
@Deprecated
7471
default void onInputConnectionLocked() {}
7572

7673
/**
7774
* Callback fired when the platform input connection has been unlocked.
7875
*
7976
* <p>This hook only exists for rare cases where the plugin relies on the state of the input
8077
* connection. This probably doesn't need to be implemented.
81-
*
82-
* <p>This method is deprecated, and will be removed in a future release.
8378
*/
8479
@SuppressLint("NewApi")
85-
@Deprecated
8680
default void onInputConnectionUnlocked() {}
8781
}

0 commit comments

Comments
 (0)