CompletionCallbackWrapper.ts 1.03 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2
import { NativeCommandsSender } from './NativeCommandsSender';
import { NotificationCompletion, Notification } from '../interfaces/Notification';
yogevbd's avatar
yogevbd committed
3
import { Platform } from 'react-native';
yogevbd's avatar
yogevbd committed
4 5 6 7 8 9 10 11
export class CompletionCallbackWrapper {
  constructor(
    private readonly nativeCommandsSender: NativeCommandsSender
  ) {}

  public wrapReceivedCallback(callback: Function): (notification: Notification) => void {
    return (notification) => {
      const completion = (response: NotificationCompletion) => {
yogevbd's avatar
yogevbd committed
12 13 14
        if (Platform.OS === 'ios') {
          this.nativeCommandsSender.finishPresentingNotification(notification.identifier, response);
        }
yogevbd's avatar
yogevbd committed
15 16 17 18 19 20
      };

      callback(notification, completion);
    }
  }

yogevbd's avatar
yogevbd committed
21 22
  public wrapOpenedCallback(callback: Function): (notification: Notification) => void {
    return (notification) => {
yogevbd's avatar
yogevbd committed
23
      const completion = () => {
yogevbd's avatar
yogevbd committed
24 25 26
        if (Platform.OS === 'ios') {
          this.nativeCommandsSender.finishHandlingAction(notification.identifier);
        }
yogevbd's avatar
yogevbd committed
27 28
      };

yogevbd's avatar
yogevbd committed
29
      callback(notification, completion);
yogevbd's avatar
yogevbd committed
30 31 32
    }
  }
}