0
I have the following Javascript code, but it does not capture touch commands, anyone knows why? If I’m using some incorrect syntax or something?
private capturarEventoTouch(componente: HTMLCanvasElement) {
// Mousedown = Clique esquerdo
fromEvent(componente, 'touchstart')
.pipe(
switchMap((e) => {
return fromEvent(componente, 'touchmove')
.pipe(
// Mouseup = Release do clique esquerdo
takeUntil(fromEvent(componente, 'touchend')),
// Mouseleave = Quando o mouse sai da área do Componente
takeUntil(fromEvent(componente, 'touchleave')),
pairwise()
);
})
)
.subscribe((res: [TouchEvent, TouchEvent]) => {
const rect = componente.getBoundingClientRect();
const posicaoAnterior = {
x: res[0].touches[0].clientX - rect.left,
y: res[0].touches[0].clientY - rect.top
};
const posicaoAtual = {
x: res[1].touches[1].clientX - rect.left,
y: res[1].touches[1].clientY - rect.top
};
this.desenharNoCanvas(posicaoAnterior, posicaoAtual);
});
}
if you put a console log it doesn’t even enter the subscribe??
– Eduardo Vargas
Edu he enters the subscribe, but now says clientX is Undefined ...
– Thales Henrique
res is Undefined too? Tries to generate a stackblitz to be easier to answer
– Eduardo Vargas