From efe4da9676bf438c70bce98cbd23652520981e67 Mon Sep 17 00:00:00 2001 From: Jesse Katsumata Date: Wed, 8 Jan 2020 01:24:17 +0900 Subject: [PATCH] chore: add missing type definition --- index.d.ts | 429 +++++++++++++++++++++++++++------------------------ package.json | 3 +- yarn.lock | 5 + 3 files changed, 238 insertions(+), 199 deletions(-) diff --git a/index.d.ts b/index.d.ts index ed1cc3877..5edf5127a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,80 +3,84 @@ // Definitions by: Jules Sam. Randolph export interface FetchResult { - NewData: 'UIBackgroundFetchResultNewData' - NoData: 'UIBackgroundFetchResultNoData' - ResultFailed: 'UIBackgroundFetchResultFailed' + NewData: 'UIBackgroundFetchResultNewData'; + NoData: 'UIBackgroundFetchResultNoData'; + ResultFailed: 'UIBackgroundFetchResultFailed'; } export interface PushNotification { - /** - * An alias for `getAlert` to get the notification's main message string - */ - getMessage(): string | Record - - /** - * Gets the sound string from the `aps` object - */ - getSound(): string - - /** - * Gets the category string from the `aps` object - */ - getCategory(): string - - /** - * Gets the notification's main message from the `aps` object - */ - getAlert(): string | Record - - /** - * Gets the content-available number from the `aps` object - */ - getContentAvailable(): number - - /** - * Gets the badge count number from the `aps` object - */ - getBadgeCount(): number - - /** - * Gets the data object on the notif - */ - getData(): Record - - /** - * iOS Only - * Signifies remote notification handling is complete - */ - finish(result: string): void + /** + * An alias for `getAlert` to get the notification's main message string + */ + getMessage(): string | Record; + + /** + * Gets the sound string from the `aps` object + */ + getSound(): string; + + /** + * Gets the category string from the `aps` object + */ + getCategory(): string; + + /** + * Gets the notification's main message from the `aps` object + */ + getAlert(): string | Record; + + /** + * Gets the content-available number from the `aps` object + */ + getContentAvailable(): number; + + /** + * Gets the badge count number from the `aps` object + */ + getBadgeCount(): number; + + /** + * Gets the data object on the notif + */ + getData(): Record; + + /** + * iOS Only + * Signifies remote notification handling is complete + */ + finish(result: string): void; } export interface PresentLocalNotificationDetails { - alertBody: string - alertAction: string - soundName?: string - category?: string - userInfo?: Record - applicationIconBadgeNumber?: number + alertBody: string; + alertAction: string; + soundName?: string; + category?: string; + userInfo?: Record; + applicationIconBadgeNumber?: number; } export interface ScheduleLocalNotificationDetails { - fireDate: Date - alertBody: string - alertAction: string - soundName?: string - category?: string - userInfo?: Record - applicationIconBadgeNumber?: number + fireDate: Date; + alertBody: string; + alertAction: string; + soundName?: string; + category?: string; + userInfo?: Record; + applicationIconBadgeNumber?: number; } export interface PushNotificationPermissions { - alert?: boolean - badge?: boolean - sound?: boolean + alert?: boolean; + badge?: boolean; + sound?: boolean; } -export type PushNotificationEventName = 'notification' | 'localNotification' | 'register' | 'registrationError' +export type PushNotificationEventName = + | 'notification' + | 'localNotification' + | 'register' + | 'registrationError'; /** * Handle push notifications for your app, including permission handling and icon badge number. @@ -85,147 +89,176 @@ export type PushNotificationEventName = 'notification' | 'localNotification' | ' * //FIXME: BGR: The documentation seems completely off compared to the actual js implementation. I could never get the example to run */ export interface PushNotificationIOSStatic { - /** - * iOS fetch results that best describe the result of a finished remote notification handler. - * For a list of possible values, see `PushNotificationIOS.FetchResult`. - */ - FetchResult: FetchResult - /** - * Schedules the localNotification for immediate presentation. - * details is an object containing: - * alertBody : The message displayed in the notification alert. - * alertAction : The "action" displayed beneath an actionable notification. Defaults to "view"; - * soundName : The sound played when the notification is fired (optional). - * category : The category of this notification, required for actionable notifications (optional). - * userInfo : An optional object containing additional notification data. - * applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. The default value of this property is 0, which means that no badge is displayed. - */ - presentLocalNotification(details: PresentLocalNotificationDetails): void - - /** - * Schedules the localNotification for future presentation. - * details is an object containing: - * fireDate : The date and time when the system should deliver the notification. - * alertBody : The message displayed in the notification alert. - * alertAction : The "action" displayed beneath an actionable notification. Defaults to "view"; - * soundName : The sound played when the notification is fired (optional). - * category : The category of this notification, required for actionable notifications (optional). - * userInfo : An optional object containing additional notification data. - * applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. Setting the number to 0 removes the icon badge. - */ - scheduleLocalNotification(details: ScheduleLocalNotificationDetails): void - - /** - * Cancels all scheduled localNotifications - */ - cancelAllLocalNotifications(): void - - /** - * Cancel local notifications. - * Optionally restricts the set of canceled notifications to those notifications whose userInfo fields match the corresponding fields in the userInfo argument. - */ - cancelLocalNotifications(userInfo: Record): void - - /** - * Sets the badge number for the app icon on the home screen - */ - setApplicationIconBadgeNumber(number: number): void - - /** - * Gets the current badge number for the app icon on the home screen - */ - getApplicationIconBadgeNumber(callback: (badge: number) => void): void - - /** - * Gets the local notifications that are currently scheduled. - */ - getScheduledLocalNotifications(callback: (notifications: ScheduleLocalNotificationDetails[]) => void): void - - /** - * Attaches a listener to remote notifications while the app is running in the - * foreground or the background. - * - * The handler will get be invoked with an instance of `PushNotificationIOS` - * - * The type MUST be 'notification' - */ - addEventListener( - type: 'notification' | 'localNotification', - handler: (notification: PushNotification) => void, - ): void - - /** - * Fired when the user registers for remote notifications. - * - * The handler will be invoked with a hex string representing the deviceToken. - * - * The type MUST be 'register' - */ - addEventListener(type: 'register', handler: (deviceToken: string) => void): void - - /** - * Fired when the user fails to register for remote notifications. - * Typically occurs when APNS is having issues, or the device is a simulator. - * - * The handler will be invoked with {message: string, code: number, details: any}. - * - * The type MUST be 'registrationError' - */ - addEventListener( - type: 'registrationError', - handler: (error: { message: string; code: number; details: any }) => void, - ): void - - /** - * Removes the event listener. Do this in `componentWillUnmount` to prevent - * memory leaks - */ - removeEventListener( + /** + * iOS fetch results that best describe the result of a finished remote notification handler. + * For a list of possible values, see `PushNotificationIOS.FetchResult`. + */ + FetchResult: FetchResult; + /** + * Schedules the localNotification for immediate presentation. + * details is an object containing: + * alertBody : The message displayed in the notification alert. + * alertAction : The "action" displayed beneath an actionable notification. Defaults to "view"; + * soundName : The sound played when the notification is fired (optional). + * category : The category of this notification, required for actionable notifications (optional). + * userInfo : An optional object containing additional notification data. + * applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. The default value of this property is 0, which means that no badge is displayed. + */ + presentLocalNotification(details: PresentLocalNotificationDetails): void; + + /** + * Schedules the localNotification for future presentation. + * details is an object containing: + * fireDate : The date and time when the system should deliver the notification. + * alertBody : The message displayed in the notification alert. + * alertAction : The "action" displayed beneath an actionable notification. Defaults to "view"; + * soundName : The sound played when the notification is fired (optional). + * category : The category of this notification, required for actionable notifications (optional). + * userInfo : An optional object containing additional notification data. + * applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. Setting the number to 0 removes the icon badge. + */ + scheduleLocalNotification(details: ScheduleLocalNotificationDetails): void; + + /** + * Cancels all scheduled localNotifications + */ + cancelAllLocalNotifications(): void; + + /** + * Remove all delivered notifications from Notification Center. + * + * See https://facebook.github.io/react-native/docs/pushnotificationios.html#removealldeliverednotifications + */ + removeAllDeliveredNotifications(): void; + + /** + * Provides you with a list of the app’s notifications that are still displayed in Notification Center. + * + * See https://facebook.github.io/react-native/docs/pushnotificationios.html#getdeliverednotifications + */ + getDeliveredNotifications( + callback: (notifications: Record[]) => void, + ): void; + + /** + * Removes the specified notifications from Notification Center + * + * See https://facebook.github.io/react-native/docs/pushnotificationios.html#removedeliverednotifications + */ + removeDeliveredNotifications(identifiers: string[]): void; + + /** + * Sets the badge number for the app icon on the home screen + */ + setApplicationIconBadgeNumber(number: number): void; + + /** + * Gets the current badge number for the app icon on the home screen + */ + getApplicationIconBadgeNumber(callback: (badge: number) => void): void; + + /** + * Cancel local notifications. + * Optionally restricts the set of canceled notifications to those notifications whose userInfo fields match the corresponding fields in the userInfo argument. + */ + cancelLocalNotifications(userInfo: Record): void; + + /** + * Gets the local notifications that are currently scheduled. + */ + getScheduledLocalNotifications( + callback: (notifications: ScheduleLocalNotificationDetails[]) => void, + ): void; + + /** + * Attaches a listener to remote notifications while the app is running in the + * foreground or the background. + * + * The handler will get be invoked with an instance of `PushNotificationIOS` + * + * The type MUST be 'notification' + */ + addEventListener( + type: 'notification' | 'localNotification', + handler: (notification: PushNotification) => void, + ): void; + + /** + * Fired when the user registers for remote notifications. + * + * The handler will be invoked with a hex string representing the deviceToken. + * + * The type MUST be 'register' + */ + addEventListener( + type: 'register', + handler: (deviceToken: string) => void, + ): void; + + /** + * Fired when the user fails to register for remote notifications. + * Typically occurs when APNS is having issues, or the device is a simulator. + * + * The handler will be invoked with {message: string, code: number, details: any}. + * + * The type MUST be 'registrationError' + */ + addEventListener( + type: 'registrationError', + handler: (error: {message: string; code: number; details: any}) => void, + ): void; + + /** + * Removes the event listener. Do this in `componentWillUnmount` to prevent + * memory leaks + */ + removeEventListener( type: PushNotificationEventName, handler: - | ((notification: PushNotification) => void) - | ((deviceToken: string) => void) - | ((error: { message: string; code: number; details: any }) => void), - ): void - - /** - * Requests all notification permissions from iOS, prompting the user's - * dialog box. - */ - requestPermissions( + | ((notification: PushNotification) => void) + | ((deviceToken: string) => void) + | ((error: {message: string; code: number; details: any}) => void), + ): void; + + /** + * Requests all notification permissions from iOS, prompting the user's + * dialog box. + */ + requestPermissions( permissions?: PushNotificationPermissions[] | PushNotificationPermissions, - ): Promise - - /** - * Unregister for all remote notifications received via Apple Push - * Notification service. - * You should call this method in rare circumstances only, such as when - * a new version of the app removes support for all types of remote - * notifications. Users can temporarily prevent apps from receiving - * remote notifications through the Notifications section of the - * Settings app. Apps unregistered through this method can always - * re-register. - */ - abandonPermissions(): void - - /** - * See what push permissions are currently enabled. `callback` will be - * invoked with a `permissions` object: - * - * - `alert` :boolean - * - `badge` :boolean - * - `sound` :boolean - */ - checkPermissions(callback: (permissions: PushNotificationPermissions) => void): void - - /** - * This method returns a promise that resolves to either the notification - * object if the app was launched by a push notification, or `null` otherwise. - */ - getInitialNotification(): Promise -} + ): Promise; -declare const PushNotificationIOS: PushNotificationIOSStatic + /** + * Unregister for all remote notifications received via Apple Push + * Notification service. + * You should call this method in rare circumstances only, such as when + * a new version of the app removes support for all types of remote + * notifications. Users can temporarily prevent apps from receiving + * remote notifications through the Notifications section of the + * Settings app. Apps unregistered through this method can always + * re-register. + */ + abandonPermissions(): void; + + /** + * See what push permissions are currently enabled. `callback` will be + * invoked with a `permissions` object: + * + * - `alert` :boolean + * - `badge` :boolean + * - `sound` :boolean + */ + checkPermissions( + callback: (permissions: PushNotificationPermissions) => void, + ): void; + + /** + * This method returns a promise that resolves to either the notification + * object if the app was launched by a push notification, or `null` otherwise. + */ + getInitialNotification(): Promise; +} -export = PushNotificationIOS +declare const PushNotificationIOS: PushNotificationIOSStatic; +export = PushNotificationIOS; diff --git a/package.json b/package.json index 36ad50702..8d88bac5f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "metro-react-native-babel-preset": "0.51.1", "prettier": "^1.19.1", "react": "16.6.3", - "react-native": "0.58.4" + "react-native": "0.58.4", + "typescript": "^3.7.4" }, "repository": { "type": "git", diff --git a/yarn.lock b/yarn.lock index 5e341feb9..38f8db2e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6264,6 +6264,11 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= +typescript@^3.7.4: + version "3.7.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19" + integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw== + ua-parser-js@^0.7.18: version "0.7.19" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.19.tgz#94151be4c0a7fb1d001af7022fdaca4642659e4b"