Skip to content

Commit 0d4f048

Browse files
committed
Made ImageMask moveable and it's move with image now
1 parent f5b0271 commit 0d4f048

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/ImageCanvas/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export const ImageCanvas = ({
459459
{...mouseEvents}
460460
>
461461
<>
462-
{mask && <ImageMask maskVersion={maskVersion} imageData={mask} />}
462+
{mask && <ImageMask maskVersion={maskVersion} videoPlaying={videoPlaying} imagePosition={imagePosition} imageData={mask} />}
463463
<canvas className={classes.canvas} ref={canvasEl} />
464464
<VideoOrImageCanvasBackground
465465
videoPlaying={videoPlaying}

src/ImageMask/index.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// @flow
22

33
import React, { useState, useEffect, useMemo } from "react"
4-
5-
export default ({ imageData, maskVersion, opacity = 0.5 }) => {
4+
// videoPlaying={videoPlaying}
5+
// imagePosition={imagePosition}
6+
// mouse-events -> none
7+
export default ({ imageData, imagePosition, videoPlaying, maskVersion, opacity = 0.5, zIndex = 999, position = 'absolute'}) => {
68
const [canvasRef, setCanvasRef] = useState(null)
79

810
useEffect(() => {
@@ -11,7 +13,25 @@ export default ({ imageData, maskVersion, opacity = 0.5 }) => {
1113
context.putImageData(imageData, 0, 0)
1214
}, [canvasRef, imageData, maskVersion])
1315

14-
const style = useMemo(() => ({ opacity }), [opacity])
16+
const style = useMemo(() => {
17+
let width = imagePosition.bottomRight.x - imagePosition.topLeft.x
18+
let height = imagePosition.bottomRight.y - imagePosition.topLeft.y
19+
return {
20+
left: imagePosition.topLeft.x,
21+
top: imagePosition.topLeft.y,
22+
width: isNaN(width) ? 0 : width,
23+
height: isNaN(height) ? 0 : height,
24+
zIndex,
25+
position
26+
}
27+
}, [
28+
imagePosition.topLeft.x,
29+
imagePosition.topLeft.y,
30+
imagePosition.bottomRight.x,
31+
imagePosition.bottomRight.y,
32+
zIndex,
33+
position
34+
])
1535

1636
return (
1737
<canvas

0 commit comments

Comments
 (0)