From 5554593568f366f98e8f7bab1c46f4d531ec667f Mon Sep 17 00:00:00 2001 From: Paito Anderson Date: Wed, 15 Nov 2017 10:02:10 -0500 Subject: [PATCH 1/2] Added react-native-push-notification Resolves zo0r/react-native-push-notification#553 --- .../react-native-push-notification/index.d.ts | 89 +++++++++++++++++++ .../react-native-push-notification-tests.ts | 25 ++++++ .../tsconfig.json | 24 +++++ .../tslint.json | 1 + 4 files changed, 139 insertions(+) create mode 100644 types/react-native-push-notification/index.d.ts create mode 100644 types/react-native-push-notification/react-native-push-notification-tests.ts create mode 100644 types/react-native-push-notification/tsconfig.json create mode 100644 types/react-native-push-notification/tslint.json 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..e7fcffed05 --- /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 + +declare module "react-native-push-notification" { + + interface PushNotificationPermissions { + alert?: boolean + badge?: boolean + sound?: boolean + } + + interface IPushNotification { + 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: IPushNotification) => 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 default class PushNotification { + static configure(options: PushNotificationOptions): void; + static unregister(): void; + static localNotification(details: PushNotificationObject): void; + static localNotificationSchedule(details: PushNotificationScheduleObject): void; + static requestPermissions(): void; + static presentLocalNotification(details: PushNotificationObject): void; + static scheduleLocalNotification(details: PushNotificationScheduleObject): void; + static cancelLocalNotifications(details: object): void; + static cancelAllLocalNotifications(): void; + static setApplicationIconBadgeNumber(badgeCount: number): void; + static getApplicationIconBadgeNumber(callback: (badgeCount: number) => void): void + static popInitialNotification(): Promise; + static abandonPermissions(): void; + static checkPermissions(callback: (permissions: PushNotificationPermissions) => void): void + static registerNotificationActions(actions: string[]): void; + static clearAllNotifications(): void; + } +} 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" } From aaab1da998f31e8f73308724f2cf3444e09be3d6 Mon Sep 17 00:00:00 2001 From: Paito Anderson Date: Wed, 15 Nov 2017 10:30:01 -0500 Subject: [PATCH 2/2] Adhere to rules --- .../react-native-push-notification/index.d.ts | 164 +++++++++--------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/types/react-native-push-notification/index.d.ts b/types/react-native-push-notification/index.d.ts index e7fcffed05..bec39b8be8 100644 --- a/types/react-native-push-notification/index.d.ts +++ b/types/react-native-push-notification/index.d.ts @@ -4,86 +4,86 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -declare module "react-native-push-notification" { - - interface PushNotificationPermissions { - alert?: boolean - badge?: boolean - sound?: boolean - } - - interface IPushNotification { - 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: IPushNotification) => 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 default class PushNotification { - static configure(options: PushNotificationOptions): void; - static unregister(): void; - static localNotification(details: PushNotificationObject): void; - static localNotificationSchedule(details: PushNotificationScheduleObject): void; - static requestPermissions(): void; - static presentLocalNotification(details: PushNotificationObject): void; - static scheduleLocalNotification(details: PushNotificationScheduleObject): void; - static cancelLocalNotifications(details: object): void; - static cancelAllLocalNotifications(): void; - static setApplicationIconBadgeNumber(badgeCount: number): void; - static getApplicationIconBadgeNumber(callback: (badgeCount: number) => void): void - static popInitialNotification(): Promise; - static abandonPermissions(): void; - static checkPermissions(callback: (permissions: PushNotificationPermissions) => void): void - static registerNotificationActions(actions: string[]): void; - static clearAllNotifications(): void; - } +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;