[iOS] Fix for Unable to Update iOS SwipeGesture Direction at Runtime #30165
[iOS] Fix for Unable to Update iOS SwipeGesture Direction at Runtime #30165jfversluis merged 6 commits intodotnet:inflight/currentfrom
Conversation
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for updating the direction of a SwipeGestureRecognizer at runtime on iOS by wiring up a property-changed handler, provides a sample page to demonstrate the behavior, and introduces a UI test to verify it.
- Add property change listener in
GesturePlatformManager.iOSto update the native recognizer’s direction immediately. - Create a sample
Issue17010page in HostApp to toggle swipe direction and update a label. - Add a UITest in
TestCases.Shared.Teststo validate dynamic swipe direction changes.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue17010.cs | UI test covering dynamic swipe direction updates |
| src/Controls/tests/TestCases.HostApp/Issues/Issue17010.cs | Sample page demonstrating runtime swipe direction toggle |
| src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs | Hook up SwipeGestureRecognizer.PropertyChanged to update native direction |
|
|
||
| [Test] | ||
| [Category(UITestCategories.Gestures)] | ||
| public void SwipeGestureDirectionShouldChangeAtRuntime() |
There was a problem hiding this comment.
The test is failing on Catalyst:
Assert.That(App.WaitForElement("DirectionLabel").GetText(), Is.EqualTo("Direction: Left"))
Expected string length 15 but was 16. Strings differ at index 11.
Expected: "Direction: Left"
But was: "Direction: Right"
----------------------^
There was a problem hiding this comment.
@jsuarezruiz, I have restricted the test case for Mac because swipe actions are not supported in Appium on MacCatalyst. Please let me know if you have any concerns.
There was a problem hiding this comment.
Mnnn, there is a specific implementation using the Appium Mac Driver to execute swipe actions https://github.com/dotnet/maui/blob/4dc9f393acbe8a697a850aa99d3fbfeab36964e0/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs
What is the current behavior? Does nothing, wrong swipe direction or other issue?
There was a problem hiding this comment.
@jsuarezruiz, The swipe operation is not working properly on MacCatalyst. Please find the below video for your reference, which demonstrates the issue. Due to this behavior, I have restricted the test case for MacCatalyst similar to below testcase.
SwipeIssue.mp4
There was a problem hiding this comment.
Thanks for the feedback, should be fixed by #30436
There was a problem hiding this comment.
@jsuarezruiz, I have tested the test case using the code provided in this PR (#30436). The swipe action on Mac is now working as expected after applying the changes.
09b7f91 to
7f958ab
Compare
|
/rebase |
a517afb to
6b1a532
Compare
|
/rebase |
6b1a532 to
8b5e66a
Compare
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…ognizer direction updates with native recognizer at runtime.
…30165) * fix-17010-Made changes to iOS gesture manager to sync SwipeGestureRecognizer direction updates with native recognizer at runtime. * fix-17010-Testcase added. * fix-17010-Modified the Testcase and added iOS and Android snapshots. * fix-17010-Modified the testcase based on Assert check and removed the snapshots. * fix-17010-Restricted test for Mac. * fix-17010-Testcase updated.
…30165) * fix-17010-Made changes to iOS gesture manager to sync SwipeGestureRecognizer direction updates with native recognizer at runtime. * fix-17010-Testcase added. * fix-17010-Modified the Testcase and added iOS and Android snapshots. * fix-17010-Modified the testcase based on Assert check and removed the snapshots. * fix-17010-Restricted test for Mac. * fix-17010-Testcase updated.
…30165) * fix-17010-Made changes to iOS gesture manager to sync SwipeGestureRecognizer direction updates with native recognizer at runtime. * fix-17010-Testcase added. * fix-17010-Modified the Testcase and added iOS and Android snapshots. * fix-17010-Modified the testcase based on Assert check and removed the snapshots. * fix-17010-Restricted test for Mac. * fix-17010-Testcase updated.
…30165) * fix-17010-Made changes to iOS gesture manager to sync SwipeGestureRecognizer direction updates with native recognizer at runtime. * fix-17010-Testcase added. * fix-17010-Modified the Testcase and added iOS and Android snapshots. * fix-17010-Modified the testcase based on Assert check and removed the snapshots. * fix-17010-Restricted test for Mac. * fix-17010-Testcase updated.
…30165) * fix-17010-Made changes to iOS gesture manager to sync SwipeGestureRecognizer direction updates with native recognizer at runtime. * fix-17010-Testcase added. * fix-17010-Modified the Testcase and added iOS and Android snapshots. * fix-17010-Modified the testcase based on Assert check and removed the snapshots. * fix-17010-Restricted test for Mac. * fix-17010-Testcase updated.
…30165) * fix-17010-Made changes to iOS gesture manager to sync SwipeGestureRecognizer direction updates with native recognizer at runtime. * fix-17010-Testcase added. * fix-17010-Modified the Testcase and added iOS and Android snapshots. * fix-17010-Modified the testcase based on Assert check and removed the snapshots. * fix-17010-Restricted test for Mac. * fix-17010-Testcase updated.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root cause
The issue was caused by a missing property change handler in the iOS GesturePlatformManager. When the SwipeGestureRecognizer.Direction property was changed at runtime in .NET MAUI applications, the change only occurred in the managed code layer. The native iOS UISwipeGestureRecognizer retained its original direction and was not updated accordingly.
As a result, if the initial swipe direction was set to "Up" and later changed to "Down" programmatically, the iOS device would still only recognize "Up" swipes. "Down" swipes were completely ignored, making dynamic gesture behavior on iOS ineffective.
Description of Issue Fix
The fix involves introducing a property change handler that monitors changes to the SwipeGestureRecognizer.Direction property. When a direction change is detected, the handler immediately updates the corresponding native iOS UISwipeGestureRecognizer with the new direction.
With this fix, swipe gesture directions can now be dynamically updated at runtime, and changes take effect immediately on iOS devices.
Tested the behavior in the following platforms.
Issues Fixed
Fixes #17010
Output
BeforeFix-SwipeGestureRecognizer.mov
AfterFix-SwipeGestureRecognizer.mov