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

Commit c7ce6dd

Browse files
author
Jonah Williams
authored
Apply translation to accessibility tree when in landscape (#5950)
1 parent aef94b7 commit c7ce6dd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

shell/platform/android/io/flutter/view/AccessibilityBridge.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package io.flutter.view;
66

7+
import android.app.Activity;
8+
import android.content.Context;
79
import android.graphics.Rect;
810
import android.opengl.Matrix;
911
import android.os.Build;
@@ -41,6 +43,8 @@ class AccessibilityBridge
4143
private SemanticsObject mHoveredObject;
4244
private int previousRouteId = ROOT_NODE_ID;
4345
private List<Integer> previousRoutes;
46+
private final View mDecorView;
47+
private Integer mLastLeftFrameInset = 0;
4448

4549
private final BasicMessageChannel<Object> mFlutterAccessibilityChannel;
4650

@@ -110,6 +114,7 @@ enum Flag {
110114
previousRoutes = new ArrayList<>();
111115
mFlutterAccessibilityChannel = new BasicMessageChannel<>(
112116
owner, "flutter/accessibility", StandardMessageCodec.INSTANCE);
117+
mDecorView = ((Activity) owner.getContext()).getWindow().getDecorView();
113118
}
114119

115120
void setAccessibilityEnabled(boolean accessibilityEnabled) {
@@ -620,6 +625,19 @@ void updateSemantics(ByteBuffer buffer, String[] strings) {
620625
if (rootObject != null) {
621626
final float[] identity = new float[16];
622627
Matrix.setIdentityM(identity, 0);
628+
// in android devices above AP 23, the system nav bar can be placed on the left side
629+
// of the screen in landscape mode. We must handle the translation ourselves for the
630+
// a11y nodes.
631+
if (Build.VERSION.SDK_INT >= 23) {
632+
Rect visibleFrame = new Rect();
633+
mDecorView.getWindowVisibleDisplayFrame(visibleFrame);
634+
if (!mLastLeftFrameInset.equals(visibleFrame.left)) {
635+
rootObject.globalGeometryDirty = true;
636+
rootObject.inverseTransformDirty = true;
637+
}
638+
mLastLeftFrameInset = visibleFrame.left;
639+
Matrix.translateM(identity, 0, visibleFrame.left, 0, 0);
640+
}
623641
rootObject.updateRecursively(identity, visitedObjects, false);
624642
rootObject.collectRoutes(newRoutes);
625643
}

0 commit comments

Comments
 (0)