From: Shane Neuville Date: Tue, 27 Aug 2019 07:19:52 +0000 (-0600) Subject: Fix android to not duplicate titleview with shell (#7276) X-Git-Tag: accepted/tizen/5.5/unified/20200421.150457~140^2^2~46 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5c5dd3b4f064dc489d918e5627edcdb1b8de6d0a;p=platform%2Fcore%2Fcsapi%2Fxsf.git Fix android to not duplicate titleview with shell (#7276) --- diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ShellTitleView.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ShellTitleView.cs new file mode 100644 index 0000000..d76a34c --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ShellTitleView.cs @@ -0,0 +1,80 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + + +#if UITEST +using NUnit.Framework; +using Xamarin.Forms.Core.UITests; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.None, 0, "Shell Title View Test", + PlatformAffected.All)] +#if UITEST + [NUnit.Framework.Category(UITestCategories.Shell)] + [NUnit.Framework.Category(UITestCategories.TitleView)] +#endif + public class ShellTitleView : TestShell + { + protected override void Init() + { + AddTopTab(createContentPage("title 1"), "page 1"); + AddTopTab(createContentPage(null), "page 2"); + AddTopTab(createContentPage("title 3"), "page 3"); + AddTopTab(createContentPage("title 4"), "page 4"); + + ContentPage createContentPage(string titleView) + { + ContentPage page = new ContentPage() + { + Content = new StackLayout() + { + Children = + { + new Label() + { + Text = "Click through the tabs and make sure title view changes and doesn't duplicate" + } + } + } + }; + + page.ToolbarItems.Add(new ToolbarItem() { IconImageSource = "coffee.png", Order = ToolbarItemOrder.Primary, Priority = 0 }); + + if (!string.IsNullOrWhiteSpace(titleView)) + { + Shell.SetTitleView(page, + new StackLayout() + { + AutomationId = "TitleViewId", + Children = { new Label() { Text = titleView } } + }); + } + + return page; + } + } + + +#if UITEST && (__IOS__ || __ANDROID__) + + [Test] + public void NoDuplicateTitleViews() + { + var titleView = RunningApp.WaitForElement("TitleViewId"); + + Assert.AreEqual(1, titleView.Length); + + RunningApp.Tap("page 2"); + RunningApp.Tap("page 3"); + RunningApp.Tap("page 4"); + titleView = RunningApp.WaitForElement("TitleViewId"); + + Assert.AreEqual(1, titleView.Length); + } +#endif + + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs index 63a56bb..279890c 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs @@ -586,13 +586,26 @@ namespace Xamarin.Forms.Controls public ContentPage AddTopTab(string title) { - ContentPage page = new ContentPage(); + var page = new ContentPage(); + AddTopTab(page, title); + return page; + } + + + public void AddTopTab(ContentPage page, string title = null) + { + if(Items.Count == 0) + { + var item = AddContentPage(page); + item.Items[0].Items[0].Title = title ?? page.Title; + return; + } + Items[0].Items[0].Items.Add(new ShellContent() { - Title = title, + Title = title ?? page.Title, Content = page }); - return page; } public ContentPage AddBottomTab(string title) @@ -642,7 +655,7 @@ namespace Xamarin.Forms.Controls public ShellItem AddContentPage(ContentPage contentPage) { - ContentPage page = new ContentPage(); + ContentPage page = contentPage ?? new ContentPage(); ShellItem item = new ShellItem() { Items = diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 599c51b..afeeaf2 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -1013,6 +1013,7 @@ + @@ -1263,7 +1264,7 @@ Designer - MSBuild:Compile + MSBuild:UpdateDesignTimeXaml Designer @@ -1324,7 +1325,7 @@ Designer - MSBuild:Compile + MSBuild:UpdateDesignTimeXaml @@ -1332,7 +1333,7 @@ Designer - MSBuild:Compile + MSBuild:UpdateDesignTimeXaml diff --git a/Xamarin.Forms.Core.UITests.Shared/UITestCategories.cs b/Xamarin.Forms.Core.UITests.Shared/UITestCategories.cs index 5e9c782..f45e9b6 100644 --- a/Xamarin.Forms.Core.UITests.Shared/UITestCategories.cs +++ b/Xamarin.Forms.Core.UITests.Shared/UITestCategories.cs @@ -52,5 +52,6 @@ public const string TabbedPage = "TabbedPage"; public const string CustomRenderers = "CustomRenderers"; public const string Page = "Page"; + public const string TitleView = "TitleView"; } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/Renderers/ShellToolbarTracker.cs b/Xamarin.Forms.Platform.Android/Renderers/ShellToolbarTracker.cs index 4702920..8591bbb 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ShellToolbarTracker.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ShellToolbarTracker.cs @@ -443,7 +443,7 @@ namespace Xamarin.Forms.Platform.Android _titleViewContainer = null; } } - else + else if(_titleViewContainer == null) { _titleViewContainer = new ContainerView(context, titleView); _titleViewContainer.MatchHeight = _titleViewContainer.MatchWidth = true; @@ -457,6 +457,10 @@ namespace Xamarin.Forms.Platform.Android _toolbar.AddView(_titleViewContainer); } + else + { + _titleViewContainer.View = titleView; + } } protected virtual void UpdateToolbarItems(Toolbar toolbar, Page page)