Skip to content

Add focus support for CupertinoActionSheetAction #166398 #167119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

O-Hannonen
Copy link
Contributor

This PR fixes #166398

  • Adds focus support for CupertinoActionSheetAction. This makes it work with keyboard shortcuts
  • Creates new widget, CupertinoTraversalGroup that applies a Cupertino style focus border around its child when any of its descendant has focus
  • Employs CupertinoTraversalGroup in CupertinoActionSheet

How the new implementation looks and behaves:
https://github.com/user-attachments/assets/ea6789f1-921d-4598-bcca-489dc063ff73

How the native counterpart looks and behaves:
https://github.com/user-attachments/assets/4c6ae2a0-7205-4de2-b981-ec7f4839da6e

Pre-launch Checklist

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus labels Apr 14, 2025
@dkwingsmt dkwingsmt self-requested a review April 23, 2025 18:10
@dkwingsmt
Copy link
Contributor

It'll take me some time to review but first I want to say that this is a fascinating change!

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

A first round of comments.

@dkwingsmt
Copy link
Contributor

Gave another round of review. My apology that the review was a bit delayed due to the chaos around the US holiday lately.

@O-Hannonen O-Hannonen requested a review from dkwingsmt June 11, 2025 08:18
@dkwingsmt
Copy link
Contributor

@/chunhtai is OOO until the end of the month, so we'll probably have to wait for him for further progress. Meanwhile I'll see if there's anything I can do.

@dkwingsmt dkwingsmt requested a review from justinmc July 16, 2025 18:12
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Some thoughts here. Thanks for jumping in here and adding focus support, I'm surprised more people haven't noticed this problem.

FYI there are conflicts on this PR that need to be fixed.

: _borderRadius = BorderRadius.zero;

/// {@macro flutter.cupertino.CupertinoFocusHalo}
const CupertinoFocusHalo.onRRect({
Copy link
Contributor

Choose a reason for hiding this comment

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

These names onRect and onRRect sound like they are meant to work with existing rectangles or rounded rectangles, but do they just decide to apply a border radius? It looks to me like a single constructor that takes an optional BorderRadius that defaults to BorderRadius.zero would be best here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related to this, @dkwingsmt any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I didn't see this comment! Sorry for the late reply.

I've talked with @justinmc offline and explained some design decisions I've proposed before for this PR. In short, I didn't want cornerRadius to appear on a unnamed constructor because it prioritizes RRects over other shapes (especially RSuperellipse, which will actually be the prominent one for Cupertino).

I also agree that onRRect isn't the most intuitive name and we can think of other options. I thought about rrect but the small letter may not be the correct grammar, as well as withRRect which might not fit the concept of halo very nicely. @justinmc agreed to think about naming with me.

@dkwingsmt
Copy link
Contributor

Hi! @O-Hannonen Are you able to address the comments above so we can work together to get this landed? This is a great addition and I'm looking forward to it!

@O-Hannonen O-Hannonen force-pushed the 166398-add-keyboard-focus-support-for-cupertino-action-sheet-action branch from ded01ef to 350cf22 Compare August 7, 2025 10:21
@O-Hannonen
Copy link
Contributor Author

Sorry for the delay due to holidays. @dkwingsmt fixed the other issues but the one regarding the constructors, as there were conflicting requests from reviewers.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM with nits, as long as the tests are fixed. This is a great all around fix considering the issue started out just being about keyboard traversal, thank you!

@chunhtai chunhtai self-requested a review August 19, 2025 22:21
@@ -1420,6 +1442,8 @@ class CupertinoActionSheetAction extends StatefulWidget {

class _CupertinoActionSheetActionState extends State<CupertinoActionSheetAction>
implements _SlideTarget {
bool _isFocused = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool _isFocused = false;
bool _showHighLight = false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO the original one that talks about focus is more descriptive in this context and also same wording is used in many other places, so keeping as is for now. Feel free to open discussion again if you strongly disagree

Copy link
Contributor

Choose a reason for hiding this comment

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

This property is set in _onShowFocusHighlight which means the code tries to infer has focus highlight -> is focused.

The property is then used to decide whether to draw the highlight.

I found it unnecessary to infer hashighlight to isfocused, and then infer it back to highlight in the build.

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM, just the naming comment

@@ -1420,6 +1442,8 @@ class CupertinoActionSheetAction extends StatefulWidget {

class _CupertinoActionSheetActionState extends State<CupertinoActionSheetAction>
implements _SlideTarget {
bool _isFocused = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This property is set in _onShowFocusHighlight which means the code tries to infer has focus highlight -> is focused.

The property is then used to decide whether to draw the highlight.

I found it unnecessary to infer hashighlight to isfocused, and then infer it back to highlight in the build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CupertinoActionSheetAction: Add keyboard support (Ipad, IOS)
4 participants