Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide a11y elements when resigning active #29566

Merged
merged 4 commits into from Nov 6, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -780,13 +780,15 @@ - (void)dealloc {

- (void)applicationBecameActive:(NSNotification*)notification {
TRACE_EVENT0("flutter", "applicationBecameActive");
self.view.accessibilityElementsHidden = NO;
if (_viewportMetrics.physical_width)
[self surfaceUpdated:YES];
[self goToApplicationLifecycle:@"AppLifecycleState.resumed"];
}

- (void)applicationWillResignActive:(NSNotification*)notification {
TRACE_EVENT0("flutter", "applicationWillResignActive");
self.view.accessibilityElementsHidden = YES;
[self goToApplicationLifecycle:@"AppLifecycleState.inactive"];
}

Expand Down
Expand Up @@ -124,6 +124,8 @@ - (void)handlePressEvent:(FlutterUIPressProxy*)press
- (void)scrollEvent:(UIPanGestureRecognizer*)recognizer;
- (void)updateViewportMetrics;
- (void)onUserSettingsChanged:(NSNotification*)notification;
- (void)applicationWillResignActive:(NSNotification*)notification;
- (void)applicationBecameActive:(NSNotification*)notification;
@end

@interface FlutterViewControllerTest : XCTestCase
Expand Down Expand Up @@ -746,6 +748,21 @@ - (void)testHideOverlay {
engine.viewController = nil;
}

- (void)testHideA11yElements {
FlutterDartProject* project = [[FlutterDartProject alloc] init];
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar" project:project];
[engine createShell:@"" libraryURI:@"" initialRoute:nil];
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
XCTAssertFalse(realVC.view.accessibilityElementsHidden, @"");
Copy link
Member

Choose a reason for hiding this comment

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

Posting the notifications directly instead of exposing the applicationWillResignActive: applicationBecameActive: API in the test worked for me:

  XCTAssertFalse(realVC.view.accessibilityElementsHidden);
  [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillResignActiveNotification object:nil];
  XCTAssertTrue(realVC.view.accessibilityElementsHidden);
  [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidBecomeActiveNotification object:nil];
  XCTAssertFalse(realVC.view.accessibilityElementsHidden);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with this. I think I was somehow not rebuilding the target correctly when I got failures on this locally. It's not failing now.

[realVC applicationWillResignActive:nil];
XCTAssertTrue(realVC.view.accessibilityElementsHidden, @"");
dnfield marked this conversation as resolved.
Show resolved Hide resolved
[realVC applicationBecameActive:nil];
XCTAssertFalse(realVC.view.accessibilityElementsHidden, @"");
engine.viewController = nil;
}

- (void)testNotifyLowMemory {
FlutterEnginePartialMock* mockEngine = [[FlutterEnginePartialMock alloc] init];
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:mockEngine
Expand Down