-
Notifications
You must be signed in to change notification settings - Fork 52
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
Conversation
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/core/mixin.js
Outdated
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ゴミconsoleが残ってるので消しちゃおう
src/core/mixin.js
Outdated
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) { |
There was a problem hiding this comment.
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');
}
src/core/mixin.js
Outdated
// bind済みであれば何もしない。 | ||
if (!!elm.getAttribute('touchevents')) { | ||
return; | ||
} | ||
|
||
const touchStartEventId = closureEventListener.add(elm, EVENT_TOUCHSTART, e => { | ||
e.stopPropagation(); | ||
touchX = e.clientX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.clientX
これはデスクトップPC等のマウス系操作が行われる環境では使用可能なプロパティだけど、モバイルデバイス等のタッチ系操作が行われる環境では使用可能だろうか??
src/core/mixin.js
Outdated
e.currentTarget.classList.add('hover'); | ||
}); | ||
|
||
const touchMoveEventId = closureEventListener.add(elm, EVENT_TOUCHMOVE, e => { | ||
e.stopPropagation(); | ||
const isPressed = e.currentTarget.classList.contains('hover'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
既存コードが削除されてるけど、意図的な削除だろうか?
問題解決へのアプローチはOKっす◎ 口頭でstartとend時の座標を参照すればOKって伝えたけど、↑のケースに対応するためにmoveを上手に活用する必要ありだね。。ごめんw |
src/core/mixin.js
Outdated
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要かな
src/core/mixin.js
Outdated
// bind済みであれば何もしない。 | ||
if (!!elm.getAttribute('touchevents')) { | ||
return; | ||
} | ||
|
||
const touchStartEventId = closureEventListener.add(elm, EVENT_TOUCHSTART, e => { | ||
e.stopPropagation(); | ||
if (isSupportTouch) { | ||
console.log(e.touches[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consoleを消す。
eslintでconsole設定入れるとか。
Content
Buttons allows touch Event that moves 10px.