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

Screen edge pan gesture is not recognized #1281

Open
Fitzmaz opened this issue Apr 4, 2023 · 8 comments
Open

Screen edge pan gesture is not recognized #1281

Fitzmaz opened this issue Apr 4, 2023 · 8 comments

Comments

@Fitzmaz
Copy link
Contributor

Fitzmaz commented Apr 4, 2023

Description

I am encountering difficulty in activating the built-in interactivePopGestureRecognizer. I have attempted to simulate a screen edge pan gesture using the dragFromPoint:displacement:steps: method, but the gesture is not being recognized.

Code Snippet

CGFloat majorSwipeDisplacement = UIScreen.mainScreen.bounds.size.width * 0.5;
CGFloat minorSwipeDisplacement = 5;
KIFDisplacement displacement = CGPointMake(majorSwipeDisplacement, minorSwipeDisplacement);

[view dragFromPoint:CGPointMake(0.5, 150) displacement:displacement steps:20];

Environment

  • iOS version: 14.7, 16.1
  • Xcode version: 14.1
@Fitzmaz
Copy link
Contributor Author

Fitzmaz commented Apr 4, 2023

As mentioned in Pull Request #776, interactivePopGestureRecognizer was able to be triggered successfully. Looks like something might have changed in the iOS SDK.

@dostrander
Copy link
Collaborator

@Fitzmaz I'd possibly try more steps and possibly start at 10-20 for x and middle of the screen for y. The maybe jump the steps to 100?

I don't have time currently to investigate this right now but if you can't repro or fix I'll try to get to it ASAP!

\cc @steve-sun-me

@Fitzmaz
Copy link
Contributor Author

Fitzmaz commented Apr 5, 2023

@dostrander Thanks for the advices. I've experimented with various parameters, but none of them seem to work. So I don't think it's a problem with the parameters themselves.

Then, I did some digging and compared the UITouch object of a normal pan gesture with that of a screen edge pan gesture. It turns out that the touch object of the screen edge pan gesture has a property called _edgeType that is set, while the touch object of the normal pan gesture does not have this property set.

Regarding the KIF framework, touch objects are generated within the dragPointsAlongPaths: method. I discovered that if I manually set the _edgeType property of the touch object to a value of 4, the screen edge pan gesture is recognized successfully. Maybe we should add a new method to the tester that can simulate a screen edge pan gesture and automatically set the touch object's property to the right value?

@dostrander
Copy link
Collaborator

@Fitzmaz that seems like a decent solution to me.

One thing i find a little strange is why the edge pan gesture doesn't pick up the drag as it would normally? I'm curious how it would normally set that edge type under the hood

@Fitzmaz
Copy link
Contributor Author

Fitzmaz commented Apr 6, 2023

@dostrander The _edgeType property was introduced on iOS 7 along with the UIScreenEdgePanGestureRecognizer class. Unfortunately, I don't have an old device to test the behavior on iOS 7. I have only tested on some devices and obtained the following results:

  _edgeType == 0 _edgeType == 1 _edgeType == 2 _edgeType == 4
iPhone 6, 11.3.1 ✅(default for edge pan)
iPhone SE2, 15.0 ✅(default for edge pan)
iPhone X, 14.7 ✅(default for edge pan)
iPhone 13, 15.6 ✅(default for edge pan)
iPhone 14, 16.1 ✅(default for edge pan)

Based on these results, I can draw a few conclusions:

  1. It seems that the edge pan gesture no longer picks up the drag since iOS 11, and possibly even earlier versions.
  2. Setting the _edgeType property to either value 1 or value 4 makes the touch recognized.
  3. The default value for an edge pan on iPhone models with a notch is 4, while on models with a home button it's 1.

@dostrander
Copy link
Collaborator

Thanks for the info. I'm still wondering if there is a way to have iOS detect the edge pan without having to set a variable on some underlying object. I would expect the way you drag that they'd detect it 🤔

@justinseanmartin
Copy link
Contributor

I think Apple does for real gestures, but I'd guess at a lower level than how KIF synthesizes UITouch events.

@Fitzmaz
Copy link
Contributor Author

Fitzmaz commented Jun 29, 2023

@dostrander Normally, the _edgeType property is set inside the _UITouchSetBasicTouchPropertiesFromEvent function.

* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 22.1
  * frame #0: 0x000000010e2332c4 UIKitCore`-[UITouch _setEdgeType:]
    frame #1: 0x000000010e23378c UIKitCore`_UITouchSetBasicTouchPropertiesFromEvent + 944
    frame #2: 0x000000010e23dea0 UIKitCore`____updateTouchesWithDigitizerEventAndDetermineIfShouldSend_block_invoke.27 + 1576
    frame #3: 0x000000010e24f0f4 UIKitCore`_UIEventHIDEnumerateChildren + 160
    frame #4: 0x000000010e241920 UIKitCore`__dispatchPreprocessedEventFromEventQueue + 2232
    frame #5: 0x000000010e244774 UIKitCore`__processEventQueue + 5612

As @justinseanmartin mentioned, KIF synthesizes UITouch and the underlying IOHIDEvent, which means that the _UITouchSetBasicTouchPropertiesFromEvent function won't be called at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants