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

Popup V2 #1581

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

bijington
Copy link
Contributor

@bijington bijington commented Nov 29, 2023

Description of Change

This is primarily aimed at playing around but also with the aim of exposing the implementation to see what everything thinks.

The popupcontainer is an internal ContentPage that is used to display content. there are 2 ways user can create popup. It can be a simple view or for more complex tasks user has to inherit from Popup. What are the complex tasks? In case you want to Close popup from the control or you want to get the result from the popup or you want to subscribe on OnOpened/OnClosed.

For MVVM users there is a PopupService. Pay attention all popups must be registered. Also you can close popup from PopupService only if you opened it using PopupService. DO NOT combine extension method and PopupService.

Now all configurations live in PopupOptions. You can configure BackgroundColor (Dim), popup size and popup layout position. Dissmiss by outside tap also exist in PopupOptions.

The BindingContext is set automatically to PopupContainer, Popup and View.

As the new Popup uses only MAUI Controls, we expect you get all benefits of HotReload. All Controls including Popup in Popup and MediaElement should work without issues.

Features currently removed: AnchorView.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

@ne0rrmatrix
Copy link
Contributor

ne0rrmatrix commented Dec 1, 2023

I have ended up rewriting at least 3 or 4 samples submitted as bugs using standard DI pattern because the code would crash in IOS 17.x. I wanted to verify the issues that were being reported. If I see a bunch of different reports I put extra effort in.

Simplifying implementation would be great. I am all for that.

@bijington bijington added the needs discussion Discuss it on the next Monthly standup label Dec 5, 2023
@TheCodeTraveler TheCodeTraveler removed the needs discussion Discuss it on the next Monthly standup label Jan 4, 2024
@bijington
Copy link
Contributor Author

There are currently a couple of breaking changes to the IPopupService that I think are still good but we should consider documenting them to aid developers upgrading:

await popupService.ShowPopupAsync<MockPageViewModel>(CancellationToken.None);

becomes

await popupService.ShowPopupAsync<MockPageViewModel>(token: CancellationToken.None);
await Assert.ThrowsAsync<TaskCanceledException>(() => popupService.ShowPopupAsync<MockPageViewModel>(viewModel => viewModel.HasLoaded = true, cts.Token));

becomes

await Assert.ThrowsAsync<TaskCanceledException>(() => popupService.ShowPopupAsync<MockPageViewModel>(viewModel => viewModel.HasLoaded = true, token: cts.Token));

It also involves removing the ability to supply a viewModel instance to the Show methods to remove the confusion we have seen around developers expecting the BindingContext to automatically be set. I am happy to move this into a separate PR if we think it if worthwhile?

@bijington bijington marked this pull request as ready for review February 11, 2024 14:26
@TheCodeTraveler
Copy link
Collaborator

@bijington FYI - we now have a few merge conflicts on this PR after merging a bunch of Popup PRs today

@dotnet-policy-service dotnet-policy-service bot added stale The author has not responded in over 30 days help wanted This proposal has been approved and is ready to be implemented labels Apr 27, 2024
@bijington bijington removed help wanted This proposal has been approved and is ready to be implemented stale The author has not responded in over 30 days labels Jun 5, 2024
@bijington bijington requested a review from a team June 9, 2024 20:43
@bijington bijington changed the title Initial musings on showing popups without having to subclass Popup Provide the ability to show popups without having to subclass Popup Jun 20, 2024
@dotnet-policy-service dotnet-policy-service bot added stale The author has not responded in over 30 days help wanted This proposal has been approved and is ready to be implemented labels Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 11 changed files in this pull request and generated no suggestions.

Files not reviewed (6)
  • samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/MultiplePopupPage.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/Views/Popups/PopupContentView.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/MauiProgram.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/MultiplePopupViewModel.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/PopupContentViewModel.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Views/Popups/PopupContentView.xaml.cs: Evaluated as low risk
@VladislavAntonyuk VladislavAntonyuk force-pushed the feature/sl/remove-popup-constraint-from-popup-service branch from c1488d0 to ebc39f2 Compare January 15, 2025 00:11
@VladislavAntonyuk VladislavAntonyuk self-assigned this Jan 15, 2025
@VladislavAntonyuk VladislavAntonyuk force-pushed the feature/sl/remove-popup-constraint-from-popup-service branch from aeb9020 to 94bee57 Compare January 15, 2025 18:52
Copy link
Member

@pictos pictos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! I didn't run locally yet, just reviewed the code.

I saw that you removed the old popups reference, and I think we should mark them as obsolete and let them live for a while before removing everything. At least is what I remember from the last standup.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 81 out of 96 changed files in this pull request and generated no comments.

Files not reviewed (15)
  • samples/CommunityToolkit.Maui.Sample/App.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/MultiplePopupPage.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/Resources/Styles/Styles.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/Models/PopupSize.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/PopupSizingIssuesViewModel.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/StylePopupViewModel.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/PopupPositionViewModel.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/CustomSizeAndPositionPopupViewModel.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/UpdatingPopupViewModel.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupLayoutAlignmentPage.xaml.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/ShowPopupInOnAppearingPage.xaml.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/ViewsGalleryViewModel.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/PopupAnchorViewModel.cs: Evaluated as low risk
Comments suppressed due to low confidence (1)

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/PopupContentViewModel.cs:8

  • The property name 'message' should be renamed to 'Message' to follow PascalCase convention.
string message = "";
@VladislavAntonyuk VladislavAntonyuk added pending documentation This feature requires documentation breaking change This label is used for PRs that include a breaking change area/views Issue/Discussion/PR that has to do with Views waiting for feedback Waiting for a response from the author or the core team member and removed help wanted This proposal has been approved and is ready to be implemented stale The author has not responded in over 30 days labels Jan 15, 2025
@VladislavAntonyuk VladislavAntonyuk changed the title Provide the ability to show popups without having to subclass Popup Popup V2 Jan 16, 2025
return popupService.ShowPopupAsync<CsharpBindingPopupViewModel>(
onPresenting: viewModel => viewModel.Load("This is a platform specific popup with a .NET MAUI View being rendered. The behaviors of the popup will confirm to 100% this platform look and feel, but still allows you to use your .NET MAUI Controls."),
token);
return popupService.ShowPopupAsync<CsharpBindingPopupViewModel>(Application.Current!.Windows[0].Page!.Navigation, new PopupOptions(), token);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ! is not ideal. Can you possibly do a null check and return a InvalidOperationException or similar?

onPresenting: viewModel => viewModel.PerformUpdates(10),
token);
return popupService.ShowPopupAsync<UpdatingPopupViewModel>(Application.Current!.Windows[0].Page!.Navigation, new PopupOptions(), token);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Using ! is not idea. A null check and/or throwing an exception if the app window is null would be my advice. It should never be in an invalid state when app is running.

[RelayCommand]
Task OnShowPopupContent(CancellationToken token)
{
return popupService.ShowPopupAsync<PopupContentViewModel>(Application.Current!.Windows[0].Page!.Navigation, new PopupOptions(), token);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another example of !

public sealed partial class PopupContentViewModel : BaseViewModel
{
[ObservableProperty]
string message = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we are not using string.empty?

{
popupService.ShowPopup<UpdatingPopupViewModel>(onPresenting: viewModel => viewModel.PerformUpdates(updates + 2));
await popupService.ShowPopupAsync<UpdatingPopupViewModel>(Application.Current!.Windows[0].Page!.Navigation, new PopupOptions(), CancellationToken.None);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above with ! not being recommended.

Copy link
Contributor

@ne0rrmatrix ne0rrmatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very well done! I am excited to see this merged. I was unable to test as there are merge conflicts. But once those are resolved I will test it. At this time I see no reason not to merge as soon as it can be tested. I would prefer not to use null forgiveness with grabbing the window object but I will let you decide if you want to do that. I will approve this as soon as i can test and verify it is functional.

@VladislavAntonyuk
Copy link
Collaborator

Thanks @ne0rrmatrix, you can switch to a branch and run the app. The PR for now is to confirm the approach and API changes. We'll need a PR to mark the current popup as obsolete, and release MCT, and after that, I'll resolve merge conflicts and add docs.

@ne0rrmatrix
Copy link
Contributor

I created a branch and tested all of the features in Mulitple Popup page. There arre some issues with CustomPositionPage page only working for first test. If you click on a second button to test another position nothing happens. But all the positions work as expected. I just needed to leave and return to test each one as I could only test one and then have to go and return.

Multiple popup page just errors out on windows with invalid container. That issue is also a bug that is present for me in main with current popup. Could be user error? Not sure. I don't use popup much. On Updating popup page clicking more and then clicking finish reset the original item to go again. Was that intended?

The Handle return result popup does not work as expected on IOS. It displays popup but does not show any response after closing. Neither touching outside popup or clicking on button initiates any visible response.

On PopupAnchorPage I have unexpected behavior. I can move the red X exactly once before having to leave page and return to move or click on popup again. The button in popup responds but does nothing.

On custom popup size and position the horizontal nd vertical options don't appear to do anything for me. Setting width and height does work 100 percent.

When leaving the page attempting to return to same page in windows fails to navigate to page. This issue is not a popup issue. Just mentioning it for reference in case anyone wants it fixed. It is an issue with other things like media element page to give an example.

This is an amazing start. I am pretty sure all of the issues I listed are compiled binding issues that are easy to fix and are the bane of anyone working with dotnet 9.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/views Issue/Discussion/PR that has to do with Views breaking change This label is used for PRs that include a breaking change pending documentation This feature requires documentation waiting for feedback Waiting for a response from the author or the core team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Proposal] Popup V2
5 participants