From f2c245f93e70d548472935d0914944324a5cd64d Mon Sep 17 00:00:00 2001 From: Victoria Ashworth <15619084+vashworth@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:05:13 -0500 Subject: [PATCH] Remove UIAccessibilityTraitKeyboardKey to fix touch typing (flutter/engine#52333) `UIAccessibilityTraitKeyboardKey` was added in https://github.com/flutter/engine/pull/4575 so that `TextInputSemanticsObject` supported VoiceOver gestures for text editing features, such as pinch to select text, and up/down fling to move cursor. After experimenting with it, I found that those features were still available even after removing `UIAccessibilityTraitKeyboardKey`. Fixes https://github.com/flutter/flutter/issues/94465. In Touch Typing Mode: https://github.com/flutter/engine/assets/15619084/ccfe90ff-d3bc-427b-b1aa-9ec1242c0c89 In Standard Typing Mode: https://github.com/flutter/engine/assets/15619084/c78b1fb0-0816-41fb-9dd5-ed8b8a4cda2d [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../ios/framework/Source/SemanticsObjectTest.mm | 16 ++++++++++++++++ .../framework/Source/accessibility_text_entry.mm | 8 ++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm index 02430aad16b..45285d7cc41 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm @@ -10,6 +10,7 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTouchInterceptingView_Test.h" #import "flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h" #import "flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTestMocks.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h" FLUTTER_ASSERT_ARC @@ -1008,4 +1009,19 @@ FLUTTER_ASSERT_ARC XCTAssertNil(weakPlatformView); } +- (void)testTextInputSemanticsObject { + fml::WeakPtrFactory factory( + new flutter::testing::MockAccessibilityBridge()); + fml::WeakPtr bridge = factory.GetWeakPtr(); + + flutter::SemanticsNode node; + node.label = "foo"; + node.flags = static_cast(flutter::SemanticsFlags::kIsTextField) | + static_cast(flutter::SemanticsFlags::kIsReadOnly); + TextInputSemanticsObject* object = [[TextInputSemanticsObject alloc] initWithBridge:bridge uid:0]; + [object setSemanticsNode:&node]; + [object accessibilityBridgeDidFinishUpdate]; + XCTAssertEqual([object accessibilityTraits], UIAccessibilityTraitNone); +} + @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm index 92820ea8e52..878f61b9780 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm @@ -304,12 +304,8 @@ static const UIAccessibilityTraits kUIAccessibilityTraitUndocumentedEmptyLine = if (![self isAccessibilityBridgeAlive]) { return 0; } - // Adding UIAccessibilityTraitKeyboardKey to the trait list so that iOS treats it like - // a keyboard entry control, thus adding support for text editing features, such as - // pinch to select text, and up/down fling to move cursor. - UIAccessibilityTraits results = [super accessibilityTraits] | - [self textInputSurrogate].accessibilityTraits | - UIAccessibilityTraitKeyboardKey; + UIAccessibilityTraits results = + [super accessibilityTraits] | [self textInputSurrogate].accessibilityTraits; // We remove an undocumented flag to get rid of a bug where single-tapping // a text input field incorrectly says "empty line". // See also: https://github.com/flutter/flutter/issues/52487