mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Add type declaration for react-native-background-timer
This commit is contained in:
36
types/react-native-background-timer/index.d.ts
vendored
Normal file
36
types/react-native-background-timer/index.d.ts
vendored
Normal 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;
|
||||
@@ -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);
|
||||
22
types/react-native-background-timer/tsconfig.json
Normal file
22
types/react-native-background-timer/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/react-native-background-timer/tslint.json
Normal file
1
types/react-native-background-timer/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user