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

Missing support for .stationary touches #51

Open
OdNairy opened this issue Feb 15, 2023 · 3 comments
Open

Missing support for .stationary touches #51

OdNairy opened this issue Feb 15, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@OdNairy
Copy link

OdNairy commented Feb 15, 2023

Describe the bug
After two finger downs it is not possible to up single finger – both touches are ending

To Reproduce
Code to reproduce:

    func testBug() throws {
        try eventGenerator.wait(1)
        try eventGenerator.fingerDown([.rightThumb, .rightIndex],
                                      at: [
                                        CGPoint(x: 200, y: 400),
                                        CGPoint(x: 400, y: 400)
                                      ])
        try eventGenerator.wait(1)
        try eventGenerator.fingerUp([.rightThumb])
        try eventGenerator.wait(3)
        try eventGenerator.fingerUp([.rightIndex])
        try eventGenerator.wait(3)
    }

Expected behavior
Single finger released allowing to manipulate the second one.
I have a scenario where I do zooming then release one finger and starting to pan the map view.

Screenshots
If applicable, add screenshots to help explain your problem.
There is an extra framework to visualise touches with handling phases and locations via UIApplication.sendEvent. Circle animation starts when touch in the Ended phase was received.

hammer_two_fingers_one_release_bug.mov

Environment (please complete the following information):

  • Devices: iPhone 14 Pro, iPad mini 5
    • Simulator: iPad mini 6
  • OS: iOS 16.3.1
  • Xcode: 14.2

Additional context
UIApplication.sendEvent receives two UITouch events with the Ended phase.
Add any other context about the problem here.

Full UIApplication.sendEvent events report from sample code
Test Case '-[DebugAppTests.DebugAppTests testBug]' started (Iteration 1 of 3).
<UITouchesEvent: 0x60000331a490> timestamp: 178537 touches: {(
    <UITouch: 0x1288461a0> phase: Began tap count: 1 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: (null) ,
    <UITouch: 0x128838560> phase: Began tap count: 1 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: <MTKView: 0x12981e400; frame = (0 0; 1133 744); layer = <CAMetalLayer: 0x600000666e80>> location in window: {200, 400} previous location in window: {200, 400} location in view: {200, 400} previous location in view: {200, 400}
)}

2023-02-15 13:41:11.608328+0200 DebugApp[69948:3352821] [Window] Manually adding the rootViewController's view to the view hierarchy is no longer supported. Please allow UIWindow to add the rootViewController's view to the view hierarchy itself.
<UITouchesEvent: 0x60000331a490> timestamp: 178537 touches: {(
    <UITouch: 0x1288461a0> phase: Began tap count: 1 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: (null) ,
    <UITouch: 0x128838560> phase: Began tap count: 1 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: <MTKView: 0x12981e400; frame = (0 0; 1133 744); layer = <CAMetalLayer: 0x600000666e80>> location in window: {200, 400} previous location in window: {200, 400} location in view: {200, 400} previous location in view: {200, 400}
)}

2023-02-15 13:41:11.707522+0200 DebugApp[69948:3352821] [EventDispatcher] Found no UIEvent for backing event of type: 1; contextId: 0x91D53B81
<UITouchesEvent: 0x60000331a490> timestamp: 178538 touches: {(
    <UITouch: 0x1288461a0> phase: Ended tap count: 0 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: (null) ,
    <UITouch: 0x128838560> phase: Ended tap count: 0 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: <MTKView: 0x12981e400; frame = (0 0; 1133 744); layer = <CAMetalLayer: 0x600000666e80>> location in window: {200, 400} previous location in window: {200, 400} location in view: {200, 400} previous location in view: {200, 400}
)}

<UITouchesEvent: 0x60000331a490> timestamp: 178538 touches: {(
    <UITouch: 0x1288461a0> phase: Ended tap count: 0 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: (null) ,
    <UITouch: 0x128838560> phase: Ended tap count: 0 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: <MTKView: 0x12981e400; frame = (0 0; 1133 744); layer = <CAMetalLayer: 0x600000666e80>> location in window: {200, 400} previous location in window: {200, 400} location in view: {200, 400} previous location in view: {200, 400}
)}

2023-02-15 13:41:12.907412+0200 DebugApp[69948:3352821] [EventDispatcher] Found no UIEvent for backing event of type: 1; contextId: 0x91D53B81
@OdNairy OdNairy added the bug Something isn't working label Feb 15, 2023
@OdNairy
Copy link
Author

OdNairy commented Feb 15, 2023

For a comparison, on the iPad I see the following event when do release a single finger in two-finger gesture:

<UITouchesEvent: 0x28231e970> timestamp: 7343.81 touches: {(
    <UITouch: 0x10571a400> phase: Ended tap count: 0 force: 0.000 window: <UIWindow: 0x104009c20; frame = (0 0; 1024 768); gestureRecognizers = <NSArray: 0x281671ec0>; layer = <UIWindowLayer: 0x281671d10>> responder: (null) ,
    <UITouch: 0x105624910> phase: Stationary tap count: 1 force: 0.000 window: <UIWindow: 0x104009c20; frame = (0 0; 1024 768); gestureRecognizers = <NSArray: 0x281671ec0>; layer = <UIWindowLayer: 0x281671d10>> responder: (null) 
)}

With the Hammer simulation:

<UITouchesEvent: 0x60000331a490> timestamp: 178538 touches: {(
    <UITouch: 0x1288461a0> phase: Ended tap count: 0 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: (null) ,
    <UITouch: 0x128838560> phase: Ended tap count: 0 force: 0.000 window: <MBXFingerTipWindow: 0x11fe07840; baseClass = UIWindow; frame = (0 0; 1133 744); gestureRecognizers = <NSArray: 0x60000066a6d0>; layer = <UIWindowLayer: 0x60000066a520>> responder: <MTKView: 0x12981e400; frame = (0 0; 1133 744); layer = <CAMetalLayer: 0x600000666e80>> location in window: {200, 400} previous location in window: {200, 400} location in view: {200, 400} previous location in view: {200, 400}
)}

It seems that Hammer have to simulate still active touches with stationary phase and not to ignore them.

@OdNairy
Copy link
Author

OdNairy commented Feb 15, 2023

My early investigation results represents that sending only .stationary phased touches in the fingerUp method is the correct way to fix the issue and preserve existing functionality.
POC implementation:

    public func fingerUp(_ indices: [FingerIndex?] = .automatic) throws {
        let indices = try self.fillExistingFingerIndices(indices, withMinimum: 1)
        let endingFingers = self.activeTouches.fingers.map { finger in
            return FingerInfo(fingerIndex: finger.fingerIndex,
                              location: finger.location,
                              phase: indices.contains(finger.fingerIndex) ?  .ended : .stationary,
                              pressure: 0, twist: 0, majorRadius: kDefaultRadius, minorRadius: kDefaultRadius)
        }

        try self.sendEvent(hand: HandInfo(fingers: endingFingers.filter({ $0.phase == .stationary })))
    }

@OdNairy
Copy link
Author

OdNairy commented Feb 15, 2023

From the production-ready implementation it would be a challenge to correctly remove ended touches as we do report only the stationary one so no downstream code for cleanup would be called.

@OdNairy OdNairy changed the title Release single finger after two-finger gesture leads to release of both Missing support for .stationary touches Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant