This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Bare-bones iOS FKA implementation #55964
Merged
auto-submit
merged 7 commits into
flutter:main
from
LongCatIsLooong:full-keyboard-access
Oct 24, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b67d0d5
A bare-bones implementation for iOS focus engine support, to enable b…
LongCatIsLooong ef0b99d
Merge remote-tracking branch 'upstream/main' into full-keyboard-access
LongCatIsLooong 28a21f7
licenses
LongCatIsLooong ced64ca
fix tests
LongCatIsLooong 3d55c09
Remove unnecessary code
LongCatIsLooong dcdea31
review
LongCatIsLooong 6ca023f
Make menu and dialogs reachable
LongCatIsLooong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
shell/platform/darwin/ios/framework/Source/SemanticsObject+UIFocusSystem.mm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "SemanticsObject.h" | ||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" | ||
|
||
FLUTTER_ASSERT_ARC | ||
|
||
// The SemanticsObject class conforms to UIFocusItem and UIFocusItemContainer | ||
// protocols, so the SemanticsObject tree can also be used to represent | ||
// interactive UI components on screen that can receive UIFocusSystem focus. | ||
// | ||
// Typically, physical key events received by the FlutterViewController is | ||
// first delivered to the framework, but that stopped working for navigation keys | ||
// since iOS 15 when full keyboard access (FKA) is on, because those events are | ||
// consumed by the UIFocusSystem and never dispatched to the UIResponders in the | ||
// application (see | ||
// https://developer.apple.com/documentation/uikit/uikeycommand/3780513-wantspriorityoversystembehavior | ||
// ). FKA relies on the iOS focus engine, to enable FKA on iOS 15+, we use | ||
// SemanticsObject to provide the iOS focus engine with the required hierarchical | ||
// information and geometric context. | ||
// | ||
// The focus engine focus is different from accessibility focus, or even the | ||
// currentFocus of the Flutter FocusManager in the framework. On iOS 15+, FKA | ||
// key events are dispatched to the current iOS focus engine focus (and | ||
// translated to calls such as -[NSObject accessibilityActivate]), while most | ||
// other key events are dispatched to the framework. | ||
@interface SemanticsObject (UIFocusSystem) <UIFocusItem, UIFocusItemContainer> | ||
@end | ||
|
||
@implementation SemanticsObject (UIFocusSystem) | ||
|
||
#pragma mark - UIFocusEnvironment Conformance | ||
|
||
- (void)setNeedsFocusUpdate { | ||
} | ||
|
||
- (void)updateFocusIfNeeded { | ||
} | ||
|
||
- (BOOL)shouldUpdateFocusInContext:(UIFocusUpdateContext*)context { | ||
return YES; | ||
} | ||
|
||
- (void)didUpdateFocusInContext:(UIFocusUpdateContext*)context | ||
withAnimationCoordinator:(UIFocusAnimationCoordinator*)coordinator { | ||
} | ||
|
||
- (id<UIFocusEnvironment>)parentFocusEnvironment { | ||
// The root SemanticsObject node's parent is the FlutterView. | ||
return self.parent ?: self.bridge->view(); | ||
} | ||
|
||
- (NSArray<id<UIFocusEnvironment>>*)preferredFocusEnvironments { | ||
return nil; | ||
} | ||
|
||
- (id<UIFocusItemContainer>)focusItemContainer { | ||
return self; | ||
} | ||
|
||
#pragma mark - UIFocusItem Conformance | ||
|
||
- (BOOL)canBecomeFocused { | ||
if ((self.node.flags & static_cast<int32_t>(flutter::SemanticsFlags::kIsHidden)) != 0) { | ||
return NO; | ||
} | ||
// Currently only supports SemanticsObjects that handle | ||
// -[NSObject accessibilityActivate]. | ||
return self.node.HasAction(flutter::SemanticsAction::kTap); | ||
} | ||
|
||
- (CGRect)frame { | ||
return self.accessibilityFrame; | ||
} | ||
|
||
#pragma mark - UIFocusItemContainer Conformance | ||
|
||
- (NSArray<id<UIFocusItem>>*)focusItemsInRect:(CGRect)rect { | ||
// It seems the iOS focus system relies heavily on focusItemsInRect | ||
// (instead of preferredFocusEnvironments) for directional navigation. | ||
// | ||
// The order of the items seems to be important, menus and dialogs become | ||
// unreachable via FKA if the returned children are organized | ||
// in hit-test order. | ||
// | ||
// This method is only supposed to return items within the given | ||
// rect but returning everything in the subtree seems to work fine. | ||
NSMutableArray<SemanticsObject*>* reversedItems = | ||
[[NSMutableArray alloc] initWithCapacity:self.childrenInHitTestOrder.count]; | ||
for (NSUInteger i = 0; i < self.childrenInHitTestOrder.count; ++i) { | ||
[reversedItems | ||
addObject:self.childrenInHitTestOrder[self.childrenInHitTestOrder.count - 1 - i]]; | ||
} | ||
return reversedItems; | ||
} | ||
|
||
- (id<UICoordinateSpace>)coordinateSpace { | ||
return self.bridge->view(); | ||
} | ||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning a reversed array seems very unintuitive, are you doing this just to make menus and dialogs reachable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's undocumented. I tested in an example app, popup menus couldn't be focused (instead the model barrier is the only thing focusable when a popup menu is present) if the items were in hit test order.