diff --git a/types/react-native-push-notification/index.d.ts b/types/react-native-push-notification/index.d.ts new file mode 100644 index 0000000000..bec39b8be8 --- /dev/null +++ b/types/react-native-push-notification/index.d.ts @@ -0,0 +1,89 @@ +// Type definitions for react-native-push-notification 3.0 +// Project: https://github.com/zo0r/react-native-push-notification#readme +// Definitions by: Paito Anderson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +export interface PushNotificationPermissions { + alert?: boolean; + badge?: boolean; + sound?: boolean; +} + +export interface PushNotification { + foreground: boolean; + userInteraction: boolean; + message: string|object; + data: object; + badge: number; + alert: object; + sound: string; +} + +export class PushNotificationOptions { + onRegister?: (token: { os: string, token: string }) => void; + onNotification?: (notification: PushNotification) => void; + senderID?: string; + popInitialNotification?: boolean; + requestPermissions?: boolean; +} + +export type RepeatType = 'week' | 'day' | 'hour' | 'minute' | 'time'; + +export class PushNotificationObject { + /* Android only properties */ + id?: string; + ticker?: string; + autoCancel?: boolean; + largeIcon?: string; + smallIcon?: string; + bigText?: string; + subText?: string; + color?: string; + vibrate?: boolean; + vibration?: number; + tag?: string; + group?: string; + ongoing?: boolean; + + /* iOS only properties */ + alertAction?: any; + category?: any; + userInfo?: any; + + /* iOS and Android properties */ + title?: string; + message: string; + playSound?: boolean; + soundName?: string; + number?: string; + repeatType?: RepeatType; + actions?: string; +} + +export class PushNotificationScheduleObject extends PushNotificationObject { + Date: Date; +} + +export interface PushNotification { + configure(options: PushNotificationOptions): void; + unregister(): void; + localNotification(details: PushNotificationObject): void; + localNotificationSchedule(details: PushNotificationScheduleObject): void; + requestPermissions(): void; + presentLocalNotification(details: PushNotificationObject): void; + scheduleLocalNotification(details: PushNotificationScheduleObject): void; + cancelLocalNotifications(details: object): void; + cancelAllLocalNotifications(): void; + setApplicationIconBadgeNumber(badgeCount: number): void; + getApplicationIconBadgeNumber(callback: (badgeCount: number) => void): void; + popInitialNotification(): Promise; + abandonPermissions(): void; + checkPermissions(callback: (permissions: PushNotificationPermissions) => void): void; + registerNotificationActions(actions: string[]): void; + clearAllNotifications(): void; +} + +declare const PushNotification: PushNotification; + +export default PushNotification; diff --git a/types/react-native-push-notification/react-native-push-notification-tests.ts b/types/react-native-push-notification/react-native-push-notification-tests.ts new file mode 100644 index 0000000000..f23ab07ef1 --- /dev/null +++ b/types/react-native-push-notification/react-native-push-notification-tests.ts @@ -0,0 +1,25 @@ +import PushNotification from 'react-native-push-notification'; + +PushNotification.configure({ + onNotification: (notification) => {}, + onRegister: (token) => {}, + senderID: 'XXX', + popInitialNotification: false, + requestPermissions: true, +}); + +PushNotification.unregister(); +PushNotification.localNotification = (details) => {}; +PushNotification.localNotificationSchedule = (details) => {}; +PushNotification.requestPermissions(); +PushNotification.presentLocalNotification = (details) => {}; +PushNotification.scheduleLocalNotification = (details) => {}; +PushNotification.cancelLocalNotifications = (details) => {}; +PushNotification.cancelAllLocalNotifications(); +PushNotification.setApplicationIconBadgeNumber(1); +PushNotification.getApplicationIconBadgeNumber((badgeCount) => {}); +PushNotification.popInitialNotification(); +PushNotification.checkPermissions((checkPermissions) => {}); +PushNotification.abandonPermissions(); +PushNotification.registerNotificationActions(['Accept', 'Reject', 'Yes', 'No']); +PushNotification.clearAllNotifications(); diff --git a/types/react-native-push-notification/tsconfig.json b/types/react-native-push-notification/tsconfig.json new file mode 100644 index 0000000000..a030044ab2 --- /dev/null +++ b/types/react-native-push-notification/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-native-push-notification-tests.ts" + ] +} diff --git a/types/react-native-push-notification/tslint.json b/types/react-native-push-notification/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-push-notification/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }