이 문서에서는 React 웹 앱을 사용하여 Android에서 터치 이벤트를 처리하는 방법을 설명합니다
아래에서 React를 사용하여 Android에서 터치 이벤트를 처리하는 방법을 확인하세요.
React는 다음을 사용하여 Android 터치 이벤트를 캡처합니다: onTouchStart; onTouchMove; onTouchend
아래는 React 웹 앱 내에서 Android 터치 이벤트를 처리하는 방법의 예입니다
import React from 'react';
export default class EventComponent extends React.Component {
constructor(props) {
super(props);
this._onTouchStart = this._onTouchStart.bind(this);
this._onTouchMove = this._onTouchMove.bind(this);
this._onTouchEnd = this._onTouchEnd.bind(this);
this.state = { swiped: false };
this._swipe = {};
this.minDistance = 50;
}
_onTouchStart(e) {
const touch = e.touches[0];
this._swipe = { x: touch.clientX };
this.setState({ swiped: false });
}
_onTouchMove(e) {
if (e.changedTouches && e.changedTouches.length) {
const touch = e.changedTouches[0];
this._swipe.swiping = true;
}
}
_onTouchEnd(e) {
const touch = e.changedTouches[0];
const absX = Math.abs(touch.clientX - this._swipe.x);
if (this._swipe.swiping && absX this.minDistance ) {
this.props.onSwiped && this.props.onSwiped();
this.setState({ swiped: true });
}
this._swipe = {};
}
render() {
return (
{`Component-${this.state.swiped ? 'swiped' : ''}`}
); } }
Please report any broken links by emailing support@elotouch.com and include a link to the knowledge article