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 1 commit
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 @@ -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
Original file line number Diff line number Diff line change
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, @"");
[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