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

FlyoutPage IsPresented does not work when user opens flyout by clicking on hamburger #15767

Open
SmartmanApps opened this issue Jun 21, 2023 · 8 comments
Labels
area-controls-flyoutpage FlyoutPage good first issue Good for newcomers platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@SmartmanApps
Copy link

Description

With FlyoutLayoutBehavior.Popover, whereby the Details page should entirely hide the Flyout(Menu)Page, most of the Disappearing lifecycle events never run. i.e.

  • OnDisappearing never runs (observed on both Windows and Android)
  • IsVisible is never set to false (observed on both Windows and Android)
  • IsPresented only ever set to false on Windows manually by dev (works automatically on Android if user hides the menu again without making a selection, but only then, otherwise same behaviour as Windows)
  • IsPresentedChanged DOES work, but that's the only one I've seen working (and only when the dev explicitly sets IsPresented to false themselves on Windows, otherwise it stays true the whole time).

Steps to Reproduce

  1. create a new app
  2. add a FlyoutPage (note: the FlyoutPage sample app STILL doesn't work - I reported this previously. Error message is "Can't change IsPresented when setting Default")
  3. add some debugging to observe these behaviours
  4. run on different platforms

Link to public reproduction project repository

https://github.com/SmartmanApps/FlyoutRepro

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

1000.19041.1000.0 Android API 28

Did you find any workaround?

No (IsPresentedChanged works on Android, but only half usable on Windows).

Relevant log output

********************************** TemplateFlyoutMenuPage.OnAppearing is running
********************************** TemplateFlyoutPage.IsPresented is True
********************************** TemplateFlyoutPage.IsVisible is True
********************************** TemplateFlyoutPage.IsPresented is False
********************************** TemplateFlyoutPage.IsVisible is True
********************************** TemplateFlyoutPage.IsPresented is True
********************************** TemplateFlyoutPage.IsVisible is True
********************************** TemplateFlyoutPage.IsPresented is False
********************************** TemplateFlyoutPage.IsVisible is True
@SmartmanApps SmartmanApps added the t/bug Something isn't working label Jun 21, 2023
@Eilon Eilon added the area-controls-flyoutpage FlyoutPage label Jun 21, 2023
@PureWeen PureWeen changed the title FlyoutPage with FlyoutLayoutBehavior.Popover (most) Disappearing lifecycle events never run FlyoutPage IsPresented does not work when user opens flyout by clicking on hamburger Jun 21, 2023
@PureWeen PureWeen added this to the Backlog milestone Jun 21, 2023
@ghost
Copy link

ghost commented Jun 21, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@PureWeen
Copy link
Member

Of the listed issues my thinking is that

IsPresented only ever set to false on Windows manually by dev (works automatically on Android if user hides the menu again without making a selection, but only then, otherwise same behaviour as Windows)

is the only part here that is a bug and the rest of it is by design.

We don't trigger visible/appearing just because something is obstructed.

@SmartmanApps
Copy link
Author

SmartmanApps commented Jun 21, 2023

@PureWeen

We don't trigger visible/appearing just because something is obstructed.

That would make sense if you were using one of the Split options, but again this is with the Popover option, in which the page completely disappears, same as when you do a NavigationPage.PushModalAsync and the page disappears underneath another page, and OnDisappearing runs, but in this case the page has another page on top of it and yet OnDisappearing never runs.

This is inconsistent behaviour with OnDisappearing running when you do NavigationPage.PushModalAsync (in that case OnDisappearing runs, in this case it doesn't). I wanted to put code into OnAppearing - same as I do with NavigationPages in a stack when the page above it gets popped - only to find it only ever runs once.

@lizharems lizharems assigned lizharems and unassigned lizharems Jul 12, 2023
@SmartmanApps
Copy link
Author

I have a partial workaround for this, which I have pushed to a "workaround" branch in the original repo. I say "partial" because it works if the user actually changes pages, but not if they just close the menu and stay on the same page (which is a symptom of "IsPresented" not being set to false on Windows when the user does that - one of the issues here needing fixing, the root issue).

The workaround is on your FlyoutPage, subscribe a method to IsPresentedChanged, and then in that method you can manually call On(Dis)Appearing based on whether IsPresented is true or not, like so...

IsPresentedChanged+=TemplateFlyoutPage_IsPresentedChanged;
...
private void TemplateFlyoutPage_IsPresentedChanged(object sender,System.EventArgs e) {
    //// WORKAROUND - manually call On(Dis)Appearing
    //// Won't be called on Windows if user just clicks on menu again to close it without changing pages
    if (IsPresented) {OnAppearing();}
    else {OnDisappearing();}
    }

BTW I've realised that the reason OnDisappearing isn't running is because the hamburger icon itself is still visible... but the menu isn't! This for me is the important issue (which the workaround partially addresses). On Windows, with Flyout set to Popover, even though the hamburger icon remains visible the MenuPage itself completely disappears (because the page they have selected completely covers it, similar to when you do a PushModalAsync with a Page), and so I want the OnDisappearing for the ContentPage to run. This creates regular events (OnAppearing and OnDisappearing) where you can check if something needs changing in the Menu, such as someone has become a subscriber, or the opposite, their subscription has run out, and we can make corresponding changes to what appears in the Menu (such as display "Premium only" next to a feature not available on the free version... but I'm not sure if this is a feature request or a bug fix :-) ).

@SmartmanApps
Copy link
Author

Hello again. I have some more information to add in regards to my last statement (the part which I'm not sure if it's a feature request or a bug fix :-) ). This applies to both Windows AND Android (not just Windows-only, which is the original issue).

In regards to my comment about wanting OnAppearing to run when the user clicks on the hamburger menu in Popover mode (given that the menu itself isn't visible to the user until then, given it's hidden under whatever the current Detail page is) I found, with further digging, that there's currently no way for the app (the dev) to know that the menu isn't presented upon start-up, even though it isn't. i.e. the Menu Page has had OnAppearing run, and thinks the Menu Page is visible, even though IsPresented is false. This is because, as per my previous comment, I have to hook into IsPresentedChanged to make these things run (OnAppearing and OnDisappearing), but because the app starts out with IsPresented set to false, there's no change to it's state until the first time a user clicks on the hamburger, and so the app actually starts out in this weird state where OnAppearing has run but IsPresented is false. So we either need OnAppearing to NOT run if IsPresented is false, or for IsPresented to get set back to it's correct stae of false after the constructor and OnAppearing has run so that OnDisappearing can run. As it is now those 2 states are out of sync with each other until the first click of the Menu.

Here's some Debug output. Note the last 2 lines before hamburger clicked on - OnAppearing has run whilst IsPresented is false.

********************************** MainFlyoutPage.IsPresented is False pre flyout menu constructor
********************************** MainFlyoutMenuPage constructor is running
********************************** MainFlyoutMenuPage constructor is finished
********************************** MainFlyoutPage.IsPresented is False post flyout menu constructor
********************************** MainFlyoutPage.IsPresented is False end of constructor
********************************** MainFlyoutPage.OnAppearing is running
********************************** MainFlyoutPage.IsPresented is False
********************************** MainFlyoutMenuPage.OnAppearing is running
********************************** MainFlyoutPage.IsPresented is False
Clicked on hamburger
********************************** MainFlyoutPage_IsPresentedChanged is running
********************************** MainFlyoutPage.OnAppearing is running
********************************** MainFlyoutPage.IsPresented is True
********************************** MainFlyoutPage.IsPresented is True
********************************** MainFlyoutPage.IsPresented is True
********************************** MainFlyoutPage.IsVisible is True

@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 4. Can repro on windows and android platforms with sample project.
https://github.com/SmartmanApps/FlyoutRepro
image

@bmacombe
Copy link
Contributor

Of the listed issues my thinking is that

IsPresented only ever set to false on Windows manually by dev (works automatically on Android if user hides the menu again without making a selection, but only then, otherwise same behaviour as Windows)

is the only part here that is a bug and the rest of it is by design.

This is a bug and causing me issues at the moment. I'm working on a custom TitleView that needs to be able to show the flyout. It only works once on Windows because IsPresented is never set back to false if the flyout is closed by the user clicking outside of it. (using popover mode)

@bmacombe
Copy link
Contributor

Since my button in the TitleView is obscured when the flyout is open, I've been able to work around it just assuming IsPresented should be set to false when my button is clicked

if(Window?.Page is FlyoutPage flyoutPage)
{
	flyoutPage.IsPresented = false;
	flyoutPage.IsPresented = true;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-flyoutpage FlyoutPage good first issue Good for newcomers platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants