Skip to content

Commit 3651949

Browse files
author
Petr Konecny
committed
fix: added video pausing
1 parent e2eb443 commit 3651949

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/hooks/useAutoScroll.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class IntervalTimer {
3434
pause() {
3535
if (!this.paused) {
3636
this.clear()
37-
this.remaining = new Date().getTime() - this.callbackStartTime
37+
this.remaining = this._delay - (new Date().getTime() - this.callbackStartTime)
3838
this.paused = true
3939
this.onPause?.(this.remaining)
4040
}
@@ -44,33 +44,30 @@ export class IntervalTimer {
4444
if (this.paused) {
4545
if (this.remaining) {
4646
this.onResume?.(this.remaining)
47+
this.paused = false
48+
this.callbackStartTime = new Date().getTime()
4749
setTimeout(() => {
4850
this.run()
49-
this.paused = false
50-
this.start()
5151
}, this.remaining)
52-
} else {
53-
this.paused = false
54-
this.start()
5552
}
5653
}
5754
}
5855

5956
clear() {
6057
if (this.timerId) {
61-
clearInterval(this.timerId)
58+
clearTimeout(this.timerId)
6259
}
6360
}
6461

6562
start() {
6663
this.clear()
64+
this.callbackStartTime = new Date().getTime()
6765
this.timerId = setTimeout(() => {
6866
this.run()
6967
}, this._delay)
7068
}
7169

7270
run() {
73-
this.callbackStartTime = new Date().getTime()
7471
this._callback()
7572
}
7673
}
@@ -128,6 +125,7 @@ export const useAutoScroll = ({
128125
})
129126
},
130127
)
128+
timeoutRef.current.start()
131129
return timeoutRef.current
132130
},
133131
[clearCarouselTimeout, goToPage, scrollValue, timeoutValue],

0 commit comments

Comments
 (0)