[notifications][ios] Properly define attachment options

This commit is contained in:
Chris Bianca 2018-03-01 08:39:24 +00:00
parent ee3b2932ef
commit 7acace4ce6
4 changed files with 38 additions and 21 deletions

View File

@ -463,10 +463,27 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
for (NSDictionary *a in ios[@"attachments"]) {
NSString *identifier = a[@"identifier"];
NSURL *url = [NSURL URLWithString:a[@"url"]];
NSDictionary *options = a[@"options"];
NSMutableDictionary *attachmentOptions = nil;
if (a[@"options"]) {
NSDictionary *options = a[@"options"];
attachmentOptions = [[NSMutableDictionary alloc] init];
for (id key in options) {
if ([key isEqualToString:@"typeHint"]) {
attachmentOptions[UNNotificationAttachmentOptionsTypeHintKey] = options[key];
} else if ([key isEqualToString:@"thumbnailHidden"]) {
attachmentOptions[UNNotificationAttachmentOptionsThumbnailHiddenKey] = options[key];
} else if ([key isEqualToString:@"thumbnailClippingRect"]) {
attachmentOptions[UNNotificationAttachmentOptionsThumbnailClippingRectKey] = options[key];
} else if ([key isEqualToString:@"thumbnailTime"]) {
attachmentOptions[UNNotificationAttachmentOptionsThumbnailTimeKey] = options[key];
}
}
}
NSError *error;
UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:identifier URL:url options:options error:&error];
UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:identifier URL:url options:attachmentOptions error:&error];
if (attachment) {
[attachments addObject:attachment];
} else {

View File

@ -4,14 +4,14 @@
*/
import type Notification from './Notification';
import type {
Attachment,
AttachmentOptions,
IOSAttachment,
IOSAttachmentOptions,
NativeIOSNotification,
} from './types';
export default class IOSNotification {
_alertAction: string | void; // alertAction | N/A
_attachments: Attachment[]; // N/A | attachments
_attachments: IOSAttachment[]; // N/A | attachments
_badge: number | void; // applicationIconBadgeNumber | badge
_category: string | void;
_hasAction: boolean | void; // hasAction | N/A
@ -40,7 +40,7 @@ export default class IOSNotification {
return this._alertAction;
}
get attachments(): Attachment[] {
get attachments(): IOSAttachment[] {
return this._attachments;
}
@ -74,7 +74,7 @@ export default class IOSNotification {
addAttachment(
identifier: string,
url: string,
options?: AttachmentOptions
options?: IOSAttachmentOptions
): Notification {
this._attachments.push({
identifier,

View File

@ -115,27 +115,27 @@ export type NativeAndroidNotification = {|
when?: number,
|};
export type AttachmentOptions = {|
TypeHint: string,
ThumbnailHidden: boolean,
ThumbnailClippingRect: {
export type IOSAttachmentOptions = {|
typeHint: string,
thumbnailHidden: boolean,
thumbnailClippingRect: {
height: number,
width: number,
x: number,
y: number,
},
ThumbnailTime: number,
thumbnailTime: number,
|};
export type Attachment = {|
export type IOSAttachment = {|
identifier: string,
options?: AttachmentOptions,
options?: IOSAttachmentOptions,
url: string,
|};
export type NativeIOSNotification = {|
alertAction?: string,
attachments: Attachment[],
attachments: IOSAttachment[],
badge?: number,
category?: string,
hasAction?: boolean,

View File

@ -18,7 +18,7 @@ import type {
const FirebaseCoreModule = NativeModules.RNFirebase;
const APPS: { [string]: App } = {};
const APP_MODULES: { [App]: { [string]: FirebaseModule } } = {};
const APP_MODULES: { [string]: { [string]: FirebaseModule } } = {};
const DEFAULT_APP_NAME = '[DEFAULT]';
export default {
@ -49,8 +49,8 @@ export default {
InstanceClass: Class<M>
): () => FirebaseModule {
return (): M => {
if (!APP_MODULES[app]) {
APP_MODULES[app] = {};
if (!APP_MODULES[app._name]) {
APP_MODULES[app._name] = {};
}
if (
@ -62,11 +62,11 @@ export default {
app.utils().checkPlayServicesAvailability();
}
if (!APP_MODULES[app][namespace]) {
APP_MODULES[app][namespace] = new InstanceClass(app, app.options);
if (!APP_MODULES[app._name][namespace]) {
APP_MODULES[app._name][namespace] = new InstanceClass(app, app.options);
}
return APP_MODULES[app][namespace];
return APP_MODULES[app._name][namespace];
};
},