iOS: A11y only disable during app resigning to background when voice over on (flutter/engine#32820)

This commit is contained in:
Chris Yang
2022-04-29 10:39:04 -07:00
committed by GitHub
parent acfe2ab302
commit f6ec59fccb
3 changed files with 44 additions and 1 deletions

View File

@@ -179,6 +179,14 @@ FLUTTER_DARWIN_EXPORT
*/
- (id<FlutterPluginRegistry>)pluginRegistry;
/**
* A wrapper around UIAccessibilityIsVoiceOverRunning().
*
* As a C function, UIAccessibilityIsVoiceOverRunning() cannot be mocked in testing. Mock
* this class method to testing features depends on UIAccessibilityIsVoiceOverRunning().
*/
+ (BOOL)isUIAccessibilityIsVoiceOverRunning;
/**
* True if at least one frame has rendered and the ViewController has appeared.
*

View File

@@ -826,7 +826,9 @@ static void SendFakeTouchEvent(FlutterEngine* engine,
- (void)applicationWillResignActive:(NSNotification*)notification {
TRACE_EVENT0("flutter", "applicationWillResignActive");
self.view.accessibilityElementsHidden = YES;
if ([FlutterViewController isUIAccessibilityIsVoiceOverRunning]) {
self.view.accessibilityElementsHidden = YES;
}
[self goToApplicationLifecycle:@"AppLifecycleState.inactive"];
}
@@ -1718,6 +1720,10 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch)
return _engine;
}
+ (BOOL)isUIAccessibilityIsVoiceOverRunning {
return UIAccessibilityIsVoiceOverRunning();
}
#pragma mark - FlutterPluginRegistry
- (NSObject<FlutterPluginRegistrar>*)registrarForPlugin:(NSString*)pluginKey {

View File

@@ -939,6 +939,9 @@ typedef enum UIAccessibilityContrast : NSInteger {
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
id flutterViewControllerClassMOCK = OCMClassMock([FlutterViewController class]);
[[[flutterViewControllerClassMOCK stub] andReturnValue:@YES] isUIAccessibilityIsVoiceOverRunning];
XCTAssertFalse(realVC.view.accessibilityElementsHidden);
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationWillResignActiveNotification
@@ -949,6 +952,32 @@ typedef enum UIAccessibilityContrast : NSInteger {
object:nil];
XCTAssertFalse(realVC.view.accessibilityElementsHidden);
engine.viewController = nil;
[flutterViewControllerClassMOCK stopMocking];
}
- (void)testDontHideA11yElementsWhenVoiceOverIsOff {
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];
id flutterViewControllerClassMOCK = OCMClassMock([FlutterViewController class]);
[[[flutterViewControllerClassMOCK stub] andReturnValue:@NO] isUIAccessibilityIsVoiceOverRunning];
XCTAssertFalse(realVC.view.accessibilityElementsHidden);
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationWillResignActiveNotification
object:nil];
XCTAssertFalse(realVC.view.accessibilityElementsHidden);
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationDidBecomeActiveNotification
object:nil];
XCTAssertFalse(realVC.view.accessibilityElementsHidden);
engine.viewController = nil;
[flutterViewControllerClassMOCK stopMocking];
}
- (void)testNotifyLowMemory {