#31 : Add ProgressManager to carousel component

This commit is contained in:
Vadim
2021-07-02 00:24:04 +03:00
parent 06a9302278
commit 9d00b1bc6c

View File

@@ -12,6 +12,7 @@
} from '../../utils/event' } from '../../utils/event'
import { getAdjacentIndexes } from '../../utils/page' import { getAdjacentIndexes } from '../../utils/page'
import { get } from '../../utils/object' import { get } from '../../utils/object'
import { ProgressManager } from '../../utils/ProgressManager.js'
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@@ -107,12 +108,22 @@
let pagesElement let pagesElement
let focused = false let focused = false
let progressValue
const progressManager = new ProgressManager({
autoplayDuration,
onValueChange: (value) => {
progressValue = value
}
})
let autoplayInterval = null let autoplayInterval = null
$: { $: {
if (pauseOnFocus) { if (pauseOnFocus) {
if (focused) { if (focused) {
progressManager.pause()
clearAutoplay() clearAutoplay()
} else { } else {
progressManager.resume()
applyAutoplay() applyAutoplay()
} }
} }
@@ -156,11 +167,17 @@
} }
let cleanupFns = [] let cleanupFns = []
onMount(() => { onMount(() => {
(async () => { (async () => {
await tick() await tick()
cleanupFns.push(store.subscribe(value => { cleanupFns.push(store.subscribe(value => {
currentPageIndex = value.currentPageIndex currentPageIndex = value.currentPageIndex
progressManager.reset() // clear interval out of condition in case autoplay was changed reactively
if (autoplay) {
progressManager.start()
}
})) }))
if (pagesElement && pageWindowElement) { if (pagesElement && pageWindowElement) {
// load first and last child to clone them // load first and last child to clone them