Skip to content

[iOS] Fix SearchBar unexpected left margin in iPad windowed mode on 26 Version#34704

Merged
kubaflo merged 7 commits intodotnet:inflight/currentfrom
SubhikshaSf4851:Fix-34551
Apr 27, 2026
Merged

[iOS] Fix SearchBar unexpected left margin in iPad windowed mode on 26 Version#34704
kubaflo merged 7 commits intodotnet:inflight/currentfrom
SubhikshaSf4851:Fix-34551

Conversation

@SubhikshaSf4851
Copy link
Copy Markdown
Contributor

@SubhikshaSf4851 SubhikshaSf4851 commented Mar 27, 2026

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 whether this change resolves your issue. Thank you!

Root Cause :

iPadOS 26 windowed mode introduces a left safe-area inset (due to traffic light buttons). UISearchBar applies this via UIKit, and MAUI also applies safe area at the layout level. Both together cause a double inset, resulting in an extra left margin.

Description of Change :

Safe Area Handling Fix:

  • Updated the MauiSearchBar constructor to set InsetsLayoutMarginsFromSafeArea = false, preventing UIKit from automatically applying safe-area insets and avoiding double-inset scenarios on iPadOS 26+ windowed mode.

Testing :

  • Added a new test, MauiSearchBarInsetsLayoutMarginsFromSafeAreaIsFalse, to verify that InsetsLayoutMarginsFromSafeArea is disabled on the MauiSearchBar, ensuring the fix remains in place.
  • Included the necessary using Microsoft.Maui.Platform; directive in the test file to support the new test.

Issues Fixed

Fixes #34551

Tested the behavior in the following platforms

  • Windows
  • Android
  • iOS
  • Mac
Before Issue Fix After Issue Fix
BeforeFix34551.mov
AfterFix34551.mov

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34704

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34704"

@dotnet-policy-service dotnet-policy-service Bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Mar 27, 2026
@SubhikshaSf4851 SubhikshaSf4851 changed the title Fix SearchBar unexpected left margin in iPad windowed mode on 26 Version [iOS] Fix SearchBar unexpected left margin in iPad windowed mode on 26 Version Mar 27, 2026
@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Mar 28, 2026
@SubhikshaSf4851
Copy link
Copy Markdown
Contributor Author

🤖 AI Summary

📊 Expand Full Review97fab15 · updated condition only for iPad

As recommended I have moved the logics into MauiSearchBar also Added Device Test

@sheiksyedm sheiksyedm marked this pull request as ready for review March 30, 2026 10:16
Copilot AI review requested due to automatic review settings March 30, 2026 10:16
Copy link
Copy Markdown
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

Fixes the extra left margin seen on iPadOS 26 in windowed mode by preventing UISearchBar from propagating safe-area insets into its layout margins (avoiding a double-inset when MAUI already applies safe area at the layout level).

Changes:

  • Set InsetsLayoutMarginsFromSafeArea = false for MauiSearchBar.
  • Add an iOS device test asserting MauiSearchBar.InsetsLayoutMarginsFromSafeArea is false.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Core/src/Platform/iOS/MauiSearchBar.cs Disables UIKit’s safe-area-to-layout-margins propagation on the native search bar.
src/Core/tests/DeviceTests/Handlers/SearchBar/SearchBarHandlerTests.iOS.cs Adds a regression test asserting the new default value for InsetsLayoutMarginsFromSafeArea.

Comment thread src/Core/src/Platform/iOS/MauiSearchBar.cs Outdated
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

The tests failed

@SubhikshaSf4851
Copy link
Copy Markdown
Contributor Author

@kubaflo I have checked the device tests and UI tests in local which contains category searchBar and no test were failed. I have also checked the test for issue34551, It fails without Fix and passed with Fix.

WithOut Fix With Fix
Screenshot 2026-04-06 at 11 44 00 Screenshot 2026-04-06 at 11 43 05
Device Test UI Test
Screenshot 2026-04-06 at 12 35 03 Screenshot 2026-04-06 at 12 28 39

@MauiBot MauiBot added the s/agent-fix-win AI found a better alternative fix than the PR label Apr 7, 2026
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

There'a an updated ai's summary - could you please check it?

@SubhikshaSf4851
Copy link
Copy Markdown
Contributor Author

@kubaflo I have implemented the suggested changes

@sheiksyedm
Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@dotnet dotnet deleted a comment from MauiBot Apr 14, 2026
@dotnet dotnet deleted a comment from MauiBot Apr 14, 2026
@sheiksyedm
Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Copy Markdown
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

Could you please review the AI's suggestions?

@SubhikshaSf4851
Copy link
Copy Markdown
Contributor Author

@kubaflo I have updated the suggested changes ,

@dotnet dotnet deleted a comment from MauiBot Apr 17, 2026
@dotnet dotnet deleted a comment from MauiBot Apr 17, 2026
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

Maybe we should scope it to iOS 26+ only?

@SubhikshaSf4851
Copy link
Copy Markdown
Contributor Author

@kubaflo Initially added a condition and limited the fix to version 26, but the AI summary suggested removing it. However, removing the condition did not change the behavior in version 18. so kept it as it is.

@dotnet dotnet deleted a comment from MauiBot Apr 21, 2026
@dotnet dotnet deleted a comment from MauiBot Apr 21, 2026
@kubaflo kubaflo changed the base branch from main to inflight/current April 27, 2026 14:56
@kubaflo kubaflo merged commit fb68747 into dotnet:inflight/current Apr 27, 2026
28 of 31 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR7 milestone Apr 27, 2026
PureWeen pushed a commit that referenced this pull request Apr 28, 2026
…6 Version (#34704)

<!-- Please keep the note below for people who find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Root Cause : 
iPadOS 26 windowed mode introduces a left safe-area inset (due to
traffic light buttons). `UISearchBar` applies this via `UIKit`, and MAUI
also applies safe area at the layout level. Both together cause a double
inset, resulting in an extra left margin.

### Description of Change :
**Safe Area Handling Fix:**

* Updated the `MauiSearchBar` constructor to set
`InsetsLayoutMarginsFromSafeArea = false`, preventing UIKit from
automatically applying safe-area insets and avoiding double-inset
scenarios on iPadOS 26+ windowed mode.

### Testing :

* Added a new test,
`MauiSearchBarInsetsLayoutMarginsFromSafeAreaIsFalse`, to verify that
`InsetsLayoutMarginsFromSafeArea` is disabled on the `MauiSearchBar`,
ensuring the fix remains in place.
* Included the necessary `using Microsoft.Maui.Platform;` directive in
the test file to support the new test.


<!-- Enter description of the fix in this section -->
### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #34551 
### Tested the behavior in the following platforms

- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/4702c772-b3e2-4a48-88b1-97ef82738498">
| <video
src="https://github.com/user-attachments/assets/05bb31f1-4480-4602-b807-ad9b105b7a95">
|
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
PureWeen pushed a commit that referenced this pull request Apr 29, 2026
…6 Version (#34704)

<!-- Please keep the note below for people who find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Root Cause : 
iPadOS 26 windowed mode introduces a left safe-area inset (due to
traffic light buttons). `UISearchBar` applies this via `UIKit`, and MAUI
also applies safe area at the layout level. Both together cause a double
inset, resulting in an extra left margin.

### Description of Change :
**Safe Area Handling Fix:**

* Updated the `MauiSearchBar` constructor to set
`InsetsLayoutMarginsFromSafeArea = false`, preventing UIKit from
automatically applying safe-area insets and avoiding double-inset
scenarios on iPadOS 26+ windowed mode.

### Testing :

* Added a new test,
`MauiSearchBarInsetsLayoutMarginsFromSafeAreaIsFalse`, to verify that
`InsetsLayoutMarginsFromSafeArea` is disabled on the `MauiSearchBar`,
ensuring the fix remains in place.
* Included the necessary `using Microsoft.Maui.Platform;` directive in
the test file to support the new test.


<!-- Enter description of the fix in this section -->
### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #34551 
### Tested the behavior in the following platforms

- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/4702c772-b3e2-4a48-88b1-97ef82738498">
| <video
src="https://github.com/user-attachments/assets/05bb31f1-4480-4602-b807-ad9b105b7a95">
|
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-searchbar SearchBar control community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) version/iOS-26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in iPad windowed mode SearchBar adds left margin equivaltent to SafeAreaInsets when placed inside grid

7 participants