Add type declaration for react-native-background-timer

This commit is contained in:
tsmalla
2018-06-21 17:13:02 +02:00
parent 0897921174
commit a790f39720
4 changed files with 90 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
// Type definitions for react-native-background-timer 2.0
// Project: https://github.com/ocetnik/react-native-background-timer#readme
// Definitions by: Tjark Smalla <https://github.com/chillkroeteTTS>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/*~ You can declare types that are available via importing the module */
export type IntervalId = number;
export type TimeoutId = number;
/*~ You can declare properties of the module using const, let, or var */
declare class BackgroundTimer {
constructor();
start(delay?:number): any;
stop(): void;
runBackgroundTimer(callback: ()=>void, delay: number): void;
backgroundClockMethod(callback: ()=>void, delay: number): void;
stopBackgroundTimer(): void;
setTimeout(callback: ()=>void, timeout: number): TimeoutId;
clearTimeout(timeoutId: TimeoutId): void;
setInterval(callback: ()=>void, timeout: number): IntervalId;
clearInterval(intervalId: IntervalId): void;
}
declare const _BackgroundTimer: BackgroundTimer;
export default _BackgroundTimer;

View File

@@ -0,0 +1,31 @@
// Tests taken from Examples at https://github.com/ocetnik/react-native-background-timer
import BackgroundTimer from 'react-native-background-timer';
BackgroundTimer.runBackgroundTimer(() => {
// do stuff
},
3000);
// rest of code will be performing for iOS on background too
BackgroundTimer.stopBackgroundTimer();
BackgroundTimer.start();
// Do whatever you want incuding setTimeout;
BackgroundTimer.stop();
// Start a timer that runs continuous after X milliseconds
const intervalId = BackgroundTimer.setInterval(() => {
// this will be executed every 200 ms
// even when app is the the background
}, 200);
// Cancel the timer when you are done with it
BackgroundTimer.clearInterval(intervalId);
// Start a timer that runs once after X milliseconds
const timeoutId = BackgroundTimer.setTimeout(() => {
// this will be executed once after 10 seconds
// even when app is the the background
}, 10000);
// Cancel the timeout if necessary
BackgroundTimer.clearTimeout(timeoutId);

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"react-native-background-timer-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }