[iOS] Fix SearchBar unexpected left margin in iPad windowed mode on 26 Version#34704
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34704Or
iex "& { $(irm https://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34704" |
e30453e to
f97218d
Compare
As recommended I have moved the logics into MauiSearchBar also Added Device Test |
There was a problem hiding this comment.
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 = falseforMauiSearchBar. - Add an iOS device test asserting
MauiSearchBar.InsetsLayoutMarginsFromSafeAreaisfalse.
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. |
|
@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.
|
kubaflo
left a comment
There was a problem hiding this comment.
There'a an updated ai's summary - could you please check it?
|
@kubaflo I have implemented the suggested changes |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines successfully started running 2 pipeline(s). |
kubaflo
left a comment
There was a problem hiding this comment.
Could you please review the AI's suggestions?
|
@kubaflo I have updated the suggested changes , |
kubaflo
left a comment
There was a problem hiding this comment.
Maybe we should scope it to iOS 26+ only?
…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. -->
…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. -->




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).
UISearchBarapplies this viaUIKit, 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:
MauiSearchBarconstructor to setInsetsLayoutMarginsFromSafeArea = false, preventing UIKit from automatically applying safe-area insets and avoiding double-inset scenarios on iPadOS 26+ windowed mode.Testing :
MauiSearchBarInsetsLayoutMarginsFromSafeAreaIsFalse, to verify thatInsetsLayoutMarginsFromSafeAreais disabled on theMauiSearchBar, ensuring the fix remains in place.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
BeforeFix34551.mov
AfterFix34551.mov