[types][flow] Fix #1558

This commit is contained in:
Salakar
2019-01-04 00:26:08 +00:00
parent f752ab01af
commit 71e0489139
2 changed files with 23 additions and 26 deletions

View File

@@ -20,64 +20,61 @@ type CompletionHandler = BackgroundFetchResultValue => void;
export default class IOSNotification {
_alertAction: string | void;
// alertAction | N/A
_attachments: IOSAttachment[];
// N/A | attachments
_badge: number | void;
// applicationIconBadgeNumber | badge
_category: string | void;
_hasAction: boolean | void;
// hasAction | N/A
_launchImage: string | void;
// alertLaunchImage | launchImageName
_notification: Notification;
_threadIdentifier: string | void; // N/A | threadIdentifier
_threadIdentifier: string | void;
_complete: CompletionHandler;
constructor(
notification: Notification,
notifications: Notifications,
notifications?: Notifications,
data?: NativeIOSNotification
) {
this._notification = notification;
if (data) {
this._alertAction = data.alertAction;
this._attachments = data.attachments;
this._attachments = data.attachments || [];
this._badge = data.badge;
this._category = data.category;
this._hasAction = data.hasAction;
this._launchImage = data.launchImage;
this._threadIdentifier = data.threadIdentifier;
} else {
this._attachments = [];
}
if (isIOS && notifications && notifications.ios) {
const complete = (fetchResult: BackgroundFetchResultValue) => {
const { notificationId } = notification;
if (notificationId) {
getLogger(notifications).debug(
`Completion handler called for notificationId=${notificationId}`
);
getNativeModule(notifications).complete(notificationId, fetchResult);
}
};
if (!isIOS || !notifications || !notifications.ios) {
return this;
}
if (notifications.ios.shouldAutoComplete) {
complete(notifications.ios.backgroundFetchResult.noData);
} else {
this._complete = complete;
// IOS + Native Notification Only
const complete = (fetchResult: BackgroundFetchResultValue) => {
const { notificationId } = notification;
if (notificationId) {
getLogger(notifications).debug(
`Completion handler called for notificationId=${notificationId}`
);
getNativeModule(notifications).complete(notificationId, fetchResult);
}
}
};
// Defaults
this._attachments = this._attachments || [];
if (notifications.ios.shouldAutoComplete) {
complete(notifications.ios.backgroundFetchResult.noData);
} else {
this._complete = complete;
}
}
get alertAction(): ?string {

View File

@@ -40,7 +40,7 @@ export default class Notification {
constructor(
nativeNotification?: NativeNotification,
notifications: Notifications
notifications?: Notifications
) {
if (nativeNotification) {
this._body = nativeNotification.body;