Skip to content

[iOS] Fix for Unable to Update iOS SwipeGesture Direction at Runtime #30165

Merged
jfversluis merged 6 commits intodotnet:inflight/currentfrom
BagavathiPerumal:fix-17010
Dec 1, 2025
Merged

[iOS] Fix for Unable to Update iOS SwipeGesture Direction at Runtime #30165
jfversluis merged 6 commits intodotnet:inflight/currentfrom
BagavathiPerumal:fix-17010

Conversation

@BagavathiPerumal
Copy link
Contributor

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.

  • Windows
  • Mac
  • iOS
  • Android

Issues Fixed

Fixes #17010

Output

Before Issue Fix After Issue Fix
BeforeFix-SwipeGestureRecognizer.mov
AfterFix-SwipeGestureRecognizer.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jun 24, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BagavathiPerumal BagavathiPerumal marked this pull request as ready for review June 26, 2025 04:40
Copilot AI review requested due to automatic review settings June 26, 2025 04:40
@BagavathiPerumal BagavathiPerumal requested a review from a team as a code owner June 26, 2025 04:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.iOS to update the native recognizer’s direction immediately.
  • Create a sample Issue17010 page in HostApp to toggle swipe direction and update a label.
  • Add a UITest in TestCases.Shared.Tests to 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()
Copy link
Contributor

Choose a reason for hiding this comment

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

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"
----------------------^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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.

// On Catalyst, Swipe actions not supported in Appium.

SwipeIssue.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the feedback, should be fixed by #30436

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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.

@jsuarezruiz
Copy link
Contributor

/rebase

@jfversluis
Copy link
Member

/rebase

@jfversluis
Copy link
Member

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis jfversluis changed the base branch from main to inflight/current December 1, 2025 10:56
@jfversluis jfversluis merged commit a3e314a into dotnet:inflight/current Dec 1, 2025
1 of 36 checks passed
@jfversluis jfversluis added this to the .NET 10.0 SR3 milestone Dec 1, 2025
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…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.
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…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.
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…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.
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…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.
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…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.
github-actions bot pushed a commit that referenced this pull request Dec 5, 2025
…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.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-gestures Gesture types community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to Update iOS SwipeGesture Direction at Runtime

4 participants