Skip to content

Commit 96f055e

Browse files
committed
Fix restarting Timer after initial finish called
1 parent f045fec commit 96f055e

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/index.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TimerWrapper extends Component {
4141

4242
switch (active) {
4343
case true:
44-
const nextTime = duration !== null && this.state.time === duration
44+
const nextTime = duration !== null && this.state.time >= duration
4545
? 0
4646
: this.state.time;
4747

@@ -107,34 +107,33 @@ class TimerWrapper extends Component {
107107
time: nextTime,
108108
});
109109

110-
if (duration !== null && progress === 1) {
110+
this.setState({
111+
time: nextTime,
112+
});
113+
114+
if (duration !== null && this.state.time >= duration) {
111115
onFinish({
112116
duration,
113117
progress,
114118
time: nextTime,
115119
});
116120

117-
if (loop) {
118-
nextTime = 0;
119-
onStart({
120-
duration,
121-
progress: 0,
122-
time: nextTime,
123-
});
124-
125-
this.setState({
126-
startTime: Date.now(),
127-
});
128-
}
129-
else {
121+
if (!loop) {
130122
cancelAnimationFrame(this.animationFrame);
131123
return;
132124
}
133-
}
134125

135-
this.setState({
136-
time: nextTime,
137-
});
126+
nextTime = 0;
127+
onStart({
128+
duration,
129+
progress: 0,
130+
time: nextTime,
131+
});
132+
133+
this.setState({
134+
startTime: Date.now(),
135+
});
136+
}
138137

139138
this.animationFrame = requestAnimationFrame(this.tick);
140139
}

0 commit comments

Comments
 (0)