react-native-canvas icon indicating copy to clipboard operation
react-native-canvas copied to clipboard

CanvasRenderingContext2D.isPointInPath is not working

Open HuriHuchi opened this issue 3 years ago • 1 comments

CanvasRenderingContext2D.isPointInPath is not working. Whenever I try to use it, I get the error as in the image below.

Does anyone know about this issue?

Below is an example code similar to the code I wrote.

  const Component = () => {

  const handleCanvas = (canvas: Canvas) => {
    if (!canvas) return
    const ctx = canvas.getContext('2d')

    canvas.width = WINDOW_WIDTH
    canvas.height = WINDOW_HEIGHT

    const circle = new Path2D(canvas)
    circle.arc(200, 200, 50, 0, 2 * Math.PI)
    ctx.fillStyle = 'red'
    ctx.fill(circle)

    /** below code is not working */
    ctx.isPointInPath(210, 210, 'nonzero', circle)
  }
  return (
    <>
      <Canvas ref={handleCanvas} />
    </>
  )
}

aa

HuriHuchi avatar Oct 07 '21 08:10 HuriHuchi

This is not a bug, the syntax is invalid, as of the MDN specification: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/isPointInPath

isPointInPath(x, y)
isPointInPath(x, y, fillRule)
isPointInPath(path, x, y)
isPointInPath(path, x, y, fillRule)

ctx.isPointInPath(210, 210, 'nonzero', circle) would expect that the first argument (210) is an instance of Path2D, which it isn't.

nora-soderlund avatar Oct 05 '22 12:10 nora-soderlund