Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When I try to show the Popup by calling the PopupShow method inside the NavigatedTo event, it doesn't show up.
Same if I try to show the Popup in the OnAppearing event. I was getting the below exception message.
The location where the exception occurred is the code below called in the CreatePopup method of PopupExtensions.shared.cs.
The Get MauiContext method was implemented like this:
The page's Handler is null during the OnAppearing and OnNavigatedTo event timings.
Therefore, MauiContext cannot be obtained. The timing that the Handler of the page can
acquire is the Loaded event.
The implementation before the fix calls CreateAndShowPopup method in the NavigatedTo event.
When the Popup is displayed in the OnAppearing event, the Handler of the page is null, so the exception above is raised.
When the Popup is displayed in the OnNavigatedTo event, the CreateAndShowPopup method is not called because the registration for the NavigatedTo event is performed within the Page's OnNavigatedTo event.
So I changed the CreateAndShowPopup method to be called in the Loaded event instead of the NavigatedTo event.
The Loaded event is a later event than the OnAppearing and OnNavigatedTo events, and the page's Handler is never null.
Description of Change
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information
page.IsPlatformEnabled is True only in the Loaded event. OnAppearing event, OnNavigatedTo event,
page.IsPlatformEnabled is False. In the OnLoaded event the CreateAndShowPopup method is called
directly, but in the OnAppearing and OnNavigatedTo events it is called within the Loaded event.
Below is the execution result.
[Show the popup inside the OnAppearing event on Android]
Android.Emulator.-.pixel_2_-_api_30_5554.2023-06-09.12-02-19.mp4
[Show the popup inside the OnNavigatedTo event on Android]
Android.Emulator.-.pixel_2_-_api_30_5554.2023-06-09.12-03-45.mp4
[Show the popup inside the Loaded event on Android]
Android.Emulator.-.pixel_2_-_api_30_5554.2023-06-09.12-05-32.mp4
[Show the popup inside the OnAppearing event on iOS]
A_RPReplay_Final1686281776.MP4
[Show the popup inside the OnNavigatedTo event on iOS]
N_RPReplay_Final1686281148.MP4
[Show the popup inside the Loaded event on iOS]
L_RPReplay_Final1686280764.MP4