#49 : Dispatch and handle swipe failed
This commit is contained in:
@@ -70,13 +70,17 @@ export function swipeable(node, { thresholdProvider }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseup(event) {
|
function handleMouseup(event) {
|
||||||
isTouching = false
|
|
||||||
if (!isValidSwipe()) return
|
|
||||||
|
|
||||||
const coords = getCoords(event)
|
|
||||||
dispatch('end', { x: coords.x, y: coords.y })
|
|
||||||
removeEndEventListener(window, handleMouseup)
|
removeEndEventListener(window, handleMouseup)
|
||||||
removeMoveEventListener(window, handleMousemove)
|
removeMoveEventListener(window, handleMousemove)
|
||||||
|
|
||||||
|
isTouching = false
|
||||||
|
|
||||||
|
if (!isValidSwipe()) {
|
||||||
|
dispatch('swipeFailed')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const coords = getCoords(event)
|
||||||
|
dispatch('end', { x: coords.x, y: coords.y })
|
||||||
}
|
}
|
||||||
|
|
||||||
addStartEventListener(node, handleMousedown)
|
addStartEventListener(node, handleMousedown)
|
||||||
|
|||||||
@@ -168,7 +168,7 @@
|
|||||||
children[pageIndex].style.maxWidth = `${pageWidth}px`
|
children[pageIndex].style.maxWidth = `${pageWidth}px`
|
||||||
}
|
}
|
||||||
|
|
||||||
offsetPage(false)
|
offsetPage({ animated: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
function addClones() {
|
function addClones() {
|
||||||
@@ -228,7 +228,8 @@
|
|||||||
await showPage(pageIndex + Number(infinite))
|
await showPage(pageIndex + Number(infinite))
|
||||||
}
|
}
|
||||||
|
|
||||||
function offsetPage(animated) {
|
function offsetPage(options) {
|
||||||
|
const animated = get(options, 'animated', true)
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// _duration is an offset animation time
|
// _duration is an offset animation time
|
||||||
_duration = animated ? duration : 0
|
_duration = animated ? duration : 0
|
||||||
@@ -262,7 +263,7 @@
|
|||||||
disabled = true
|
disabled = true
|
||||||
|
|
||||||
updateStoreFn()
|
updateStoreFn()
|
||||||
await offsetPage(get(options, 'animated', true))
|
await offsetPage({ animated: get(options, 'animated', true) })
|
||||||
disabled = false
|
disabled = false
|
||||||
|
|
||||||
const jumped = await jumpIfNeeded()
|
const jumped = await jumpIfNeeded()
|
||||||
@@ -305,6 +306,10 @@
|
|||||||
if (!swiping) return
|
if (!swiping) return
|
||||||
showPage(currentPageIndex)
|
showPage(currentPageIndex)
|
||||||
}
|
}
|
||||||
|
async function handleSwipeFailed() {
|
||||||
|
if (!swiping) return
|
||||||
|
await offsetPage({ animated: true })
|
||||||
|
}
|
||||||
|
|
||||||
function handlePausedToggle(event) {
|
function handlePausedToggle(event) {
|
||||||
if (event.detail.isTouchable) {
|
if (event.detail.isTouchable) {
|
||||||
@@ -341,6 +346,7 @@
|
|||||||
on:start={handleSwipeStart}
|
on:start={handleSwipeStart}
|
||||||
on:move={handleSwipeMove}
|
on:move={handleSwipeMove}
|
||||||
on:end={handleSwipeEnd}
|
on:end={handleSwipeEnd}
|
||||||
|
on:swipeFailed={handleSwipeFailed}
|
||||||
on:threshold={handleThreshold}
|
on:threshold={handleThreshold}
|
||||||
style="
|
style="
|
||||||
transform: translateX({offset}px);
|
transform: translateX({offset}px);
|
||||||
|
|||||||
Reference in New Issue
Block a user