Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  PESDKModule.m
  3. //  PESDKDemo
  4. //
  5. //  Created by Malte Baumann on 09/03/2017.
  6. //  Copyright © 2017 Facebook. All rights reserved.
  7. //
  8.  
  9. #import "PESDKModule.h"
  10. #import <React/RCTUtils.h>
  11. #import <PhotoEditorSDK/PhotoEditorSDK.h>
  12.  
  13. @interface PESDKModule () <PESDKPhotoEditViewControllerDelegate>
  14. @end
  15.  
  16. @implementation PESDKModule
  17.  
  18. RCT_EXPORT_MODULE(PESDK);
  19.  
  20. RCT_EXPORT_METHOD(present:(NSString *)path) {
  21.   dispatch_async(dispatch_get_main_queue(), ^{
  22.     PESDKPhotoEditViewController *photoEditViewController = [[PESDKPhotoEditViewController alloc] initWithPhotoAsset:[[PESDKPhoto alloc] initWithData:[NSData dataWithContentsOfFile:path]] configuration:[[PESDKConfiguration alloc] init]];
  23.     photoEditViewController.delegate = self;
  24.    
  25.     UIViewController *currentViewController = RCTPresentedViewController();
  26.     [currentViewController presentViewController:photoEditViewController animated:YES completion:NULL];
  27.   });
  28. }
  29.  
  30. #pragma mark - IMGLYPhotoEditViewControllerDelegate
  31.  
  32. - (void)photoEditViewController:(PESDKPhotoEditViewController *)photoEditViewController didSaveImage:(UIImage *)image imageAsData:(NSData *)data {
  33.   [photoEditViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{
  34.     [self sendEventWithName:@"PhotoEditorDidSave" body:@{ @"image": [UIImageJPEGRepresentation(image, 1.0) base64EncodedStringWithOptions: 0], @"data": [data base64EncodedStringWithOptions:0] }];
  35.   }];
  36. }
  37.  
  38. - (void)photoEditViewControllerDidCancel:(PESDKPhotoEditViewController *)photoEditViewController {
  39.   [photoEditViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{
  40.     [self sendEventWithName:@"PhotoEditorDidCancel" body:@{}];
  41.   }];
  42. }
  43.  
  44. - (void)photoEditViewControllerDidFailToGeneratePhoto:(PESDKPhotoEditViewController *)photoEditViewController {
  45.   [self sendEventWithName:@"PhotoEditorDidFailToGeneratePhoto" body:@{}];
  46. }
  47.  
  48. #pragma mark - RCTEventEmitter
  49.  
  50. - (NSArray<NSString *> *)supportedEvents {
  51.   return @[ @"PhotoEditorDidSave", @"PhotoEditorDidCancel", @"PhotoEditorDidFailToGeneratePhoto" ];
  52. }
  53.  
  54. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement