Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed shell pages with top bar #20337

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
x:Class="Maui.Controls.Sample.Issues.Issue19159">
<TabBar>
<Tab>
<ShellContent
Title="Page 1"
ContentTemplate="{x:DataTemplate local:Issue19159ContentPage}">
</ShellContent>
<ShellContent
Title="Page 2"
ContentTemplate="{x:DataTemplate local:Issue19159ContentPage}"/>
</Tab>
</TabBar>
</Shell>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 19159, "Top tab bar on Shell hides content", PlatformAffected.iOS)]
public partial class Issue19159 : Shell
{
public Issue19159()
{
InitializeComponent();
}
}

public class Issue19159ContentPage : ContentPage
{
public Issue19159ContentPage()
{
Content = new StackLayout()
{
AutomationId = "page",
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.Fill,
BackgroundColor = new Microsoft.Maui.Graphics.Color(255, 0, 0),
Margin = new Microsoft.Maui.Thickness(10)
};
}
}
}
32 changes: 31 additions & 1 deletion src/Controls/src/Core/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.Maui.Controls
/// </summary>
/// <remarks><see cref = "Page" /> is primarily a base class for more useful derived types. Objects that are derived from the <see cref="Page"/> class are most prominently used as the top level UI element in .NET MAUI applications. In addition to their role as the main pages of applications, <see cref="Page"/> objects and their descendants can be used with navigation classes, such as <see cref="NavigationPage"/> or <see cref="FlyoutPage"/>, among others, to provide rich user experiences that conform to the expected behaviors on each platform.
/// </remarks>
public partial class Page : VisualElement, ILayout, IPageController, IElementConfiguration<Page>, IPaddingElement, ISafeAreaView, ISafeAreaView2, IView, ITitledElement, IToolbarElement
public partial class Page : VisualElement, ILayout, IPageController, IElementConfiguration<Page>, IPaddingElement, ISafeAreaView, ISafeAreaView2, IView, ITitledElement, IToolbarElement, IShellContentInsetObserver
{
/// <summary>
/// The identifier used by the internal messaging system to set <see cref="IsBusy"/>.
Expand Down Expand Up @@ -73,6 +73,8 @@ public partial class Page : VisualElement, ILayout, IPageController, IElementCon

View _titleView;

ShellSection _shellSection;

List<Action> _pendingActions = new List<Action>();

/// <summary>
Expand Down Expand Up @@ -486,6 +488,20 @@ protected override void OnParentSet()
{
if (!Application.IsApplicationOrWindowOrNull(RealParent) && !(RealParent is Page) && !(RealParent is BaseShellItem))
throw new InvalidOperationException("Parent of a Page must also be a Page");

var parent = Parent;
while (!Application.IsApplicationOrWindowOrNull(parent))
{
if (parent is ShellSection shellSection)
{
_shellSection = shellSection;
((IShellSectionController)shellSection).AddContentInsetObserver(this);
break;
}

parent = parent.Parent;
}

base.OnParentSet();
}

Expand Down Expand Up @@ -644,6 +660,12 @@ public void SendDisappearing()
var pageContainer = this as IPageContainer<Page>;
pageContainer?.CurrentPage?.SendDisappearing();

if (_shellSection != null)
{
((IShellSectionController)_shellSection).RemoveContentInsetObserver(this);
_shellSection = null;
}

OnDisappearing();
Disappearing?.Invoke(this, EventArgs.Empty);

Expand Down Expand Up @@ -853,5 +875,13 @@ protected virtual void OnNavigatedFrom(NavigatedFromEventArgs args) { }
/// <returns>The <see cref="Window"/> instance that parents the page.</returns>
public virtual Window GetParentWindow()
=> this.FindParentOfType<Window>();

/// <summary>
/// Adds inset to the page if the page is a part of a shell
/// </summary>
void IShellContentInsetObserver.OnInsetChanged(Thickness inset, double tabThickness)
{
Padding = new Thickness(inset.Left, inset.Top + tabThickness, inset.Right, inset.Bottom);
}
}
}
25 changes: 25 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue19159.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue19159 : _IssuesUITest
{
public Issue19159(TestDevice device) : base(device)
{
}

public override string Issue => "Top tab bar on Shell hides content";

[Test]
public void ContentShouldNotBeOverlaidByTopBar()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Mac, TestDevice.Windows | TestDevice.Android });
_ = App.WaitForElement("page1");

// The content should not be overlaid by top bar
VerifyScreenshot();
}
}
}
Loading