KEMBAR78
[Android] Prevent Picker from Gaining Focus on Touch by bhavanesh2001 · Pull Request #29068 · dotnet/maui · GitHub
Skip to content

Conversation

@bhavanesh2001
Copy link
Contributor

@bhavanesh2001 bhavanesh2001 commented Apr 17, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This PR brings Picker behavior on Android in line with DatePicker and TimePicker, in support of the enhancement described in #8945.

Currently, the Picker's platform control is focusable on touch, and a lot of custom logic has been implemented to make it work with this focus behavior. However, even with that logic, the platform control does not lose focus automatically when the dialog is dismissed — the Focus event fires, but the corresponding Unfocus event does not trigger when the dialog closes. This has led to some weird bugs.

In contrast, both DatePicker and TimePicker are not focusable on touch, so obviously, their Focused and Unfocused events do not fire.

This PR makes Picker behave the same way — by making it non-focusable on Touch, we avoid the current awkward focus lifecycle and ensure consistent behavior across all picker types, paving the way for future improvements with #8945.

CC @PureWeen

Supersedes #25319

Related to #8946
Related to #6252

Issues Fixed

Fixes #19739
Fixes #8546
Fixes #13503
Fixes #24862
Fixes #28121
Fixes #21704
Fixes #15394

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Apr 17, 2025
@bhavanesh2001 bhavanesh2001 marked this pull request as ready for review April 18, 2025 10:36
@bhavanesh2001 bhavanesh2001 requested a review from a team as a code owner April 18, 2025 10:36
@PureWeen
Copy link
Member

Making a note here that we need to validate keyboard interactions and TalkBack to make sure everything works as expected

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
@PureWeen PureWeen force-pushed the android_picker_cleanup branch from c30679d to eb3a4db Compare June 13, 2025 16:07
@PureWeen PureWeen added this to the .NET 9 SR9 milestone Jun 13, 2025
@PureWeen PureWeen added the p/0 Work that we can't release without label Jun 13, 2025
@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Jun 13, 2025
@PureWeen PureWeen removed the request for review from tj-devel709 June 13, 2025 16:47
@bhavanesh2001 bhavanesh2001 requested a review from PureWeen June 13, 2025 20:51
@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

We should make sure to maintain this behavior
#25319 (review)

using UITest.Appium;
using UITest.Core;

#if TEST_FAILS_ON_ANDROID
Copy link
Member

Choose a reason for hiding this comment

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

We will probably want to add some extra code to make sure this test still passes

Copy link
Contributor Author

@bhavanesh2001 bhavanesh2001 Jun 15, 2025

Choose a reason for hiding this comment

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

Although I think firing Focus/Unfocus events based on dialog show/dismiss is questionable, I wired up mappers for Focus() and Unfocus() calls to ensure they still work.

@github-project-automation github-project-automation bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Jun 14, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

{
}

protected override IMovementMethod? DefaultMovementMethod => null;
Copy link
Member

Choose a reason for hiding this comment

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

Can we comment the three places we are doing this with why we are doing this?

Indicate that according to the docs this MovementMethod is purely related to moving the cursor inside the box but since the text is readonly we remove it to avoid cursor related keyboard navigation?

@bhavanesh2001 bhavanesh2001 requested a review from PureWeen June 16, 2025 19:26
@bhavanesh2001 bhavanesh2001 requested a review from PureWeen June 16, 2025 20:09
@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Jun 18, 2025
@PureWeen PureWeen changed the base branch from main to inflight/current June 19, 2025 13:40
@PureWeen PureWeen merged commit 023c9ba into dotnet:inflight/current Jun 19, 2025
129 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Jun 19, 2025
PureWeen pushed a commit that referenced this pull request Jun 21, 2025
* make picker not focisable

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

* Address review comments

* set keylistner to null

* Make sure Focus()/Unfocus() works

* Address review comments

* Remove IsFocused Checks
PureWeen pushed a commit that referenced this pull request Jun 25, 2025
* make picker not focisable

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

* Address review comments

* set keylistner to null

* Make sure Focus()/Unfocus() works

* Address review comments

* Remove IsFocused Checks
PureWeen pushed a commit that referenced this pull request Jun 25, 2025
* make picker not focisable

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

* Address review comments

* set keylistner to null

* Make sure Focus()/Unfocus() works

* Address review comments

* Remove IsFocused Checks
github-actions bot pushed a commit that referenced this pull request Jun 26, 2025
* make picker not focisable

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

* Address review comments

* set keylistner to null

* Make sure Focus()/Unfocus() works

* Address review comments

* Remove IsFocused Checks
github-actions bot pushed a commit that referenced this pull request Jun 26, 2025
* make picker not focisable

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

* Address review comments

* set keylistner to null

* Make sure Focus()/Unfocus() works

* Address review comments

* Remove IsFocused Checks
PureWeen pushed a commit that referenced this pull request Jun 27, 2025
* make picker not focisable

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

* Address review comments

* set keylistner to null

* Make sure Focus()/Unfocus() works

* Address review comments

* Remove IsFocused Checks
github-actions bot pushed a commit that referenced this pull request Jun 27, 2025
* make picker not focisable

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

* Address review comments

* set keylistner to null

* Make sure Focus()/Unfocus() works

* Address review comments

* Remove IsFocused Checks
PureWeen pushed a commit that referenced this pull request Jun 27, 2025
* make picker not focisable

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

* Address review comments

* set keylistner to null

* Make sure Focus()/Unfocus() works

* Address review comments

* Remove IsFocused Checks
PureWeen added a commit that referenced this pull request Jun 28, 2025
For more information about inflight process check
https://github.com/dotnet/maui/wiki/Inflight-Branch-Process

# .NET MAUI Release Notes - Inflight/Candidate Branch

## What's Changed

### MAUI Product Fixes
* [iOS] CarouselView with CarouselViewHandler2 make app crash when
Loop="False" and user scroll to the last position - fixes #26863 by
@kubaflo in #26868
* Fixes Setting BackgroundColor to null does not actually changes
BackgroundColor - fixes #22914 and #19576 by @jgonzalez-gft in
#22917
* Fixed the picker title's color - fixes #16737 by @kubaflo in
#23075
* [android] Fallback to default icons in SearchHandler by @aheubusch in
#25067
* ScrollView's Background on iOS - fixes #24016 by @kubaflo in
#25541
* [iOS] Enabled MultiTouch Support for Handling Multi-Touch Points in
GraphicsView - fixes #29461 by @prakashKannanSf3972 in
#29895
* Optimize converters for GridLength, ColumnDefinition, and
RowDefinition - performance improvement by @emiller in
#20048
* Add defensive IsAlive check to Android ViewExtensions.OnUnloaded -
fixes #28051 by @jfversluis in #29934
* [Windows] Fixed runtime update issue for SearchBar PlaceholderColor
and BackgroundColor - fixes #29962 by @Tamilarasan-Paranthaman in
#29965
* Weak subscription to CanExecuteChange events - fixes #16124 by
@sneumaier in #29837
* [iOS, Mac] Fix for downsized image retaining original dimensions in
GraphicsView - fixes #30006 by @SyedAbdulAzeemSF4852 in
#30007
* [Android] Prevent Picker from Gaining Focus on Touch - fixes #19739,
#8546, #13503, #24862, #28121, #21704, #15394 by @bhavanesh2001 in
#29068
* Fix CV1 GridItemsLayout centering single item AND Fix Empty view not
resizing when bounds change - fixes #29595, #29634 by @albyrock87 in
#29639

### Testing
* [Testing] Feature Matrix UITest Cases for Button by @TamilarasanSF4853
in #29803
* [Testing] Feature matrix UITest Cases for BoxView Control by
@HarishKumarSF4517 in #29808
* [Testing] Enable HandlerDoesNotLeak for Button and ProgressBar by
@bhavanesh2001 in #29896
* [Testing] Add Validation Test For Issue28051 On Android by
@prakashKannanSf3972 in #30026
* [Testing] Fixed Test case failure in PR 30115 - [2025/06/23] Candidate
by @HarishKumarSF4517 in #30136

### Dependency Updates
* Bump to 1.7.250606001 of WindowsAppSDK by @sneumaier in
#29915

### Housekeeping
* [housekeeping] Update namespaces in HostApp and Shared tests projects
by @bhavanesh2001 in #29904
* Update SetterSpecificity.cs Remove Extra Line From Bad Merge by
@sneumaier in #29987
* Revert - Fixed the Label not sized correctly on Android by @Ahamed-Ali
in #30023
* Revert "Fixes Setting BackgroundColor to null does not actually
changes BackgroundColor #22914 (#22917)" by @mattleibow in
#30031
* [create-pull-request] automated change by @github-actions[bot] in
#30019
* [create-pull-request] automated change by @github-actions[bot] in
#30043
* [create-pull-request] automated change by @github-actions[bot] in
#30078
* Update Controls.TestCases.HostApp.csproj by @HarishKumarSF4517 in
#30124

## New Contributors
* @albyrock87 made their first contribution in
#29639
* @SyedAbdulAzeemSF4852 made their first contribution in
#30007
* @emiller made their first contribution in
#20048
* @jgonzalez-gft made their first contribution in
#22917
* @aheubusch made their first contribution in
#25067

**Full Changelog**:
https://github.com/dotnet/maui/compare/main..inflight/candidate
@github-actions github-actions bot locked and limited conversation to collaborators Jul 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.