Add RCTConverter+UIBackgroundFetchResult to handle auto conversion

This commit is contained in:
Ryan Grey 2018-07-27 14:45:20 +01:00
parent 5168f96a32
commit b53695ad52
5 changed files with 54 additions and 10 deletions

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
168785AD210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 168785AB210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m */; };
17AF4F6B1F59CDBF00C02336 /* RNFirebaseLinks.m in Sources */ = {isa = PBXBuildFile; fileRef = 17AF4F6A1F59CDBF00C02336 /* RNFirebaseLinks.m */; };
27540F9A209F3641001F4AF4 /* RNFirebaseFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 27540F99209F3641001F4AF4 /* RNFirebaseFunctions.m */; };
8300A7AE1F31E143001B16AB /* RNFirebaseDatabaseReference.m in Sources */ = {isa = PBXBuildFile; fileRef = 8300A7AD1F31E143001B16AB /* RNFirebaseDatabaseReference.m */; };
@ -50,6 +51,8 @@
/* Begin PBXFileReference section */
134814201AA4EA6300B7C361 /* libRNFirebase.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFirebase.a; sourceTree = BUILT_PRODUCTS_DIR; };
168785AB210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+UIBackgroundFetchResult.m"; sourceTree = "<group>"; };
168785AC210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+UIBackgroundFetchResult.h"; sourceTree = "<group>"; };
17AF4F691F59CDBF00C02336 /* RNFirebaseLinks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNFirebaseLinks.h; sourceTree = "<group>"; };
17AF4F6A1F59CDBF00C02336 /* RNFirebaseLinks.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFirebaseLinks.m; sourceTree = "<group>"; };
27540F98209F361B001F4AF4 /* RNFirebaseFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFirebaseFunctions.h; sourceTree = "<group>"; };
@ -126,6 +129,16 @@
name = Products;
sourceTree = "<group>";
};
168785A0210B50AA00E4BD57 /* converters */ = {
isa = PBXGroup;
children = (
168785AC210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.h */,
168785AB210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m */,
);
name = converters;
path = RNFirebase/converters;
sourceTree = "<group>";
};
17AF4F681F59CDBF00C02336 /* links */ = {
isa = PBXGroup;
children = (
@ -149,6 +162,7 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
168785A0210B50AA00E4BD57 /* converters */,
27540F97209F35DF001F4AF4 /* functions */,
83AAA0762063DEC2007EC5F7 /* invites */,
838E372420231E15004DCD3A /* notifications */,
@ -398,6 +412,7 @@
27540F9A209F3641001F4AF4 /* RNFirebaseFunctions.m in Sources */,
838E372320231DF0004DCD3A /* RNFirebaseInstanceId.m in Sources */,
839D916E1EF3E20B0077C7C8 /* RNFirebaseAdMobRewardedVideo.m in Sources */,
168785AD210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m in Sources */,
839D916C1EF3E20B0077C7C8 /* RNFirebaseAdMob.m in Sources */,
17AF4F6B1F59CDBF00C02336 /* RNFirebaseLinks.m in Sources */,
8376F7161F7C149100D45A85 /* RNFirebaseFirestoreCollectionReference.m in Sources */,

View File

@ -0,0 +1,5 @@
#import <React/RCTConvert.h>
@interface RCTConvert (UIBackgroundFetchResult)
@end

View File

@ -0,0 +1,9 @@
#import "RCTConvert+UIBackgroundFetchResult.h"
@implementation RCTConvert (UIBackgroundFetchResult)
RCT_ENUM_CONVERTER(UIBackgroundFetchResult, (@{ @"backgroundFetchResultNoData" : @(UIBackgroundFetchResultNoData),
@"backgroundFetchResultNewData" : @(UIBackgroundFetchResultNewData),
@"backgroundFetchResultFailed" : @(UIBackgroundFetchResultFailed)}),
UIBackgroundFetchResultNoData, integerValue)
@end

View File

@ -113,16 +113,7 @@ RCT_EXPORT_METHOD(stopHandlingNotificationDisplayed) {
completionHandlers = nil;
}
RCT_EXPORT_METHOD(complete:(NSString*)handlerKey fetchResult:(NSString *)rnFetchResult) {
UIBackgroundFetchResult fetchResult = UIBackgroundFetchResultNoData;
if ([@"noData" isEqualToString:rnFetchResult]) {
fetchResult = UIBackgroundFetchResultNoData;
} else if ([@"newData" isEqualToString:rnFetchResult]) {
fetchResult = UIBackgroundFetchResultNewData;
} else if ([@"failed" isEqualToString:rnFetchResult]) {
fetchResult = UIBackgroundFetchResultFailed;
}
RCT_EXPORT_METHOD(complete:(NSString*)handlerKey fetchResult:(UIBackgroundFetchResult)fetchResult) {
void (^completionHandler)(UIBackgroundFetchResult) = completionHandlers[handlerKey];
completionHandlers[handlerKey] = nil;
@ -787,6 +778,12 @@ RCT_EXPORT_METHOD(jsInitialised:(RCTPromiseResolveBlock)resolve rejecter:(RCTPro
return @[NOTIFICATIONS_NOTIFICATION_DISPLAYED, NOTIFICATIONS_NOTIFICATION_OPENED, NOTIFICATIONS_NOTIFICATION_RECEIVED];
}
- (NSDictionary *) constantsToExport {
return @{ @"backgroundFetchResultNoData" : @(UIBackgroundFetchResultNoData),
@"backgroundFetchResultNewData" : @(UIBackgroundFetchResultNewData),
@"backgroundFetchResultFailed" : @(UIBackgroundFetchResultFailed)};
}
+ (BOOL)requiresMainQueueSetup
{
return YES;

View File

@ -45,6 +45,12 @@ type OnNotificationOpenedObserver = {
next: NotificationOpen,
};
type BackgroundFetchResult = {
noData: string,
newData: string,
failure: string,
};
const NATIVE_EVENTS = [
'notifications_notification_displayed',
'notifications_notification_opened',
@ -78,6 +84,7 @@ const hasListeners = (eventType: string): boolean => {
*/
export default class Notifications extends ModuleBase {
_android: AndroidNotifications;
_backgroundFetchResult: BackgroundFetchResult;
constructor(app: App) {
super(app, {
@ -89,6 +96,13 @@ export default class Notifications extends ModuleBase {
});
this._android = new AndroidNotifications(this);
const nativeModule = getNativeModule(this);
this._backgroundFetchResult = {
noData: nativeModule.backgroundFetchResultNoData,
newData: nativeModule.backgroundFetchResultNewData,
failure: nativeModule.backgroundFetchResultFailure,
};
SharedEventEmitter.addListener(
// sub to internal native event - this fans out to
// public event name: onNotificationDisplayed
@ -153,6 +167,10 @@ export default class Notifications extends ModuleBase {
return this._android;
}
get backgroundFetchResult(): BackgroundFetchResult {
return { ...this._backgroundFetchResult };
}
/**
* Cancel all notifications
*/