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

Attempt to present <Plugin_Maui_BottomSheet_Platform_MaciOS_BottomSheetUIViewController whose view is not in the window hierarchy. #72

Open
johncdoherty opened this issue Mar 6, 2025 · 3 comments
Labels
bug Something isn't working question Further information is requested

Comments

@johncdoherty
Copy link

Describe the bug
Thanks a ton for this great MAUI bottom sheet implementation.

I'm running into an issue on iOS (only) when I try to open a bottom sheet from another bottom sheet. I receive the exception below and bottom sheet doesn't open. I also experience the same issue if I use the CommunityToolkit.Mvvm Messenger to open the bottom sheet from the main page's view model, which I attempted as a workaround. Perhaps I'm not using something properly? Thanks!

Exception:
BottomSheetSample[7612:11078107] [Presentation] Attempt to present <Plugin_Maui_BottomSheet_Platform_MaciOS_BottomSheetUIViewController: 0x119451a00> on <Plugin_Maui_BottomSheet_Platform_MaciOS_BottomSheetUIViewController: 0x139822e00> (from <Plugin_Maui_BottomSheet_Platform_MaciOS_BottomSheetUIViewController: 0x139822e00>) whose view is not in the window hierarchy.

To Reproduce
Steps to reproduce the behavior:

  1. Build and run the attached 'BottomSheetSample' project on an iOS simulator or real device
  2. Click on 'Open BottomSheet 1'
  3. Click on 'Open BottomSheet 2' or 'Open BottomSheet2 via Message'
  4. Exception above occurs and 2nd bottom sheet doesn't open

Expected behavior
BottomSheet2 should open, like it does if you click 'Open BottomSheet 2' from the main page

Desktop (please complete the following information):

  • OS: iOS

Smartphone (please complete the following information):

  • Device: [e.g. iPhone 16 Pro Max simulator or real device
  • OS: iOS18.2

BottomSheetSample.zip

@johncdoherty johncdoherty added bug Something isn't working to verify labels Mar 6, 2025
@johncdoherty
Copy link
Author

Added a repo of the sample here: https://github.com/johncdoherty/BottomSheetSample

@lucacivale lucacivale added question Further information is requested and removed to verify labels Mar 6, 2025
@lucacivale
Copy link
Owner

@johncdoherty
I had a look at your repro.

First I would recommend you to use the AddBottomSheet method to register your BottomSheets. This adds transient named BottomSheets. You wouldn't even need your Servicehelper and View and ViewModel singletons are normally an exception.

Navigation would work like this. The benefit here is that it decouples your ui from your business logic.
_bottomSheetNavigationService.NavigateTo("Showcase");

But this is just a recommendation 😄

The issue currently is that before you open the second BottomSheet you clear the stack.
Is this really necessary?
If yes we would need a ClearBottomSheetStackAsync to ensure that all BottomSheets are really closed before we move on.

As a workaround you can add a delay after ClearBottomSheetStack

private async void Button_Clicked(object sender, EventArgs e)
{
    bottomSheetNavigationService.ClearBottomSheetStack();
    await Task.Delay(600);
    this.bottomSheetNavigationService.NavigateTo("BottomSheet2");
}

@johncdoherty
Copy link
Author

@lucacivale Thank you for the quick response!

Yes, I completely agree with your recommendation of decoupling. There are some underlying factors that require me to implement it this way right now, but plan to shift to the approach you mentioned above after I have your library fully integrated.

The await Task.Delay(600); workaround works well for me right, now, but it's unavoidable that I need to clear the bottom sheet stack in some scenarios. An addition of ClearBottomSheetStackAsync() (and perhaps NavigateToAsync()) would be really helpful.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants