terrylinla / react-native-sketch-canvas

A React Native component for drawing by touching on both iOS and Android.
MIT License
693 stars 450 forks source link

enhancement: isPointOnPath method #70

Closed ShaMan123 closed 5 years ago

ShaMan123 commented 6 years ago

I'm using SketchCanvas in 2 ways:


<SketchCanvas touchEnabled={this.state.mode}  />

changeMode(shouldPaint){
  this.setState({ mode: shouldPaint });
}

if touchEnabled === true => the user paints if touchEnabled === false => the user touches SketchCanvas in order to pick a path.

This is why I'm trying to detect if a user touches a path while touchEnabled prop is set to false. Is there a way?

Managed to write a function that returns the pathId of a touched path. However it doesn't work properly because of the inaccuracy of the touch and because of the width of the path. Any idea how to detect a touch made on a path that is not exactly on a given point of the path.

I'm clueless regarding native code :(

ShaMan123 commented 6 years ago

check out this repo!

creambyemute commented 5 years ago

@ShaMan123 Check out my (movable, rotatable and scalable) shapes branch on my fork. It's only working on android for now (check example 1 of the example app), but starting on the iOS part soon.

It's mostly done in native but we could move some of the logic to the JS-side in the end which would help us both :-).

Aside from that, try to work with an offset (hitslop) so you can detect even when the user slightly misses the line.

ShaMan123 commented 5 years ago

@creambyemute it says your branch is even with master. I've implemented a rough android touch detector in my fork. Not entirely happy with it because it detects a general touch on a path in the canvas. It doesn't detect a certain path unfortunately. Tried other methods to achieve this with no luck. Have no experience writing in iOS but found some documentation regarding path touch deection. I will soon start working on it.

creambyemute commented 5 years ago

@ShaMan123 thats why I said to look at my branch :P. I didn't work on master but on a separate branch

ShaMan123 commented 5 years ago

changed issue title and method to isPointOnPath(x, y, pathId, callback)

ShaMan123 commented 5 years ago

closing. see PR #99