react-native-background-timer icon indicating copy to clipboard operation
react-native-background-timer copied to clipboard

TypeError : expected 'double' but had 'boolean' RNBackgroundTimer.setTimeout

Open matthieupinte opened this issue 8 years ago • 5 comments

I got some issues with react-native: ^0.49.3...

Hope you can help ^^, removed it temporary and using default React Native Timer...

screen shot 2017-10-19 at 5 03 08 pm

matthieupinte avatar Oct 19 '17 15:10 matthieupinte

I am getting almost the same error when I enable hot reloading and make a change.

After further testing, I can recreate this issue by setting a timeout with no second parameter. Any suggestions how to resolve this issue?

ximxim avatar Nov 10 '17 19:11 ximxim

This error occurs every time I enable remote debugging, both iOS and Android. "react-native": "^0.50.3" "react-native-background-timer": "^1.3.0"

The following error occurs in iOS:

simulator screen shot - iphone 6 - 2017-11-12 at 15 56 41

maartenpetit avatar Nov 12 '17 14:11 maartenpetit

You can work around this by setting the global methods in a slightly different way, e.g.:

setTimeout = (fn, ms = 0) => Timer.setTimeout(fn, ms)
setInterval = (fn, ms = 0) => Timer.setInterval(fn, ms)
clearTimeout = (fn, ms = 0) => Timer.clearTimeout(fn, ms)
clearInterval = (fn, ms = 0) => Timer.clearInterval(fn, ms)

levity avatar Nov 16 '17 00:11 levity

@levity i set the global methods like your example but still get the error , do you have any idea ? 😓

tuna1207 avatar Apr 18 '18 02:04 tuna1207

Got it solved by checking ms value

setTimeout = (fn, ms = 0) => {
  const numberMs = Number(ms)
  if (isNaN(numberMs)) return BackgroundTimer.setTimeout(fn, 0)
  return BackgroundTimer.setTimeout(fn, numberMs)
}
setInterval = (fn, ms = 0) => {
  const numberMs = Number(ms)
  if (isNaN(numberMs)) return BackgroundTimer.setInterval(fn, 0)
  return BackgroundTimer.setInterval(fn, numberMs)
}
clearTimeout = (fn, ms = 0) => {
  const numberMs = Number(ms)
  if (isNaN(numberMs)) return BackgroundTimer.clearTimeout(fn, 0)
  return BackgroundTimer.clearTimeout(fn, numberMs)
}
clearInterval = (fn, ms = 0) => {
  const numberMs = Number(ms)
  if (isNaN(numberMs)) return BackgroundTimer.clearInterval(fn, 0)
  return BackgroundTimer.clearInterval(fn, numberMs)
}

tuna1207 avatar Apr 18 '18 09:04 tuna1207