diff --git a/types/react-native-background-timer/index.d.ts b/types/react-native-background-timer/index.d.ts new file mode 100644 index 0000000000..7a64700595 --- /dev/null +++ b/types/react-native-background-timer/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for react-native-background-timer 2.0 +// Project: https://github.com/ocetnik/react-native-background-timer#readme +// Definitions by: Tjark Smalla +// 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; diff --git a/types/react-native-background-timer/react-native-background-timer-tests.ts b/types/react-native-background-timer/react-native-background-timer-tests.ts new file mode 100644 index 0000000000..6ee4334a8d --- /dev/null +++ b/types/react-native-background-timer/react-native-background-timer-tests.ts @@ -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); diff --git a/types/react-native-background-timer/tsconfig.json b/types/react-native-background-timer/tsconfig.json new file mode 100644 index 0000000000..e4c1076050 --- /dev/null +++ b/types/react-native-background-timer/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-native-background-timer-tests.ts" + ] +} diff --git a/types/react-native-background-timer/tslint.json b/types/react-native-background-timer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-background-timer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }