2
0
mirror of synced 2025-02-07 12:04:01 +00:00

Move ios API into IOSNotifications

This commit is contained in:
Ryan Grey 2018-08-14 15:28:21 +01:00
parent 1ad4b8c0dd
commit 000a4ec724
2 changed files with 41 additions and 31 deletions

View File

@ -0,0 +1,31 @@
import { getNativeModule } from '../../utils/native';
import type Notifications from '.';
export type BackgroundFetchResultValue = string;
type BackgroundFetchResult = {
noData: BackgroundFetchResultValue,
newData: BackgroundFetchResultValue,
failure: BackgroundFetchResultValue,
};
export default class IOSNotifications {
_backgroundFetchResult: BackgroundFetchResult;
shouldAutoComplete: boolean;
constructor(notifications: Notifications) {
this.shouldAutoComplete = true;
const nativeModule = getNativeModule(notifications);
this._backgroundFetchResult = {
noData: nativeModule.backgroundFetchResultNoData,
newData: nativeModule.backgroundFetchResultNewData,
failure: nativeModule.backgroundFetchResultFailure,
};
}
get backgroundFetchResult(): BackgroundFetchResult {
return { ...this._backgroundFetchResult };
}
}

View File

@ -12,6 +12,9 @@ import AndroidAction from './AndroidAction';
import AndroidChannel from './AndroidChannel'; import AndroidChannel from './AndroidChannel';
import AndroidChannelGroup from './AndroidChannelGroup'; import AndroidChannelGroup from './AndroidChannelGroup';
import AndroidNotifications from './AndroidNotifications'; import AndroidNotifications from './AndroidNotifications';
import IOSNotifications, {
type BackgroundFetchResultValue,
} from './IOSNotifications';
import AndroidRemoteInput from './AndroidRemoteInput'; import AndroidRemoteInput from './AndroidRemoteInput';
import Notification from './Notification'; import Notification from './Notification';
import { import {
@ -33,14 +36,6 @@ import type {
Schedule, Schedule,
} from './types'; } from './types';
type BackgroundFetchResultValue = string;
type BackgroundFetchResult = {
noData: BackgroundFetchResultValue,
newData: BackgroundFetchResultValue,
failure: BackgroundFetchResultValue,
};
type CompletionHandler = BackgroundFetchResultValue => void; type CompletionHandler = BackgroundFetchResultValue => void;
type OnNotification = (Notification, CompletionHandler) => any; type OnNotification = (Notification, CompletionHandler) => any;
@ -83,8 +78,8 @@ export const NAMESPACE = 'notifications';
*/ */
export default class Notifications extends ModuleBase { export default class Notifications extends ModuleBase {
_android: AndroidNotifications; _android: AndroidNotifications;
_shouldAutoComplete: boolean;
_backgroundFetchResult: BackgroundFetchResult; _ios: IOSNotifications;
constructor(app: App) { constructor(app: App) {
super(app, { super(app, {
@ -95,15 +90,7 @@ export default class Notifications extends ModuleBase {
namespace: NAMESPACE, namespace: NAMESPACE,
}); });
this._android = new AndroidNotifications(this); this._android = new AndroidNotifications(this);
this._ios = new IOSNotifications(this);
const nativeModule = getNativeModule(this);
this._backgroundFetchResult = {
noData: nativeModule.backgroundFetchResultNoData,
newData: nativeModule.backgroundFetchResultNewData,
failure: nativeModule.backgroundFetchResultFailure,
};
this.startAutoCompleting();
SharedEventEmitter.addListener( SharedEventEmitter.addListener(
// sub to internal native event - this fans out to // sub to internal native event - this fans out to
@ -128,8 +115,8 @@ export default class Notifications extends ModuleBase {
const publicEventName = 'onNotificationDisplayed'; const publicEventName = 'onNotificationDisplayed';
if (this._shouldAutoComplete) { if (this.ios.shouldAutoComplete) {
done(this.backgroundFetchResult.noData); done(this.ios.backgroundFetchResult.noData);
} }
SharedEventEmitter.emit(publicEventName, rnNotification, done); SharedEventEmitter.emit(publicEventName, rnNotification, done);
@ -171,16 +158,8 @@ export default class Notifications extends ModuleBase {
return this._android; return this._android;
} }
get backgroundFetchResult(): BackgroundFetchResult { get ios(): IOSNotifications {
return { ...this._backgroundFetchResult }; return this._ios;
}
startAutoCompleting(): void {
this._shouldAutoComplete = true;
}
stopAutoCompleting(): void {
this._shouldAutoComplete = false;
} }
/** /**