[go: nahoru, domu]

Skip to content

Commit

Permalink
Support accessibility back gesture to pop route from view controller (#…
Browse files Browse the repository at this point in the history
…51241)

Adapted suggestion from flutter/flutter#74246 (comment) to pop the route if the view controller route if `accessibilityPerformEscape` is called at that level in the responder chain.

Ideally this could know if the route was successfully popped, and only then return `YES` (halting propagation through the responder chain).

I confirmed by editing https://docs.flutter.dev/cookbook/navigation/navigation-basics#interactive-example as a demo that that the two-finger scrub (move two fingers back and forth three times quickly, making a "z") navigates back to the last route, and that the [`SementicObject`](https://github.com/flutter/engine/blob/88882292c952d76069cee67d76acc0fbae51c749/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm#L763) scrub, which already worked, continued to work.

I'm not super familiar with this code, hopefully there aren't further gotchas I'm not thinking of.

Fixes flutter/flutter#74246

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
jmagman committed Mar 18, 2024
1 parent ad75e93 commit 016206d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,15 @@ - (int32_t)accessibilityFlags {
return flags;
}

- (BOOL)accessibilityPerformEscape {
FlutterMethodChannel* navigationChannel = [_engine.get() navigationChannel];
if (navigationChannel) {
[self popRoute];
return YES;
}
return NO;
}

+ (BOOL)accessibilityIsOnOffSwitchLabelsEnabled {
if (@available(iOS 13, *)) {
return UIAccessibilityIsOnOffSwitchLabelsEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,22 @@ - (void)testItReportsAccessibilityOnOffSwitchLabelsFlagSet {
XCTAssert((flags & (int32_t)flutter::AccessibilityFeatureFlag::kOnOffSwitchLabels) != 0);
}

- (void)testAccessibilityPerformEscapePopsRoute {
FlutterEngine* mockEngine = OCMPartialMock([[FlutterEngine alloc] init]);
[mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
id mockNavigationChannel = OCMClassMock([FlutterMethodChannel class]);
OCMStub([mockEngine navigationChannel]).andReturn(mockNavigationChannel);

FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:mockEngine
nibName:nil
bundle:nil];
XCTAssertTrue([viewController accessibilityPerformEscape]);

OCMVerify([mockNavigationChannel invokeMethod:@"popRoute" arguments:nil]);

[mockNavigationChannel stopMocking];
}

- (void)testPerformOrientationUpdateForcesOrientationChange {
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
currentOrientation:UIInterfaceOrientationLandscapeLeft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
0AC232F724BA71D300A85907 /* FlutterEngineTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterEngineTest.mm; sourceTree = "<group>"; };
0AC2330324BA71D300A85907 /* accessibility_bridge_test.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = accessibility_bridge_test.mm; sourceTree = "<group>"; };
0AC2330B24BA71D300A85907 /* FlutterTextInputPluginTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterTextInputPluginTest.mm; sourceTree = "<group>"; };
0AC2330F24BA71D300A85907 /* FlutterBinaryMessengerRelayTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterBinaryMessengerRelayTest.mm; sourceTree = "<group>"; };
0AC2331024BA71D300A85907 /* connection_collection_test.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = connection_collection_test.mm; sourceTree = "<group>"; };
0AC2331224BA71D300A85907 /* FlutterEnginePlatformViewTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterEnginePlatformViewTest.mm; sourceTree = "<group>"; };
0AC2331924BA71D300A85907 /* FlutterPluginAppLifeCycleDelegateTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterPluginAppLifeCycleDelegateTest.mm; sourceTree = "<group>"; };
Expand All @@ -72,7 +71,6 @@
3DD7D38C27D2B81000DA365C /* FlutterUndoManagerPluginTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterUndoManagerPluginTest.mm; sourceTree = "<group>"; };
689EC1E2281B30D3008FEB58 /* FlutterSpellCheckPluginTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterSpellCheckPluginTest.mm; sourceTree = "<group>"; };
68B6091227F62F990036AC78 /* VsyncWaiterIosTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VsyncWaiterIosTest.mm; sourceTree = "<group>"; };
73F12C22288F92FF00AFC3A6 /* FlutterViewControllerTest_mrc.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterViewControllerTest_mrc.mm; sourceTree = "<group>"; };
D2D361A52B234EAC0018964E /* FlutterMetalLayerTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterMetalLayerTest.mm; sourceTree = "<group>"; };
F7521D7226BB671E005F15C5 /* libios_test_flutter.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libios_test_flutter.dylib; path = "../../../../out/$(FLUTTER_ENGINE)/libios_test_flutter.dylib"; sourceTree = "<group>"; };
F7521D7526BB673E005F15C5 /* libocmock_shared.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libocmock_shared.dylib; path = "../../../../out/$(FLUTTER_ENGINE)/libocmock_shared.dylib"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -109,12 +107,10 @@
0AC232F724BA71D300A85907 /* FlutterEngineTest.mm */,
0AC2330324BA71D300A85907 /* accessibility_bridge_test.mm */,
0AC2330B24BA71D300A85907 /* FlutterTextInputPluginTest.mm */,
0AC2330F24BA71D300A85907 /* FlutterBinaryMessengerRelayTest.mm */,
0AC2331024BA71D300A85907 /* connection_collection_test.mm */,
0AC2331224BA71D300A85907 /* FlutterEnginePlatformViewTest.mm */,
0AC2331924BA71D300A85907 /* FlutterPluginAppLifeCycleDelegateTest.mm */,
0AC2332124BA71D300A85907 /* FlutterViewControllerTest.mm */,
73F12C22288F92FF00AFC3A6 /* FlutterViewControllerTest_mrc.mm */,
D2D361A52B234EAC0018964E /* FlutterMetalLayerTest.mm */,
);
name = Source;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FLUTTER_ENGINE[arch=x86_64]=ios_debug_sim_unopt
FLUTTER_ENGINE[arch=arm64]=ios_debug_sim_unopt_arm64
FLUTTER_ENGINE=ios_debug_sim_unopt
FLUTTER_ENGINE=ios_debug_sim_unopt_arm64

0 comments on commit 016206d

Please sign in to comment.