Skip to content

Commit 9d5e6ed

Browse files
Vignesh-SF3580PureWeenkubaflo
committed
[Android] Fix NavigationBar overlapping StatusBar when NavigationBar visibility changes (#33359)
<!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! ### Issue Details On Android, the content area in a TabbedPage shows incorrect layout when tabs use mixed HasNavigationBar values (some true, some false). When switching to a tab where the NavigationBar is visible, the content area does not properly account for the toolbar height, resulting in content being obscured by the NavigationBar. **Regression PR:** #27294 ### Root Cause PR #27294 introduced a default OffscreenPageLimit value, which pre-creates tab fragments during initialization. When switching between tabs with different HasNavigationBar values, Android's insets system does not automatically recalculate layout measurements because they were cached during the pre-creation phase. While the toolbar height updates correctly via LayoutParameters, the content area continues using stale inset measurements. ### Description of Change Added a call to AndroidX.Core.View.ViewCompat.RequestApplyInsets(nativeToolbar) in ToolbarExtensions.UpdateIsVisible after updating LayoutParameters. This explicitly requests Android to re-dispatch window insets through the view hierarchy, triggering remeasurement of the content area when the toolbar visibility or height changes. **References:** [Android/ContentViewGroup.cs#L149](https://github.com/dotnet/maui/blob/main/src/Core/src/Platform/Android/ContentViewGroup.cs#L149) [Android/LayoutViewGroup.cs#L166](https://github.com/dotnet/maui/blob/main/src/Core/src/Platform/Android/LayoutViewGroup.cs#L166) [Android/MauiScrollView.cs#L303](https://github.com/dotnet/maui/blob/main/src/Core/src/Platform/Android/MauiScrollView.cs#L303) ### Tested the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33340 ### Screenshots | Before Issue Fix | After Issue Fix | |----------|----------| | <video width="300" height="600" src="https://github.com/user-attachments/assets/e15fe58b-a609-442c-911f-0e0f04ee8545"> | <video width="300" height="600" src="https://github.com/user-attachments/assets/e5da01a3-c0b8-4fc1-a443-efff1409dd82">) | --------- Co-authored-by: Shane Neuville <[email protected]> Co-authored-by: Jakub Florkowski <[email protected]>
1 parent 61b7561 commit 9d5e6ed

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static void UpdateIsVisible(this AToolbar nativeToolbar, Toolbar toolbar)
4747
}
4848

4949
nativeToolbar.LayoutParameters = lp;
50+
AndroidX.Core.View.ViewCompat.RequestApplyInsets(nativeToolbar);
5051
}
5152

5253
public static void UpdateTitleIcon(this AToolbar nativeToolbar, Toolbar toolbar)
27.4 KB
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
2+
using TabbedPage = Microsoft.Maui.Controls.TabbedPage;
3+
4+
namespace Maui.Controls.Sample.Issues;
5+
6+
[Issue(IssueTracker.Github, 33340, "NavigationBar overlaps StatusBar in TabbedPage", PlatformAffected.Android)]
7+
public class Issue33340 : TabbedPage
8+
{
9+
public Issue33340()
10+
{
11+
this.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
12+
var page1 = new ContentPage { Title = "Page1", Content = new Label { Text = "Page 1" } };
13+
NavigationPage.SetHasNavigationBar(page1, false);
14+
Children.Add(new NavigationPage(page1) { Title = "Tab1" });
15+
16+
var page2 = new ContentPage { Title = "Page2", Content = new Label { Text = "Page 2" } };
17+
NavigationPage.SetHasNavigationBar(page2, false);
18+
Children.Add(new NavigationPage(page2) { Title = "Tab2" });
19+
20+
var page3 = new ContentPage { Title = "Page3", Content = new Label { Text = "Page 3" } };
21+
NavigationPage.SetHasNavigationBar(page3, false);
22+
Children.Add(new NavigationPage(page3) { Title = "Tab3" });
23+
24+
var page4 = new ContentPage { Title = "Page4", Content = new Label { Text = "Page 4 with NavigationBar" } };
25+
NavigationPage.SetHasNavigationBar(page4, true);
26+
Children.Add(new NavigationPage(page4) { Title = "Tab4" });
27+
28+
CurrentPage = Children[0];
29+
}
30+
}
31+
11.2 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue33340 : _IssuesUITest
8+
{
9+
public Issue33340(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "NavigationBar overlaps StatusBar in TabbedPage";
14+
15+
[Test]
16+
[Category(UITestCategories.TabbedPage)]
17+
public void NavigationBarLayoutWithMixedHasNavigationBar()
18+
{
19+
App.WaitForElement("Tab4");
20+
App.Tap("Tab4");
21+
VerifyScreenshot();
22+
}
23+
}
8.71 KB
Loading
67.3 KB
Loading

0 commit comments

Comments
 (0)