dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

Window.ModalPopping closes app when e.Cancel = true #23462

Open brianlagunas opened 3 months ago

brianlagunas commented 3 months ago

Description

Using a custom Window class, when hooking into the Window.ModalPopping event, setting the e.Cancel = true causes the app to close when the Android hardware button is pressed for a modal navigation stack.

The offending code can be found in the App.xaml.cs file

Steps to Reproduce

  1. Clone the reproduction repo
  2. Run the App on an Android enumlator with API 34
  3. Click the button on ViewA to Navigate to ViewB
  4. Click the button on ViewB to Navigate to ViewC
  5. Hit the Android Hardware back button
  6. Observe the modal view is no popped, but the App closes.

What I expect to happen is for the modal view to not be popped, and the app to stay running on screen.

For more context, the Prism Library uses a custom Window to take control of the navigation process on a go back for the modal navigation stack. We need to cancel the built-in popping that is invoked by the hardware back button, and use our pop code instead. This gives us the ability to prevent a navigation based on our IConfirmationRequest interface. If the result of our IConfirmationRequest is true we will do the pop modal again, if the result is false, we will not pop the modal and keep the user on the current view.

Link to public reproduction project repository

https://github.com/brianlagunas/WindowModalPoppingBug

Version with bug

8.0.61 SR6.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android API 34

Did you find any workaround?

No

Relevant log output

No response

github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

PureWeen commented 3 months ago

I think we'd make this work by wiring up through the OnBackPressedDispatcher thought with https://github.com/dotnet/maui/pull/22869 looking I think we'd just override OnBackPressed on the dialog? Or perhaps the expectation is still to use OnBackPressedDispatcher now

Zhanglirong-Winnie commented 3 months ago

This issue has been verified using Visual Studio 17.11.0 Preview 2.1(8.0.61). Can repro on Android platform.