Skip to content

[iOS] - Added Focus propagation to MauiView#31154

Merged
PureWeen merged 11 commits intodotnet:inflight/currentfrom
NirmalKumarYuvaraj:fix-28945_iOS
Oct 31, 2025
Merged

[iOS] - Added Focus propagation to MauiView#31154
PureWeen merged 11 commits intodotnet:inflight/currentfrom
NirmalKumarYuvaraj:fix-28945_iOS

Conversation

@NirmalKumarYuvaraj
Copy link
Contributor

@NirmalKumarYuvaraj NirmalKumarYuvaraj commented Aug 13, 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 pull request adds support for focus propagation to MauiView on 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

  • Added CanBecomeFirstResponder and CanBecomeFocused overrides to MauiView, allowing it to participate in the iOS focus system.
  • Implemented DidUpdateFocus in MauiView to propagate native iOS focus changes to the cross-platform IView.IsFocused property.

Public API Updates

  • Registered the new focus-related overrides for MauiView in PublicAPI.Unshipped.txt for both iOS and Mac Catalyst platforms. [1] [2]

Test Coverage

  • Added a new test case in TestCases.HostApp to validate focus/unfocus propagation in a custom ContentView.
  • Added a UI test in TestCases.Shared.Tests to 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 After
Before.mov
After.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 13, 2025
@dotnet-policy-service
Copy link
Contributor

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.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Aug 13, 2025
@NirmalKumarYuvaraj NirmalKumarYuvaraj marked this pull request as ready for review August 14, 2025 13:47
Copilot AI review requested due to automatic review settings August 14, 2025 13:47
@NirmalKumarYuvaraj NirmalKumarYuvaraj requested a review from a team as a code owner August 14, 2025 13:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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",
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

The AutomationId 'Issue28945_ContentView' should be unique across the entire test suite to prevent WaitForElement failures in automated tests.

Copilot uses AI. Check for mistakes.
UpdateKeyboardSubscription();
}

public override bool CanBecomeFirstResponder => true;
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@PureWeen , I have updated the test case. Please let me know if you have any concerns.

}

// https://developer.apple.com/documentation/xctest/xcuikeyboardkey?language=objc
string[] keys = ["XCUIKeyboardKeyTab"]; // Tab Key
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz , I have implemented the sendTabKey helper method. Please let me know if you have any concern.

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

rebase

@NirmalKumarYuvaraj
Copy link
Contributor Author

rebase

@PureWeen , Rebased.

@rmarinho
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

PureWeen commented Oct 9, 2025

/rebase

@PureWeen
Copy link
Member

PureWeen commented Oct 9, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen changed the base branch from net10.0 to inflight/current October 31, 2025 20:34
@PureWeen PureWeen merged commit 4e4c728 into dotnet:inflight/current Oct 31, 2025
114 of 163 checks passed
PureWeen pushed a commit that referenced this pull request Nov 11, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 11, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 14, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 15, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 15, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 20, 2025
* 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
github-actions bot pushed a commit that referenced this pull request Nov 20, 2025
* 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
@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 2025
@PureWeen PureWeen added the area-controls-general General issues that span multiple controls, or common base classes such as View or Element label Dec 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-general General issues that span multiple controls, or common base classes such as View or Element community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants