Add +1 min to the countdown timer - With timer already finalized or in progress

0

Each time I click a button, I want to add +1 min to the timer.

<Button
    onPress={this.somarUmMinuto}
    title="Somar 1 minuto"
    color="#007FFF"
    accessibilityLabel="Somar 1 minuto"
/>

Code used to set the countdown:

iniciarCronometro() {
    var intervalId = setInterval(this.somarUmSegundo, 1000);
    this.setState({
      intervalId: intervalId,
    });
}   

somarUmSegundo() {
    let segundos = this.state.contadorSegundo;
    let minutos = this.state.contadorMinuto;

    minutos == 1 || segundos > 0;
    if (segundos == 0) {
      segundos = 59;
      minutos = minutos - 1;
    } else {
      segundos = segundos - 1;
    }

    this.setState({
      contadorSegundo: segundos,
      contadorMinuto: minutos,
    });
}

I need to increment the event to add +1 min to the timer, whether it's already finished or still in progress in the count.

Countdown timer lasts 1 minute.

    
asked by anonymous 17.10.2018 / 18:26

1 answer

1

First you need to bind to the onPress button so that you can access the state of the application, as follows:

onPress={this.somarUmMinuto.bind(this)}

Then you need to create the function for this increment:

somarUmMinuto(){
    this.setState({
        contadorMinuto: this.state.contadorMinuto + 1,
    });
}
    
17.10.2018 / 22:05