Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: Allow touch Event that moves 10px. #74

Merged
merged 9 commits into from
Aug 2, 2017
Merged

fixed: Allow touch Event that moves 10px. #74

merged 9 commits into from
Aug 2, 2017

Conversation

tosaka07
Copy link
Contributor

@tosaka07 tosaka07 commented Aug 2, 2017

Content

Buttons allows touch Event that moves 10px.

@@ -26,6 +26,7 @@ const isSupportTouch = 'ontouchstart' in document;
const EVENT_TOUCHSTART = isSupportTouch ? 'touchstart' : 'mousedown';
const EVENT_TOUCHMOVE = isSupportTouch ? 'touchmove' : 'mousemove';
const EVENT_TOUCHEND = isSupportTouch ? 'touchend' : 'mouseup';
const TOUCH_ALLOW_RANGE = 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const distanceY = e.clientY - touchY;
const hypotenuse = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
if (hypotenuse <= TOUCH_ALLOW_RANGE) {
console.log('yes');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ゴミconsoleが残ってるので消しちゃおう

const distanceX = e.clientX - touchX;
const distanceY = e.clientY - touchY;
const hypotenuse = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
if (hypotenuse <= TOUCH_ALLOW_RANGE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

例外やイレギュラーケースに対する処理を序盤に記述してから正常系に対する処理を記述する、って書き方が良いとされているよ◎

// BAD
foo(obj) {
  if (obj.a && obj.b && !obj.c) {
    console.log('OK');
  }
}
// GOOD
foo(obj) {
  if (!obj.a) {
    return;
  }
  if (!obj.b) {
    return;
  }
  if (obj.c) {
    return;
  }
  console.log('OK');
}

// bind済みであれば何もしない。
if (!!elm.getAttribute('touchevents')) {
return;
}

const touchStartEventId = closureEventListener.add(elm, EVENT_TOUCHSTART, e => {
e.stopPropagation();
touchX = e.clientX;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.clientX これはデスクトップPC等のマウス系操作が行われる環境では使用可能なプロパティだけど、モバイルデバイス等のタッチ系操作が行われる環境では使用可能だろうか??

e.currentTarget.classList.add('hover');
});

const touchMoveEventId = closureEventListener.add(elm, EVENT_TOUCHMOVE, e => {
e.stopPropagation();
const isPressed = e.currentTarget.classList.contains('hover');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既存コードが削除されてるけど、意図的な削除だろうか?

@cathcheeno
Copy link
Contributor

問題解決へのアプローチはOKっす◎
が、,「hoverのON/OFF状態」と「クリック可能/不可能状態」の2間にズレが生じているかと。
i.e. 見た目上はhover状態になっているのに、指をマウス(画面)から離すと何も起きない(反応しない)

口頭でstartとend時の座標を参照すればOKって伝えたけど、↑のケースに対応するためにmoveを上手に活用する必要ありだね。。ごめんw

e.currentTarget.classList.add('hover');
});

const touchMoveEventId = closureEventListener.add(elm, EVENT_TOUCHMOVE, e => {
e.stopPropagation();
const isPressed = e.currentTarget.classList.contains('hover');
if (!isPressed) {
e.currentTarget.classList.remove('hover');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要かな

// bind済みであれば何もしない。
if (!!elm.getAttribute('touchevents')) {
return;
}

const touchStartEventId = closureEventListener.add(elm, EVENT_TOUCHSTART, e => {
e.stopPropagation();
if (isSupportTouch) {
console.log(e.touches[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consoleを消す。
eslintでconsole設定入れるとか。

@tosaka07 tosaka07 merged commit 9e82f74 into develop Aug 2, 2017
@tosaka07 tosaka07 deleted the issues/66 branch August 2, 2017 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants