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

Add method to MacawView to find node at specified location #285

Closed
AdrianLoer opened this issue Mar 18, 2018 · 3 comments
Closed

Add method to MacawView to find node at specified location #285

AdrianLoer opened this issue Mar 18, 2018 · 3 comments
Milestone

Comments

@AdrianLoer
Copy link

I am rolling my own scrollView with a Macaw view at its center and do not yet understand everything about events in swift. It's possible I broke something somewhere UIView related:

When I set a onTouchesMoved handler on multiple node elements only the one on the first node touched will be triggered.

Is there a way to get this right so that I can get a continuous stream of nodes that are under the finger's location?

Or am I doing something wrong and that should work out of the box? I used the PeriodicTable example and could not get it to work there either

@ystrot
Copy link
Member

ystrot commented Mar 19, 2018

Hey Adrian,

Yes, that's how move events work. When you touch one node and move your finger, all move events will be delivered to this first node. If you want to detect node under the finger then you need to add listener on MacawView and found which node selected manually.

@AdrianLoer
Copy link
Author

AdrianLoer commented Mar 19, 2018

Thank you for the quick response, great work you are doing here

Use case is that I want to highlight different nodes as I drag along. I now added the following to the MacawView

public func findNodeAt(loc: CGPoint) -> Node? {
        
        guard let renderer = renderer else {
            return nil
        }
        var foundNode: Node? = .none
        localContext { ctx in
            foundNode = renderer.findNodeAt(location: loc, ctx: ctx)
        }
        return foundNode
    }

This is not perfect and mostly works because I have an exported SVG from Sketch with proper IDs to discard unwanted events on nodes. For me right now its enough, touch locations are captured on the parent UIView anyways.

But due to the private nature of involved properties I had to modify MacawView at source level.
If there is a better way any information is appreciated.

Or maybe a general hit test function could be published similar to mine above?

@ystrot
Copy link
Member

ystrot commented Mar 19, 2018

Yep, good point. We need to add such a public function to MacawView.

f3dm76 added a commit to f3dm76/Macaw that referenced this issue Apr 4, 2018
@ystrot ystrot changed the title Recognize touchMove events that started outside of the target element Add method to MacawView to find node at specified location Apr 4, 2018
@ystrot ystrot added this to the 0.9.2 milestone Apr 4, 2018
@ystrot ystrot closed this as completed in 10996a4 Apr 4, 2018
ystrot added a commit that referenced this issue Apr 4, 2018
Fix #285: Add method to MacawView to find node at specified location
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

2 participants