Change the timing of Measure method call when SwipeControl is included #2087
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.
In this PR, we will fix it so that SwipeView will work if it is included under the Popup's Content on Windows.
Description of Change
The Measure method is called when measuring the Popup size, but if SwipeView is included, an AccessViolationException will occur on Windows. The .NET MAUI SwipeView control becomes SwipeControl on the platform side, but if the Measure method of SwipeControl is called when the IsLoaded property is false, an AccessViolationException will occur.
If the Popup's content includes SwipeControl, you need to modify it so that the Measure method is called when the SwipeControl's IsLoaded property is true.
This PR was created based on the idea of .NET MAUI PR #6220.
Below are the changes.
The code below adds and removes the SwipeControl's Loaded event when the SwipeControl is included in the popup's content.
[src\CommunityToolkit.Maui.Core\Handlers\Popup\PopUpHandler.windows.cs]
The code below prevents the Measure method from being called if the Popup's Content includes SwipeControl and the SwipeControl's IsLoaded property is false. If the Popup content does not include SwipeControl, call the Measure method.
[src\CommunityToolkit.Maui.Core\Views\Popup\PopupExtensions.windows.cs]
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information
Below are the verification results.
I used the following layout in the case where the Popup's content includes SwipeControl.
The execution result is shown below.
2024-08-02.12-38-23.mp4
You can see that SwipeView is working. AccessViolationException is not occurring when displaying the Popup.
On Windows, SwipeView does not work with mouse interaction. It works with touch movements only.
dotnet/maui#6152 (comment)
Below are the verification results using the Community Toolkit sample app.
This is a case where the Popup content does not include SwipeControl.
Toolkit.Features.2024-08-02.12-57-06.mp4
You can see that the Popup is displayed at the intended size.