Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
Emmanuel Garcia committed Jun 21, 2022
commit e2b2b94571ec0e5c1c9a279ff181a2fde0390b66
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,18 @@ private void resize(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
(double) resizeArgs.get("width"),
(double) resizeArgs.get("height"));
try {
final PlatformViewBufferSize sz = handler.resize(resizeRequest);
if (sz == null) {
result.error("error", "Failed to resize the platform view", null);
} else {
final Map<String, Object> response = new HashMap<>();
response.put("width", (double) sz.width);
response.put("height", (double) sz.height);
result.success(response);
}
handler.resize(
resizeRequest,
(PlatformViewBufferSize bufferSize) -> {
if (bufferSize == null) {
result.error("error", "Failed to resize the platform view", null);
} else {
final Map<String, Object> response = new HashMap<>();
response.put("width", (double) bufferSize.width);
response.put("height", (double) bufferSize.height);
result.success(response);
}
});
} catch (IllegalStateException exception) {
result.error("error", detailedExceptionString(exception), null);
}
Expand Down Expand Up @@ -298,9 +301,11 @@ public interface PlatformViewsHandler {
* The Flutter application would like to resize an existing Android {@code View}.
*
* @param request The request to resize the platform view.
* @return The buffer size where the platform view pixels are written to.
* @param onComplete Once the resize is completed, this is the handler to notify the size of the
* platform view buffer.
*/
PlatformViewBufferSize resize(@NonNull PlatformViewResizeRequest request);
void resize(
@NonNull PlatformViewResizeRequest request, @NonNull PlatformViewBufferResized onComplete);

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

/** Allows to notify when a platform view buffer has been resized. */
public interface PlatformViewBufferResized {
void run(@Nullable PlatformViewBufferSize bufferSize);
}

/** The state of a touch event in Flutter within a platform view. */
public static class PlatformViewTouch {
/** The ID of the platform view as seen by the Flutter side. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
// Initialize the "last seen" text editing values to a non-null value.
private TextEditState mLastKnownFrameworkTextEditingState;

// When true following calls to createInputConnection will return the cached lastInputConnection
// if the input
// target is a platform view. See the comments on lockPlatformViewInputConnection for more
// details.
private boolean isInputConnectionLocked;

@SuppressLint("NewApi")
public TextInputPlugin(
@NonNull View view,
Expand Down Expand Up @@ -176,6 +182,34 @@ ImeSyncDeferringInsetsCallback getImeSyncCallback() {
return imeSyncCallback;
}

/**
* Use the current platform view input connection until unlockPlatformViewInputConnection is
* called.
*
* <p>The current input connection instance is cached and any following call to @{link
* createInputConnection} returns the cached connection until unlockPlatformViewInputConnection is
* called.
*
* <p>This is a no-op if the current input target isn't a platform view.
*
* <p>This is used to preserve an input connection when moving a platform view from one virtual
* display to another.
*/
public void lockPlatformViewInputConnection() {
if (inputTarget.type == InputTarget.Type.PLATFORM_VIEW) {
isInputConnectionLocked = true;
}
}

/**
* Unlocks the input connection.
*
* <p>See also: @{link lockPlatformViewInputConnection}.
*/
public void unlockPlatformViewInputConnection() {
isInputConnectionLocked = false;
}

/**
* Detaches the text input plugin from the platform views controller.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,16 @@ default void onFlutterViewDetached() {}
*
* <p>This hook only exists for rare cases where the plugin relies on the state of the input
* connection. This probably doesn't need to be implemented.
*
* <p>This method is deprecated, and will be removed in a future release.
*/
@SuppressLint("NewApi")
@Deprecated
default void onInputConnectionLocked() {}

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