#56 : Fix touchable handlers
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { createDispatcher } from '../../utils/event'
|
||||
import { get } from '../../utils/object'
|
||||
import {
|
||||
addFocusinEventListener,
|
||||
removeFocusinEventListener,
|
||||
@@ -10,9 +9,8 @@ import {
|
||||
/**
|
||||
* focusable events are for mouse events only
|
||||
*/
|
||||
export function focusable(node, options) {
|
||||
// pass custom dispatch fn in order to re-translate dispatched event
|
||||
const dispatch = get(options, 'dispatch', createDispatcher(node))
|
||||
export function focusable(node) {
|
||||
const dispatch = createDispatcher(node)
|
||||
|
||||
function handleFocusin() {
|
||||
addFocusoutEventListener(node, handleFocusout)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from './pausable'
|
||||
@@ -1,48 +0,0 @@
|
||||
import {
|
||||
// addTouchableChangeEventListener,
|
||||
getIsTouchable,
|
||||
createDispatcher,
|
||||
} from '../../utils/event'
|
||||
import { focusable } from '../focusable'
|
||||
import { tappable } from '../tappable'
|
||||
|
||||
function getHandler(isTouchable, node) {
|
||||
const dispatch = createDispatcher(node)
|
||||
|
||||
if (isTouchable) {
|
||||
return tappable(node, {
|
||||
dispatch: (_, payload) => {
|
||||
dispatch('pausedToggle', {
|
||||
isTouchable: true,
|
||||
...payload
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
return focusable(node, {
|
||||
dispatch: (_, payload) => {
|
||||
dispatch('pausedToggle', {
|
||||
isTouchable: false,
|
||||
...payload
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function pausable(node) {
|
||||
let destroy
|
||||
|
||||
const handleTouchableChange = (isTouchable) => {
|
||||
destroy && destroy() // destroy when touchable changed
|
||||
destroy = getHandler(isTouchable, node).destroy
|
||||
}
|
||||
handleTouchableChange(getIsTouchable())
|
||||
// in order to change handlers when browser was switched to mobile view and vice versa
|
||||
// const removeTouchableChangeListener = addTouchableChangeEventListener(handleTouchableChange)
|
||||
return {
|
||||
destroy() {
|
||||
// removeTouchableChangeListener()
|
||||
destroy() // destroy here in case if touchable was not changed
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { createDispatcher } from '../../utils/event'
|
||||
import { get } from '../../utils/object'
|
||||
import { getDistance } from '../../utils/math'
|
||||
import {
|
||||
addFocusinEventListener,
|
||||
@@ -15,9 +14,8 @@ import {
|
||||
/**
|
||||
* tappable events are for touchable devices only
|
||||
*/
|
||||
export function tappable(node, options) {
|
||||
// pass custom dispatch fn in order to re-translate dispatched event
|
||||
const dispatch = get(options, 'dispatch', createDispatcher(node))
|
||||
export function tappable(node) {
|
||||
const dispatch = createDispatcher(node)
|
||||
|
||||
let tapStartedAt = 0
|
||||
let tapStartPos = { x: 0, y: 0 }
|
||||
@@ -44,6 +42,7 @@ export function tappable(node, options) {
|
||||
}
|
||||
|
||||
function handleTapend(event) {
|
||||
event.preventDefault();
|
||||
removeFocusoutEventListener(node, handleTapend)
|
||||
|
||||
const touch = event.changedTouches[0]
|
||||
|
||||
Reference in New Issue
Block a user