1.0.1 • Published 4 years ago
react-native-background-timer-workmanager v1.0.1
React Native Background Timer Workmanager Android
Emit event periodically in both foreground and background.
Installation
If you use Expo to create a project you'll just need to "eject".
expo ejectInstall React Native Background Timer Work Manager package.
yarn add react-native-background-timer-workmanager # or using npm npm install react-native-background-timer-workmanager --saveLink 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).
react-native link react-native-background-timer-workmanagerLink the library manually if you get errors:
android/settings.gradle+ include ':react-native-background-timer-workmanager' + project(':react-native-background-timer-workmanager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-timer-workmanager/android')android/app/build.gradledependencies { + implementation project(':react-native-background-timer-workmanager') }android/app/src/main/java/com/your-app/MainApplication.java```diff + import com.shubhamd99.timer.BackgroundTimerPackage; @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( + new BackgroundTimerPackage() ); } ```
Usage
import BackgroundTimer from 'react-native-background-timer-workmanager';BackgroundTimer.start(3000, 'UNIQUE_TAG' () => {
// code that will be called every 3 seconds
});
BackgroundTimer.stop('UNIQUE_TAG'); // To Stop PollingExample:
import React, {useEffect} from 'react';
const App = () => {
useEffect(() => {
BackgroundTimer.start(10000, 'homeScreenPolling', () => {
console.log('polling..');
});
return () => BackgroundTimer.stop('homeScreenPolling');
}, []);
};
export default App;