Gathering detailed insights and metrics for react-native-background-timer
Gathering detailed insights and metrics for react-native-background-timer
Gathering detailed insights and metrics for react-native-background-timer
Gathering detailed insights and metrics for react-native-background-timer
@types/react-native-background-timer
TypeScript definitions for react-native-background-timer
react-native-background-timer-android
setInterval and setTimeout that work even if the app is running in the background
react-idle-timer
Activity detection for React.js
react-native-countdown-circle-timer
Lightweight React Native countdown timer component with color and progress animation based on SVG
npm install react-native-background-timer
48.7
Supply Chain
53.7
Quality
68.6
Maintenance
50
Vulnerability
95.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,621 Stars
381 Commits
231 Forks
22 Watching
9 Branches
25 Contributors
Updated on 19 Nov 2024
Minified
Minified + Gzipped
Java (37.48%)
Objective-C (30.74%)
JavaScript (25.74%)
Ruby (6.04%)
Cumulative downloads
Total Downloads
Last day
-16.3%
10,691
Compared to previous day
Last week
2.1%
62,816
Compared to previous week
Last month
4.8%
265,802
Compared to previous month
Last year
21.6%
2,520,827
Compared to previous year
Emit event periodically (even when app is in the background).
If you use Expo to create a project you'll just need to "eject".
1expo eject
Install React Native Background Timer package.
1yarn add react-native-background-timer 2# or using npm 3npm install react-native-background-timer --save
Link React Native Background Timer library. This step is not necessary when you use React Native >= 0.60 (and your app is not ejected from Expo).
1react-native link react-native-background-timer
If you use CocoaPods or React Native >= 0.60 (and your app is not ejected from Expo) or your app is ejected from Expo, then before running your app on iOS, make sure you have CocoaPods installed and run:
1cd ios 2pod install
Link the library manually if you get errors:
TypeError: Cannot read property 'setTimeout' of undefined
or TypeError: null is not an object (evaluating 'RNBackgroundTimer.setTimeout')
Native module cannot be null
android/settings.gradle
1+ include ':react-native-background-timer' 2+ project(':react-native-background-timer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-timer/android')
android/app/build.gradle
1dependencies { 2+ implementation project(':react-native-background-timer') 3}
android/app/src/main/java/com/your-app/MainApplication.java
1+ import com.ocetnik.timer.BackgroundTimerPackage; 2 3@Override 4protected List<ReactPackage> getPackages() { 5 return Arrays.<ReactPackage>asList( 6+ new BackgroundTimerPackage() 7 ); 8}
ios/Podfile
1+ pod 'react-native-background-timer', :path => '../node_modules/react-native-background-timer'
1import BackgroundTimer from 'react-native-background-timer';
To use the same code both on Android and iOS use runBackgroundTimer() and stopBackgroundTimer(). There can be used only one background timer to keep code consistent.
1BackgroundTimer.runBackgroundTimer(() => {
2//code that will be called every 3 seconds
3},
43000);
5//rest of code will be performing for iOS on background too
6
7BackgroundTimer.stopBackgroundTimer(); //after this call all code on background stop run.
After iOS update logic of background task little bit changed. So we can't use as it was. You have to use only start() and stop() without parameters. And all code that is performing will continue performing on background including all setTimeout() timers.
Example:
1BackgroundTimer.start();
2// Do whatever you want incuding setTimeout;
3BackgroundTimer.stop();
If you call stop() on background no new tasks will be started! Don't call .start() twice, as it stop performing previous background task and starts new. If it will be called on backgound no tasks will run.
You can use the setInterval
and setTimeout
functions.
This API is identical to that of react-native
and can be used to quickly replace existing timers
with background timers.
1// Start a timer that runs continuous after X milliseconds
2const intervalId = BackgroundTimer.setInterval(() => {
3 // this will be executed every 200 ms
4 // even when app is the the background
5 console.log('tic');
6}, 200);
7
8// Cancel the timer when you are done with it
9BackgroundTimer.clearInterval(intervalId);
1// Start a timer that runs once after X milliseconds
2const timeoutId = BackgroundTimer.setTimeout(() => {
3 // this will be executed once after 10 seconds
4 // even when app is the the background
5 console.log('tac');
6}, 10000);
7
8// Cancel the timeout if necessary
9BackgroundTimer.clearTimeout(timeoutId);
Obsolete usage which doesn't support multiple background timers.
1import { 2 DeviceEventEmitter, 3 NativeAppEventEmitter, 4 Platform, 5} from 'react-native'; 6 7import BackgroundTimer from 'react-native-background-timer';
1const EventEmitter = Platform.select({ 2 ios: () => NativeAppEventEmitter, 3 android: () => DeviceEventEmitter, 4})();
1// start a global timer 2BackgroundTimer.start(5000); // delay in milliseconds only for Android
1// listen for event 2EventEmitter.addListener('backgroundTimer', () => { 3 // this will be executed once after 5 seconds 4 console.log('toe'); 5});
1// stop the timer
2BackgroundTimer.stop();
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
17 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More