Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@chunhtai
Copy link
Contributor

Description

We passed nil to layoutchange announcement when the previous focused node changes, which is correct that the ios should focus the first element on the screen. However, it seems like ios accessiblity api sometimes may take up to 10s+ to figure out what to focus next when there are frequent screen changes such as scrolling + semantics tree changes.

This PR finds the first element on the screen to focus instead of passing nil to reduce the lag.

Related Issues

Fixes flutter/flutter#64339

Tests

I added the following tests:

See files

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

// Tries to refocus the previous focused semantics object to avoid random jumps.
SemanticsObject* nextToFocus = [objects_.get() objectForKey:@(last_focused_semantics_object_id_)];
if (!nextToFocus)
nextToFocus = first_focusable_;
Copy link
Contributor Author

@chunhtai chunhtai Aug 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one thing that i am uncertain about this pr is that we giving up on letting iOS to pick which element to focus, which may be in contradiction with accessibility guide line.

@dnfield dnfield requested a review from gaaclarke August 21, 2020 23:07
@gaaclarke
Copy link
Member

I think the name of this PR could be more specific, "make x more robust" is pretty generic. =)

@chunhtai chunhtai changed the title Make IOS accessibility announcement more robust Avoid passing nil to IOS accessibility announcement Aug 21, 2020
NSMutableArray<NSNumber*>* doomed_uids) {
[doomed_uids removeObject:@(object.uid)];
void AccessibilityBridge::UpdateFirstFocusable(SemanticsObject* object) {
if (first_focusable_ || !object.isAccessibilityElement)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have the linter running on iOS code yet but can you please add the missing curly braces to match google style here and elsewhere.

first_focusable_ = object;
}

void AccessibilityBridge::WalkAndProccessTree(SemanticsObject* object) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function isn't clear what it does from its signature. Please consider a rename or a docstring.

I wouldn't conflate the removal of objects with the calculation of first_focusable_, the first_focusable_ search doesn't even need to traverse the whole tree. The code would be more clear if the functions kept to performing one task, so keep VisitObjectsRecursivelyAndRemove and add a SemanticsObject* FindFirstFocusable(SemanticsObject* object_tree).


NSMutableArray<NSNumber*>* doomed_uids = [NSMutableArray arrayWithArray:[objects_.get() allKeys]];
doomed_uids_ = [NSMutableArray arrayWithArray:[objects_.get() allKeys]];
first_focusable_ = nil;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take my suggestion below this line will be much more clear since there is a temporal dependency that first_focusable_ is set before the next part of the function, ex: first_focusable_ = FindFirstFocusable(objects_.get())

}

NSMutableArray<NSNumber*>* doomed_uids = [NSMutableArray arrayWithArray:[objects_.get() allKeys]];
doomed_uids_ = [NSMutableArray arrayWithArray:[objects_.get() allKeys]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you making doomed_uids an ivar? This is error prone, just pass it as an argument where it is needed here. Generally you should always be looking to do as much work as you can with the least amount of data on the heap. The more stateful your system is the harder it is to reason about. Most bugs come from stale state. =)

@gaaclarke
Copy link
Member

I think the approach is good, I just have some feedback on the details =) I remember seeing this and seeing the TODO and thinking we should look into it, thanks =)

@chunhtai
Copy link
Contributor Author

@gaaclarke thanks for review, I addressed all review comments. This pr is ready for another look.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I think this looks way better =)

@chunhtai chunhtai added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Aug 26, 2020
@fluttergithubbot fluttergithubbot merged commit 8308b6a into flutter:master Aug 26, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 26, 2020
tvolkert pushed a commit to flutter/flutter that referenced this pull request Aug 27, 2020
* b08c6b9 Fixing synthesizing keys for multiple keys pressed down on flutter web (flutter/engine#19632)

* 8308b6a Avoid passing nil to IOS accessibility announcement  (flutter/engine#20700)

* 950b6a0 Roll Skia from ead4ca052b99 to 5da7327358e3 (1 revision) (flutter/engine#20782)

* 87fd0e4 Guard recording_canvas against restore calls without ending recording (flutter/engine#20786)

* 388193a Add tests for lerpDouble (flutter/engine#20778)
smadey pushed a commit to smadey/flutter that referenced this pull request Aug 27, 2020
* b08c6b9 Fixing synthesizing keys for multiple keys pressed down on flutter web (flutter/engine#19632)

* 8308b6a Avoid passing nil to IOS accessibility announcement  (flutter/engine#20700)

* 950b6a0 Roll Skia from ead4ca052b99 to 5da7327358e3 (1 revision) (flutter/engine#20782)

* 87fd0e4 Guard recording_canvas against restore calls without ending recording (flutter/engine#20786)

* 388193a Add tests for lerpDouble (flutter/engine#20778)
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
* b08c6b9 Fixing synthesizing keys for multiple keys pressed down on flutter web (flutter/engine#19632)

* 8308b6a Avoid passing nil to IOS accessibility announcement  (flutter/engine#20700)

* 950b6a0 Roll Skia from ead4ca052b99 to 5da7327358e3 (1 revision) (flutter/engine#20782)

* 87fd0e4 Guard recording_canvas against restore calls without ending recording (flutter/engine#20786)

* 388193a Add tests for lerpDouble (flutter/engine#20778)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IOS focus stuck when semantic tree changes

4 participants