ocetnik / react-native-background-timer

Emit event periodically (even when app is in the background)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BackgroundTimer.setTimeout() fires inconsistently with chrome remote debugger connected

danhab99 opened this issue · comments

I installed this package as it was recommended to me on this StackOverflow issue I'm having trouble getting timers to work with the chrome debugger to work because of a synchronization issue between my device and the browser inwhich the browser is trying to handle the timing (or something idk). I saw this line in the native android code which lead me to believe that timing dispatches are being handled natively, but the timer still doesn't work.

Code example:

const TestComponent : React.FC<{}> = () => {
  const [time, setTime] = useState(0);

  useEffect(() => {
    BackgroundTimer.setTimeout(() => {
      setTime(x => x + 1)
    }, 1000)
  , [time]);

  return <></>
}

React Native info:

react-native info                                                                                                                 ~/Documents/node/obm-app  
info Fetching system and libraries information...
(node:1581462) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
System:
    OS: Linux 5.10 Manjaro Linux
    CPU: (20) x64 Intel(R) Core(TM) i9-10850K CPU @ 3.60GHz
    Memory: 7.08 GB / 31.26 GB
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 15.14.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/bin/yarn
    npm: 7.7.6 - /usr/local/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 23, 25, 29, 30
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.3
      System Images: android-25 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7199119
  Languages:
    Java: 1.8.0_292 - /usr/bin/javac
    Python: 3.9.4 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: ~0.63.3 => 0.63.4 
  npmGlobalPackages:
    *react-native*: Not Found

package.json

{
  "main": "index.js",
  "scripts": {
    "preandroid": "cd android && ./gradlew clean",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start --reset-cache",
    "test": "jest",
  },
  "dependencies": {
    "@apollo/client": "^3.3.9",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/native": "^5.8.1",
    "@react-navigation/stack": "^5.11.0",
    "bluebird": "^3.7.2",
    "buffer": "^6.0.3",
    "color": "^3.1.3",
    "expo": "~39.0.2",
    "expo-splash-screen": "~0.6.2",
    "expo-status-bar": "~1.0.2",
    "expo-updates": "~0.3.2",
    "graphql": "^15.5.0",
    "lodash.ismatch": "^4.4.0",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "~0.63.3",
    "react-native-background-timer": "^2.4.1",
    "react-native-cookies": "^3.3.0",
    "react-native-exit-app": "^1.1.0",
    "react-native-fs": "^2.16.6",
    "react-native-gesture-handler": "~1.7.0",
    "react-native-reanimated": "~1.13.0",
    "react-native-restart": "0.0.20",
    "react-native-safe-area-context": "^3.1.9",
    "react-native-screens": "~2.10.1",
    "react-native-share": "^5.1.0",
    "react-native-sidebar": "^0.3.0",
    "react-native-svg": "^12.1.0",
    "react-native-svg-transformer": "^0.14.3",
    "react-native-unimodules": "~0.11.0",
    "react-native-uuid": "^1.4.9",
    "react-native-vector-icons": "^7.1.0",
    "react-native-web": "~0.13.12",
    "react-native-webview": "^11.0.2",
    "react-redux": "^7.2.2",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "regression": "^2.0.1"
  },
  "devDependencies": {
    "@babel/core": "~7.9.0",
    "babel-jest": "~25.2.6",
    "jest": "~25.2.6",
    "react-test-renderer": "~16.13.1"
  },
  "jest": {
    "preset": "react-native"
  },
  "private": true,
  "version": "1.0.0"
}

This code works fine on the device, but not when the chrome debugger is connected. This is kind of an urgent problem and I'd really appreciate a prompt response.

Discovery: apparently the timer only works while I'm tapping the screen?? I can't explain why