Skip to content

Commit

Permalink
Apply translation to accessibility tree when in landscape (flutter#5950)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored Aug 7, 2018
1 parent aef94b7 commit c7ce6dd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.opengl.Matrix;
import android.os.Build;
Expand Down Expand Up @@ -41,6 +43,8 @@ class AccessibilityBridge
private SemanticsObject mHoveredObject;
private int previousRouteId = ROOT_NODE_ID;
private List<Integer> previousRoutes;
private final View mDecorView;
private Integer mLastLeftFrameInset = 0;

private final BasicMessageChannel<Object> mFlutterAccessibilityChannel;

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

void setAccessibilityEnabled(boolean accessibilityEnabled) {
Expand Down Expand Up @@ -620,6 +625,19 @@ void updateSemantics(ByteBuffer buffer, String[] strings) {
if (rootObject != null) {
final float[] identity = new float[16];
Matrix.setIdentityM(identity, 0);
// in android devices above AP 23, the system nav bar can be placed on the left side
// of the screen in landscape mode. We must handle the translation ourselves for the
// a11y nodes.
if (Build.VERSION.SDK_INT >= 23) {
Rect visibleFrame = new Rect();
mDecorView.getWindowVisibleDisplayFrame(visibleFrame);
if (!mLastLeftFrameInset.equals(visibleFrame.left)) {
rootObject.globalGeometryDirty = true;
rootObject.inverseTransformDirty = true;
}
mLastLeftFrameInset = visibleFrame.left;
Matrix.translateM(identity, 0, visibleFrame.left, 0, 0);
}
rootObject.updateRecursively(identity, visitedObjects, false);
rootObject.collectRoutes(newRoutes);
}
Expand Down

0 comments on commit c7ce6dd

Please sign in to comment.