[iOS] - Added Focus propagation to MauiView#31154
[iOS] - Added Focus propagation to MauiView#31154PureWeen merged 11 commits intodotnet:inflight/currentfrom
Conversation
|
Hey there @@NirmalKumarYuvaraj! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds focus propagation support to MauiView on iOS, enabling native iOS focus changes to be properly reflected in the cross-platform layer. The implementation ensures that when a MauiView gains or loses focus through the iOS focus system, the corresponding IView.IsFocused property is updated accordingly.
- Implements focus system participation through CanBecomeFirstResponder and CanBecomeFocused overrides
- Adds DidUpdateFocus override to propagate native focus changes to the cross-platform IView.IsFocused property
- Includes comprehensive test coverage for focus/unfocus behavior validation
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Core/src/Platform/iOS/MauiView.cs | Implements focus propagation by adding CanBecomeFirstResponder, CanBecomeFocused, and DidUpdateFocus overrides |
| src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt | Registers new public API methods for iOS platform |
| src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | Registers new public API methods for Mac Catalyst platform |
| src/Controls/tests/TestCases.HostApp/Issues/Issue28945.cs | Creates test UI with focusable ContentView and focus toggle functionality |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28945.cs | Implements automated UI test to validate focus propagation behavior |
| Content = new Label | ||
| { | ||
| Text = "This is a focusable contentview, click the button to toggle focus", | ||
| AutomationId = "Issue28945_ContentView", |
There was a problem hiding this comment.
The AutomationId 'Issue28945_ContentView' should be unique across the entire test suite to prevent WaitForElement failures in automated tests.
| UpdateKeyboardSubscription(); | ||
| } | ||
|
|
||
| public override bool CanBecomeFirstResponder => true; |
There was a problem hiding this comment.
Don't set these ourselves
The main purpose of this pr is if someone enables these then we will properly propagate focused from the Mauiview to the xplat code
There was a problem hiding this comment.
@PureWeen , I have updated the test case. Please let me know if you have any concerns.
844751c to
4eab1b5
Compare
| } | ||
|
|
||
| // https://developer.apple.com/documentation/xctest/xcuikeyboardkey?language=objc | ||
| string[] keys = ["XCUIKeyboardKeyTab"]; // Tab Key |
There was a problem hiding this comment.
Could be nice to override the Catalyst implementation fo the SendKeys method to avoid specific platform code in future tests. We can do it in another separate PR. If we separate, could you create a related issue?
There was a problem hiding this comment.
@jsuarezruiz , I have implemented the sendTabKey helper method. Please let me know if you have any concern.
4eab1b5 to
5370200
Compare
@PureWeen , Rebased. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
c07a777 to
ebb8208
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
* Added Focus propagation to MauiView * minor changes * code changes * refactoring * Updated changes * modified script file * refactored * Modified test case * Modified Changes * more changes * Implement send tab keys helper # Conflicts: # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
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 pull request adds support for focus propagation to
MauiViewon iOS, ensuring that native focus changes are correctly reflected in the cross-platform layer. It introduces new API overrides, updates the iOS platform implementation, and adds corresponding test cases to validate the feature.iOS Platform Focus Propagation
CanBecomeFirstResponderandCanBecomeFocusedoverrides toMauiView, allowing it to participate in the iOS focus system.DidUpdateFocusinMauiViewto propagate native iOS focus changes to the cross-platformIView.IsFocusedproperty.Public API Updates
MauiViewinPublicAPI.Unshipped.txtfor both iOS and Mac Catalyst platforms. [1] [2]Test Coverage
TestCases.HostAppto validate focus/unfocus propagation in a customContentView.TestCases.Shared.Teststo verify that focus events are correctly handled and reflected in the UI.Note: DidUpdateFocus is called only on Mac when Tab key is pressed.
Issues Fixed
Fixes #28945
Output
Before.mov
After.mov