Skip to content

Commit

Permalink
Improve rendering for tab pages without title.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanpalmer committed Sep 1, 2022
1 parent c472c07 commit 238f851
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
15 changes: 15 additions & 0 deletions DemoApp/DemoPages/TabbedPageDemoPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public TabbedPageDemoPage(bool withInnerNavigation = false)
new Label{Text = "This is content on tab A"},
new Button{Text = "Open ModalPage", Command = new Command(OpenModalPage)},
new Button{Text = "Open Subpage", Command = new Command(OpenSubpage)},
new Button { Text = "Remove titles", Command = new Command(RemoveTitles) },
new Button { Text = "Remove icons", Command = new Command(RemoveIcons) },
}
}
}.AddPageLog();
Expand Down Expand Up @@ -77,5 +79,18 @@ async void OpenSubpage()
}.AddPageLog();
await CurrentPage.Navigation.PushAsync(page);
}


void RemoveTitles()
{
foreach (var c in Children)
c.Title = "";
}

void RemoveIcons()
{
foreach (var c in Children)
c.IconImageSource = null;
}
}
}
12 changes: 11 additions & 1 deletion QuickTest/ElementRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static string Render(this Element element)
var tabbedPage = element.FindParent<TabbedPage>();
var tabResult = "";
while (tabbedPage != null) {
tabResult = "\n|" + string.Join("|", tabbedPage.Children.Select(p => tabbedPage.CurrentPage == p ? $"> {p.Title} <" : $" {p.Title} ")) + "|" + tabResult;
tabResult = "\n|" + string.Join("|", tabbedPage.Children.Select(p => tabbedPage.CurrentPage == p ? $"> {GetTabTitle(p)} <" : $" {GetTabTitle(p)} ")) + "|" + tabResult;
tabbedPage = tabbedPage.FindParent<TabbedPage>();
}
result += tabResult;
Expand Down Expand Up @@ -89,6 +89,16 @@ static string GetTitle(ContentPage page)
return result;
}

static string GetTabTitle(Page page)
{
if (!string.IsNullOrWhiteSpace(page.Title))
return page.Title;
else if (page.IconImageSource is FileImageSource fileImageSource)
return fileImageSource.File;
else
return page.AutomationId;
}

public static string Render(this ListView listView)
{
var result = "";
Expand Down
8 changes: 8 additions & 0 deletions Tests/RendererTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ public void TestTabbedPageRendering()
Assert.That(Render(), Is.EqualTo(\n · \n · This is a modal page\n · Close"));
Tap("Close");
Assert.That(Render(), Does.StartWith(tabbedPageRendering));

Tap("Remove titles");
tabbedPageRendering = "· TabbedPage \n |> one.png <| two.png |\n · \n · This is content on tab A\n";
Assert.That(Render(), Does.StartWith(tabbedPageRendering));

Tap("Remove icons");
tabbedPageRendering = "· TabbedPage \n |> _Tab_A_AutomationId_ <| _Tab_B_AutomationId_ |\n · \n · This is content on tab A\n";
Assert.That(Render(), Does.StartWith(tabbedPageRendering));
}

[Test]
Expand Down

0 comments on commit 238f851

Please sign in to comment.