vydimitrov / react-countdown-circle-timer

Lightweight React/React Native countdown timer component with color and progress animation based on SVG
MIT License
692 stars 87 forks source link

Run things in the background along with the countdown #70

Closed GaylordP closed 3 years ago

GaylordP commented 3 years ago

Hello and thank you for your library :)

I use react-native-countdown-circle-timer and it works very well. The last five seconds, I execute a "beep" thanks to the react-native-sound library : it works very well too.

But when my application is in the background, the beep does not run. I tried to do a console.log() and indeed, as soon as the application goes to the background it no longer appears.

I know the stopwatch continues in the background (when I come back, time to spend).

Can you help me run things in the background along with the countdown ? Thanks you very much

Sound.setCategory('Playback')
const soundWait = new Sound('wait.mp3', Sound.MAIN_BUNDLE)

let lastShowTimerText
const remainingAlreadyShowed = []

<CountdownCircleTimer
  isPlaying
  duration={60}
  colors="red"
  size={120}
  trailColor="#fff"
>
  {({ remainingTime }) => {
    console.log(remainingTime) // not showed in background, but the timer continued well when I come back 

    if (undefined === remainingAlreadyShowed.find(item => item === remainingTime)) {
      remainingAlreadyShowed.push(remainingTime)

      if (remainingTime <= 5) {
        soundWait.play()
      }

      lastShowTimerText = <Animated.Text style={styles.timer}>{remainingTime }</Animated.Text>

      return lastShowTimerText
    } else {
      return lastShowTimerText
    }
  }}
</CountdownCircleTimer>
vydimitrov commented 3 years ago

Hey, I guess what happens here is that Animated component from React Native (the countdown is using Animated internally) is suspending animations when the app is running in the background. You can check this issue but I don't see any solution.

vydimitrov commented 3 years ago

I am closing this issue. Let me know if I can help you in any other way.