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 all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Region;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
Expand Down Expand Up @@ -135,6 +136,28 @@ private void init() {
setAlpha(0.0f);
}

// This is a work around for TalkBack.
// If Android decides that our layer is transparent because, e.g. the status-
// bar is transparent, TalkBack highlighting stops working.
// Explicitly telling Android this part of the region is not actually
// transparent makes TalkBack work again.
// See https://github.com/flutter/flutter/issues/73413 for context.
@Override
public boolean gatherTransparentRegion(Region region) {
if (getAlpha() < 1.0f) {
return false;
}
final int[] location = new int[2];
getLocationInWindow(location);
region.op(
Copy link
Member

Choose a reason for hiding this comment

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

did you intend to read the output of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CL this was based on didn't use the return value. I'm not sure it's important here - I guess we could just return this value instead of returning true, but this op should always modify the region as long as the surface view is actually being used.

location[0],
location[1],
location[0] + getRight() - getLeft(),
location[1] + getBottom() - getTop(),
Region.Op.DIFFERENCE);
return true;
}

@Nullable
@Override
public FlutterRenderer getAttachedRenderer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.Region;
import android.media.Image;
import android.media.Image.Plane;
import android.media.ImageReader;
Expand Down Expand Up @@ -795,6 +796,20 @@ public void flutterImageView_onDrawClosesAllImages() {
verify(mockImage, times(2)).close();
}

@Test
public void flutterSurfaceView_GathersTransparentRegion() {
final Region mockRegion = mock(Region.class);
final FlutterSurfaceView surfaceView = new FlutterSurfaceView(RuntimeEnvironment.application);

surfaceView.setAlpha(0.0f);
assertFalse(surfaceView.gatherTransparentRegion(mockRegion));
verify(mockRegion, times(0)).op(anyInt(), anyInt(), anyInt(), anyInt(), any());

surfaceView.setAlpha(1.0f);
assertTrue(surfaceView.gatherTransparentRegion(mockRegion));
verify(mockRegion, times(1)).op(0, 0, 0, 0, Region.Op.DIFFERENCE);
}

/*
* A custom shadow that reports fullscreen flag for system UI visibility
*/
Expand Down