onTouchMove stops mid zoom
See original GitHub issueMy demo (https://codesandbox.io/embed/react-konva-basic-demo-hh582) works but live.
But I get onTouchMove running several times then it stops for some reason. I’ve narrowed it down to something to do with my Group component. I think the state causes a rerender which seems to throw off the component but for scale up and down with button I need to use state. Any way around this?
<Group
rotation={this.state.rotation}
x={x_pos}
y={y_pos}
draggable
scaleX={this.state.scale}
scaleY={this.state.scale}
ref={node => {
this.groupRef = node;
}}
dragBoundFunc={pos => {
const rotDegrees = rotation % 360;
const upright =
rotDegrees == 0 || rotDegrees == 180 ? true : false;
const top = upright
? this.state.imageHeight / 2
: this.state.imageWidth / 2;
const left = upright
? this.state.imageWidth / 2
: this.state.imageHeight / 2;
const bottom = upright
? window.innerHeight - 56 - this.state.imageHeight / 2
: window.innerHeight - 56 - this.state.imageWidth / 2; // here also we've subtract topbar height from canvas container
const right = upright
? this.state.width - this.state.imageWidth / 2
: this.state.width - this.state.imageHeight / 2;
let x = pos.x;
let y = pos.y;
if (pos.y > bottom) {
y = bottom;
} else if (pos.y < top) {
y = top;
}
if (pos.x > right) {
x = right;
} else if (pos.x < left) {
x = left;
}
return {
x,
y
};
}}
onTouchMove={res => {
const stage = res.currentTarget;
var touch1 = res.evt.touches[0];
var touch2 = res.evt.touches[1];
if (touch1 && touch2) {
var dist = this.getDistance(
{
x: touch1.clientX,
y: touch1.clientY
},
{
x: touch2.clientX,
y: touch2.clientY
}
);
if (!this.lastDist) {
this.lastDist = dist;
}
console.log("scale state:", this.state.scale);
var scale = (stage.scaleX() * dist) / this.lastDist;
this.setScale(scale);
console.log("calculated scale:", scale);
this.lastDist = dist;
}
}}
onTouchEnd={() => {
this.lastDist = 0;
}}
>
handleScalePlus = () => {
if (this.mounted) {
let scale = this.state.scale + 0.1;
this.setState({
scale: scale > 3 ? 3 : scale
});
}
};
handleScaleMinus = () => {
if (this.mounted) {
let scale = this.state.scale - 0.1;
this.setState({
scale: scale < 1 ? 1 : scale
});
}
};
setScale = scale => {
if (this.mounted) {
if (scale < 3 && scale > 1) {
this.setState({
scale
});
}
}
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
android: move a view on touch move (ACTION_MOVE)
I'd like to do a simple control: a container with a view inside. If I touch the container and I move the finger,...
Read more >Chrome mobile > touchmove > setTimeout (timeout function ...
Interesting is other issue that I have noticed, sporadically when I zoom-in and than zoom-out the drawing speed increases, and timeout begins ...
Read more >Element: touchmove event - Web APIs | MDN
The touchmove event is fired when one or more touch points are moved along the ... Values below 1.0 indicate an inward pinch...
Read more >Injections Samples - ChartIQ SDK Documentation
By default, if you click (or touch) and drag over the y-axis, the chart will zoom vertically. This override disables that functionality both...
Read more >Map | Mapbox GL JS
If bounds is specified, it overrides center and zoom constructor options. options.boxZoom. boolean. default: true. If true , the "box ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Or attach manually:
On my device (ios safari) multitouch scale with zoom whole page (browser behavior). But I guess we need to prevent it. I created this demo: https://codesandbox.io/s/react-konva-multitouch-scale-demo-dtci9
res.evt.preventDefault();
It works ok for me.