Skip to content

Commit d6b4513

Browse files
committed
Add onCountdownOver prop.
1 parent dcf2796 commit d6b4513

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ countingTitleStyle | object | Yes | none | custom title style when counting down
166166
timeFontStyle | FontPropTypes | Yes | none | font style of time
167167
shouldStartCountdown | function | Yes | return true | before start countdown, you can use this function to handle some business logic, return true to allow countdown, otherwise return false
168168
onNetworkFailed | function | Yes | none | invoke when the network is failed, so the countdown timer will be invalid in this situation, maybe you will use it to show some message for users
169+
onCountdownOver | function | Yes | none | invoke when the countdown over
169170

170171

171172
## Methods

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default class Countdown extends PureComponent {
5858
timeFontStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
5959
shouldStartCountdown: PropTypes.func,
6060
onNetworkFailed: PropTypes.func,
61+
onCountdownOver: PropTypes.func,
6162
};
6263

6364
static defaultProps = {
@@ -104,6 +105,9 @@ export default class Countdown extends PureComponent {
104105
}
105106

106107
stopCountdown = () => {
108+
const { onCountdownOver } = this.props;
109+
onCountdownOver && onCountdownOver();
110+
107111
this.setState({
108112
status: CountdownStatus.Over,
109113
second: this.props.time,
@@ -121,10 +125,12 @@ export default class Countdown extends PureComponent {
121125
};
122126

123127
turnsOnTimer = () => {
128+
const { onCountdownOver } = this.props;
124129
const now = new Date();
125130
const diff = Math.round((now - this.recodTime) / 1000);
126131
// timer should be over
127132
if (this.state.second - diff <= 0) {
133+
onCountdownOver && onCountdownOver();
128134
this.setState({ status: CountdownStatus.Over, second: this.props.time });
129135
} else {
130136
this.setState({
@@ -165,12 +171,14 @@ export default class Countdown extends PureComponent {
165171
};
166172

167173
startTimer = () => {
168-
const { time } = this.props;
174+
const { time, onCountdownOver } = this.props;
169175

170176
this.timer = setInterval(() => {
171177
let nextSecond = this.state.second - 1;
172178
// countdown over
173179
if (nextSecond === 0) {
180+
onCountdownOver && onCountdownOver();
181+
174182
this.clearTimer();
175183
this.setState({ status: CountdownStatus.Over, second: time });
176184
return;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rn-countdown",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "A smart countdown component for react-native apps. You may use it to handle different status when request a verification code.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)