Bug 54977 - Toolbaritems do not appear. Regression from 2.3.3
Summary: Toolbaritems do not appear. Regression from 2.3.3
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-04-10 16:36 UTC by Neville Dastur
Modified: 2017-06-23 14:28 UTC (History)
5 users (show)

Tags: android, toolbar
Is this bug a regression?: Yes
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Neville Dastur 2017-04-10 16:36:33 UTC
I set by toolbar items in XAML

```
<ContentPage.ToolbarItems>
	<ToolbarItem Text="Add Group" Clicked="on_AddGroup_Clicked">
		<ToolbarItem.Icon>
			<OnPlatform x:TypeArguments="FileImageSource" Android="plus" />
		</ToolbarItem.Icon>
	</ToolbarItem>
</ContentPage.ToolbarItems>
```

Since I have upgraded forms to 2.3.4 the toolbar text does not show. Downgrading to 2.3.3 fixes the issue.

Of interest, the button item is there as it is "clickable" it is just that the text does not show.

Not sure if related to the issue described in this forum post
https://forums.xamarin.com/discussion/92305/on-android-the-toolbar-is-not-showing-until-push-popasync
Comment 1 Paul DiPietro [MSFT] 2017-04-10 17:48:45 UTC
Appears to work correctly on nightly.
Comment 2 Neville Dastur 2017-04-11 12:14:45 UTC
I tried without the
```
<ToolbarItem.Icon>
   <OnPlatform x:TypeArguments="FileImageSource" Android="plus" />
</ToolbarItem.Icon>
```

bit and works like that. But it is different behaviour to Forms 2.3.3
Comment 3 Stephane Delcroix 2017-04-18 14:08:13 UTC
this works fine in 2.3.4.231.

Please provide a simple project triggering the issue
Comment 4 John Hardman 2017-06-20 12:03:19 UTC
I am seeing an intermittent problem with the toolbar on 2.3.4 on Android, where the first time I open a page it shows the toolbar, but on subsequent openings of that same page it sometimes does and sometimes doesn't show the toolbar. The toolbar on the page I noticed this on has one primary toolbar item and three secondary toolbar items.
Comment 5 Rui Marinho 2017-06-20 18:39:49 UTC
Thank you for taking the time to submit the bug. We are unable to reproduce this issue. Please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue. Can you help with a repo John Hardman ?
Comment 6 John Hardman 2017-06-20 22:00:07 UTC
I'll see if I can create one tomorrow.
Comment 7 John Hardman 2017-06-21 11:58:30 UTC
For me, the problem occurs because of the way the page is pushed. For a page that will get a lot of use, I kept a WeakReference to the page object and used that when pushing the page onto the navigation stack on 2nd and subsequent uses. I had disabled that code long ago as it resulted in problems, but people in the forums had said recently that they were doing that successfully, so I re-enabled it. Well, it does still cause problems, so I'll be disabling it again.

Code to demonstrate this is below.
Push an instance of Bug54977ReproRootPageView onto the navigation stack.
Press the button.
Check for the toolbar (it is visible).
Hit back.
Press the button again.
Check for the toolbar (it isn't visible).

Whilst the toolbar could be re-added in OnAppearing, my concern would be as to what else might be going wrong that isn't immediately apparent, so this use of WeakReference will be disabled in my code again.

Note that this isn't just on Android. It occurs on iOS and UWP as well.


using System;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace ViewsUsingXamarinForms
{
    public class Bug54977ReproRootPageView : ContentPage
    {
        private static WeakReference bug54977ReproPageView;

        public Bug54977ReproRootPageView()
        {
            Title = "Bug54977 Page 1";
            Content = new Button
            {
                Text = "Press me",
                Command = new Command(async () => { await OnClickAsync(); }),
                FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center
            };
        }

        private Task OnClickAsync()
        {
            Bug54977ReproPageView page
                = bug54977ReproPageView?.Target as Bug54977ReproPageView;

            if (page == null)
            {
                page = new Bug54977ReproPageView();
                bug54977ReproPageView = new WeakReference(page);
            }

            return Navigation.PushAsync(page);
        }

    } // class

    internal class Bug54977ReproPageView : ContentPage
    {
        internal Bug54977ReproPageView()
        {
            this.Title = "Bug54977 Page 2";

            Content = new Label
            {
                Text = "Check for toolbar item above, then hit Back",
                FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                LineBreakMode = LineBreakMode.WordWrap,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center
            };

            ToolbarItems.Add(new ToolbarItem
            {
                Order = ToolbarItemOrder.Primary,
                Priority = 0,
                Text = "Value",
            });
        }

    } // class

} // namespace ViewsUsingXamarinForms

// eof
Comment 8 John Hardman 2017-06-21 12:00:30 UTC
Re-reading the original post, I believe what I am seeing is different to the original post.
Comment 9 David Ortinau [MSFT] 2017-06-23 14:28:43 UTC
Thanks John,

Based on that, I'm going to close this issue. 

Re: the possible issue you are raising, I'm not able to reproduce it. Please open a new issue with more details on that. I tested on 2.3.4.247, Android 7.1.