Skip to content

Fix input mirroring in platform views when system language is RTL, and support is set in manifest.#183472

Merged
auto-submit[bot] merged 6 commits into
flutter:masterfrom
gmackall:fix_rtl_pv_input_mirror
Mar 11, 2026
Merged

Fix input mirroring in platform views when system language is RTL, and support is set in manifest.#183472
auto-submit[bot] merged 6 commits into
flutter:masterfrom
gmackall:fix_rtl_pv_input_mirror

Conversation

@gmackall

@gmackall gmackall commented Mar 10, 2026

Copy link
Copy Markdown
Member

Fixes #182823

We use a FrameLayout to wrap platform views. We construct new FrameLayout.LayoutParams and set them on the frame layout (here, and a couple of other places). Because we don't specify a gravity, it defaults to UNSPECIFIED_GRAVITY, which is Gravity.TOP | Gravity.START. When a developer indicates that their app supports RTL (right-to-left) layouts (e.g. arabic), and the system language is set to one with an RTL layout, START becomes right https://developer.android.com/reference/android/view/Gravity#getAbsoluteGravity(int,%20int), and the view ends up thinking it is positioned relative to the right of the screen, even though we are controlling the drawing and putting it on the left.

Because we are handling the drawing, and all that matters is that flutter knows where the view is, we can just statically set the horizontal gravity to be left. Then flutter knows where to find the view and deliver the tap to it, whether we are in an RTL or LTR layout.

@github-actions github-actions Bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Mar 10, 2026
final ViewGroup.LayoutParams viewWrapperLayoutParams = viewWrapper.getLayoutParams();
viewWrapperLayoutParams.width = physicalWidth;
viewWrapperLayoutParams.height = physicalHeight;
if (viewWrapperLayoutParams instanceof FrameLayout.LayoutParams) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of weird: the call to FrameLayout.getLayoutParams above returns a ViewGroup.LayoutParams, not a FrameLayout.LayoutParams. Then we immediately call our own setLayoutParams implementation:
https://github.com/flutter/flutter/blob/master/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java#L87
which takes a FrameLayout.LayoutParams, so we are always doing this cast which I am checking for. I could alternatively put this in the setLayoutParams method, but I'd prefer to keep the layout parameter configuration here in one place. But I acknowledge it looks weird... in my defense it's weird that android gives back a ViewGroup.LayoutParams in the first place...

@gmackall gmackall marked this pull request as ready for review March 10, 2026 22:19
@gmackall gmackall requested a review from a team as a code owner March 10, 2026 22:19
await flutterDriver.close();
});

test(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither taps delivered by flutterDriver or the nativeDriver extension repro the issue. Instead, this test requests the location of the blue box via flutter driver, and also requests pixel information, to calculate the location of the box and deliver a tab via adb to those physical coordinates.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue with input mirroring for platform views in RTL layouts by explicitly setting the gravity of FrameLayout.LayoutParams to Gravity.LEFT | Gravity.TOP. This prevents the default Gravity.START from being misinterpreted in RTL contexts. The changes are applied consistently across FlutterMutatorView, PlatformViewsController, and PlatformViewsController2. A new integration test is also added to verify the fix. The fix appears correct and well-tested. However, I found a compilation error in the new test application code that needs to be addressed.

@gmackall

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an input mirroring issue on platform views in RTL layouts. The changes involve explicitly setting the gravity to Gravity.LEFT | Gravity.TOP for FrameLayout.LayoutParams in FlutterMutatorView, PlatformViewsController, and PlatformViewsController2. This ensures platform views are positioned correctly regardless of layout direction. Additionally, an integration test has been added to verify the fix, which required enabling RTL support in the test application's manifest.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses an input mirroring issue on platform views in RTL layouts by explicitly setting the layout gravity to Gravity.LEFT | Gravity.TOP. The change is well-supported by a new integration test that accurately reproduces and verifies the fix. My only suggestion is to consider deduplicating the new gravity value to improve code maintainability.

@gmackall gmackall added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 11, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Mar 11, 2026
Merged via the queue into flutter:master with commit fec7a38 Mar 11, 2026
183 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 11, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Mar 12, 2026
flutter/flutter@3f400d7...9e36adb

2026-03-12 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from QD887D4OanteB7UKM... to jJbpv4J_tjW-wuKDq... (flutter/flutter#183584)
2026-03-12 matt.kosarek@canonical.com Adding the SatelliteWindowController interface to `_window.dart` (flutter/flutter#182903)
2026-03-12 engine-flutter-autoroll@skia.org Roll Skia from 0cab3e4ee34b to 46f41493ebf4 (17 revisions) (flutter/flutter#183553)
2026-03-12 engine-flutter-autoroll@skia.org Roll Dart SDK from 8531f7c2bdae to 59be21f25f2d (4 revisions) (flutter/flutter#183547)
2026-03-12 koji.wakamiya@gmail.com [ios][engine] Fix keyboard flicker when switching text fields (flutter/flutter#182661)
2026-03-11 34871572+gmackall@users.noreply.github.com Rename hcpp opt in flag to `enable-hcpp` (flutter/flutter#183151)
2026-03-11 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#183541)
2026-03-11 97480502+b-luk@users.noreply.github.com Re-enable gpu_test.dart for opengles, but disable specific tests in the file (flutter/flutter#183531)
2026-03-11 jacksongardner@google.com Use CLA-approved email and username for github workflow commits. (flutter/flutter#183540)
2026-03-11 okorohelijah@google.com [integration_test]UIScene Migration (flutter/flutter#182631)
2026-03-11 git@reb0.org ci: Run orchestrator for windows_arm_host_engine on Linux  (flutter/flutter#181075)
2026-03-11 mdebbar@google.com [web] Prevent Firefox auto-updates (flutter/flutter#183330)
2026-03-11 koji.wakamiya@gmail.com Add scrollCacheExtent to PageView (flutter/flutter#180411)
2026-03-11 danny@tuppeny.com Remove redundant VS Code code/tests (flutter/flutter#183506)
2026-03-11 danny@tuppeny.com Roll pub packages (flutter/flutter#183527)
2026-03-11 34871572+gmackall@users.noreply.github.com Reapply "Make HCPP upgrading work for vd/tlhc (#181024)" (#183310) (flutter/flutter#183360)
2026-03-11 victorsanniay@gmail.com Add awaits to dev/ callsites (flutter/flutter#183479)
2026-03-11 stuartmorgan@google.com Standardize review timeline guidance (flutter/flutter#183465)
2026-03-11 chingjun@google.com Rename ExecutionModelToString to ExecutionModelToStringName. (flutter/flutter#183461)
2026-03-11 34871572+gmackall@users.noreply.github.com Fix input mirroring in platform views when system language is RTL, and support is set in manifest. (flutter/flutter#183472)
2026-03-11 engine-flutter-autoroll@skia.org Roll Packages from ee460d6 to ecace66 (10 revisions) (flutter/flutter#183517)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
okorohelijah pushed a commit to okorohelijah/packages that referenced this pull request Mar 26, 2026
…r#11233)

flutter/flutter@3f400d7...9e36adb

2026-03-12 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from QD887D4OanteB7UKM... to jJbpv4J_tjW-wuKDq... (flutter/flutter#183584)
2026-03-12 matt.kosarek@canonical.com Adding the SatelliteWindowController interface to `_window.dart` (flutter/flutter#182903)
2026-03-12 engine-flutter-autoroll@skia.org Roll Skia from 0cab3e4ee34b to 46f41493ebf4 (17 revisions) (flutter/flutter#183553)
2026-03-12 engine-flutter-autoroll@skia.org Roll Dart SDK from 8531f7c2bdae to 59be21f25f2d (4 revisions) (flutter/flutter#183547)
2026-03-12 koji.wakamiya@gmail.com [ios][engine] Fix keyboard flicker when switching text fields (flutter/flutter#182661)
2026-03-11 34871572+gmackall@users.noreply.github.com Rename hcpp opt in flag to `enable-hcpp` (flutter/flutter#183151)
2026-03-11 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#183541)
2026-03-11 97480502+b-luk@users.noreply.github.com Re-enable gpu_test.dart for opengles, but disable specific tests in the file (flutter/flutter#183531)
2026-03-11 jacksongardner@google.com Use CLA-approved email and username for github workflow commits. (flutter/flutter#183540)
2026-03-11 okorohelijah@google.com [integration_test]UIScene Migration (flutter/flutter#182631)
2026-03-11 git@reb0.org ci: Run orchestrator for windows_arm_host_engine on Linux  (flutter/flutter#181075)
2026-03-11 mdebbar@google.com [web] Prevent Firefox auto-updates (flutter/flutter#183330)
2026-03-11 koji.wakamiya@gmail.com Add scrollCacheExtent to PageView (flutter/flutter#180411)
2026-03-11 danny@tuppeny.com Remove redundant VS Code code/tests (flutter/flutter#183506)
2026-03-11 danny@tuppeny.com Roll pub packages (flutter/flutter#183527)
2026-03-11 34871572+gmackall@users.noreply.github.com Reapply "Make HCPP upgrading work for vd/tlhc (#181024)" (#183310) (flutter/flutter#183360)
2026-03-11 victorsanniay@gmail.com Add awaits to dev/ callsites (flutter/flutter#183479)
2026-03-11 stuartmorgan@google.com Standardize review timeline guidance (flutter/flutter#183465)
2026-03-11 chingjun@google.com Rename ExecutionModelToString to ExecutionModelToStringName. (flutter/flutter#183461)
2026-03-11 34871572+gmackall@users.noreply.github.com Fix input mirroring in platform views when system language is RTL, and support is set in manifest. (flutter/flutter#183472)
2026-03-11 engine-flutter-autoroll@skia.org Roll Packages from ee460d6 to ecace66 (10 revisions) (flutter/flutter#183517)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
mboetger pushed a commit to mboetger/flutter that referenced this pull request Mar 26, 2026
…d support is set in manifest. (flutter#183472)

Fixes flutter#182823

We use a
[`FrameLayout`](https://developer.android.com/reference/android/widget/FrameLayout)
to [wrap platform
views](https://github.com/flutter/flutter/blob/master/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/mutatorsstack/FlutterMutatorView.java#L30).
We construct new `FrameLayout.LayoutParams` and set them on the frame
layout
([here](https://github.com/flutter/flutter/blob/758463261fabe1b37f2a4752bfc44a57e10c79b7/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/mutatorsstack/FlutterMutatorView.java#L107),
and a couple of other places). Because we don't specify a gravity, it
defaults to
[UNSPECIFIED_GRAVITY](https://developer.android.com/reference/android/widget/FrameLayout.LayoutParams#gravity),
which is `Gravity.TOP | Gravity.START`. When a developer indicates that
their app supports RTL (right-to-left) layouts (e.g. arabic), and the
system language is set to one with an RTL layout, START becomes left
https://developer.android.com/reference/android/view/Gravity#getAbsoluteGravity(int,%20int),
and the view ends up thinking it is positioned relative to the right of
the screen, even though we are controlling the drawing and putting it on
the left.

Because we are handling the drawing, and all that matters is that
flutter knows where the view is, we can just statically set the
horizontal gravity to be left. Then flutter knows where to find the view
and deliver the tap to it, whether we are in an RTL or LTR layout.

---------

Co-authored-by: Gray Mackall <mackall@google.com>
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
…d support is set in manifest. (flutter#183472)

Fixes flutter#182823

We use a
[`FrameLayout`](https://developer.android.com/reference/android/widget/FrameLayout)
to [wrap platform
views](https://github.com/flutter/flutter/blob/master/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/mutatorsstack/FlutterMutatorView.java#L30).
We construct new `FrameLayout.LayoutParams` and set them on the frame
layout
([here](https://github.com/flutter/flutter/blob/758463261fabe1b37f2a4752bfc44a57e10c79b7/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/mutatorsstack/FlutterMutatorView.java#L107),
and a couple of other places). Because we don't specify a gravity, it
defaults to
[UNSPECIFIED_GRAVITY](https://developer.android.com/reference/android/widget/FrameLayout.LayoutParams#gravity),
which is `Gravity.TOP | Gravity.START`. When a developer indicates that
their app supports RTL (right-to-left) layouts (e.g. arabic), and the
system language is set to one with an RTL layout, START becomes left
https://developer.android.com/reference/android/view/Gravity#getAbsoluteGravity(int,%20int),
and the view ends up thinking it is positioned relative to the right of
the screen, even though we are controlling the drawing and putting it on
the left.

Because we are handling the drawing, and all that matters is that
flutter knows where the view is, we can just statically set the
horizontal gravity to be left. Then flutter knows where to find the view
and deliver the tap to it, whether we are in an RTL or LTR layout.

---------

Co-authored-by: Gray Mackall <mackall@google.com>
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11233)

flutter/flutter@3f400d7...9e36adb

2026-03-12 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from QD887D4OanteB7UKM... to jJbpv4J_tjW-wuKDq... (flutter/flutter#183584)
2026-03-12 matt.kosarek@canonical.com Adding the SatelliteWindowController interface to `_window.dart` (flutter/flutter#182903)
2026-03-12 engine-flutter-autoroll@skia.org Roll Skia from 0cab3e4ee34b to 46f41493ebf4 (17 revisions) (flutter/flutter#183553)
2026-03-12 engine-flutter-autoroll@skia.org Roll Dart SDK from 8531f7c2bdae to 59be21f25f2d (4 revisions) (flutter/flutter#183547)
2026-03-12 koji.wakamiya@gmail.com [ios][engine] Fix keyboard flicker when switching text fields (flutter/flutter#182661)
2026-03-11 34871572+gmackall@users.noreply.github.com Rename hcpp opt in flag to `enable-hcpp` (flutter/flutter#183151)
2026-03-11 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#183541)
2026-03-11 97480502+b-luk@users.noreply.github.com Re-enable gpu_test.dart for opengles, but disable specific tests in the file (flutter/flutter#183531)
2026-03-11 jacksongardner@google.com Use CLA-approved email and username for github workflow commits. (flutter/flutter#183540)
2026-03-11 okorohelijah@google.com [integration_test]UIScene Migration (flutter/flutter#182631)
2026-03-11 git@reb0.org ci: Run orchestrator for windows_arm_host_engine on Linux  (flutter/flutter#181075)
2026-03-11 mdebbar@google.com [web] Prevent Firefox auto-updates (flutter/flutter#183330)
2026-03-11 koji.wakamiya@gmail.com Add scrollCacheExtent to PageView (flutter/flutter#180411)
2026-03-11 danny@tuppeny.com Remove redundant VS Code code/tests (flutter/flutter#183506)
2026-03-11 danny@tuppeny.com Roll pub packages (flutter/flutter#183527)
2026-03-11 34871572+gmackall@users.noreply.github.com Reapply "Make HCPP upgrading work for vd/tlhc (#181024)" (#183310) (flutter/flutter#183360)
2026-03-11 victorsanniay@gmail.com Add awaits to dev/ callsites (flutter/flutter#183479)
2026-03-11 stuartmorgan@google.com Standardize review timeline guidance (flutter/flutter#183465)
2026-03-11 chingjun@google.com Rename ExecutionModelToString to ExecutionModelToStringName. (flutter/flutter#183461)
2026-03-11 34871572+gmackall@users.noreply.github.com Fix input mirroring in platform views when system language is RTL, and support is set in manifest. (flutter/flutter#183472)
2026-03-11 engine-flutter-autoroll@skia.org Roll Packages from ee460d6 to ecace66 (10 revisions) (flutter/flutter#183517)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] PlatformView pointer events (tap & drag) are horizontally mirrored in RTL mode

3 participants