diff --git a/CHANGELOG.md b/CHANGELOG.md index 782b76e..542b66a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## [3.0.0] + +### Changed + +* Changed and aligned the error codes for the modules. +* [react-native-videoeditorsdk] Unlocking the SDK via `VESDK.unlockWithLicense` now returns a `Promise`. +* [react-native-photoeditorsdk] Unlocking the SDK via `PESDK.unlockWithLicense` now returns a `Promise`. + +### Fixed + +* [react-native-videoeditorsdk] Fixed unused types exports. + ## [2.17.1] ### Fixed diff --git a/android/src/main/java/ly/img/react_native/pesdk/RNPhotoEditorSDKModule.kt b/android/src/main/java/ly/img/react_native/pesdk/RNPhotoEditorSDKModule.kt index 02ec3e9..ef0e725 100644 --- a/android/src/main/java/ly/img/react_native/pesdk/RNPhotoEditorSDKModule.kt +++ b/android/src/main/java/ly/img/react_native/pesdk/RNPhotoEditorSDKModule.kt @@ -6,6 +6,7 @@ import android.net.Uri import android.util.Log import androidx.annotation.WorkerThread import com.facebook.react.bridge.* +import ly.img.android.AuthorizationException import ly.img.android.IMGLY import ly.img.android.PESDK import ly.img.android.pesdk.PhotoEditorSettingsList @@ -47,13 +48,23 @@ class RNPhotoEditorSDKModule(val reactContext: ReactApplicationContext) : ReactC reactContext.addActivityEventListener(this) } + /** IMGLY constants for the plugin use. */ + object IMGLYConstants { + const val K_ERROR_UNABLE_TO_UNLOCK = "E_UNABLE_TO_UNLOCK" + } + private var currentPromise: Promise? = null private var currentConfig: Configuration? = null @ReactMethod - fun unlockWithLicense(license: String) { - PESDK.initSDKWithLicenseData(license) - IMGLY.authorize() + fun unlockWithLicense(license: String, promise: Promise) { + try { + PESDK.initSDKWithLicenseData(license) + IMGLY.authorize() + promise.resolve(null) + } catch (e: AuthorizationException) { + promise.reject(IMGLYConstants.K_ERROR_UNABLE_TO_UNLOCK, "Unlocking the SDK failed due to: ${e.message}.") + } } override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, intent: Intent?) { diff --git a/index.d.ts b/index.d.ts index bcdc88a..4aaa095 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,5 @@ -import { Component } from 'react'; -import { Configuration } from './configuration'; +import { Component } from "react"; +import { Configuration } from "./configuration"; /** * The result of an export. @@ -33,10 +33,10 @@ declare class PESDK { * is dismissed without exporting the edited image. */ static openEditor( - image: string | {uri: string} | number, + image: string | { uri: string } | number, configuration?: Configuration, serialization?: object - ): Promise + ): Promise; /** * Unlock PhotoEditor SDK with a license. @@ -48,9 +48,7 @@ declare class PESDK { * and `pesdk_license.android.json` for the Android license file in order to get automatically * resolved by the packager. */ - static unlockWithLicense( - license: string | object - ): void + static unlockWithLicense(license: string | object): Promise; } /** @@ -74,7 +72,7 @@ interface PhotoEditorModalProps { * @note EXIF meta data is only preserved in the edited image if and only if the source * image is loaded from a local `file://` resource. */ - image?: string | {uri: string} | number; + image?: string | { uri: string } | number; /** * This prop determines the configuration used to initialize the editor. @@ -118,7 +116,11 @@ interface PhotoEditorModalState { /** * A component that wraps the `PESDK.openEditor` function to modally present a photo editor. */ -declare class PhotoEditorModal extends Component {} +declare class PhotoEditorModal extends Component< + PhotoEditorModalProps, + PhotoEditorModalState +> {} +export * from "./configuration"; export { PESDK, PhotoEditorModal }; -export * from './configuration'; + diff --git a/index.js b/index.js index cbef36e..866fba0 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ import { Component } from 'react'; -import { NativeModules, Image, Platform } from 'react-native'; +import { Image, NativeModules, Platform } from 'react-native'; import { Configuration } from './configuration'; const { RNPhotoEditorSDK } = NativeModules; @@ -158,9 +158,9 @@ class PESDK { */ static unlockWithLicense(license) { if (Platform.OS == 'android') { - RNPhotoEditorSDK.unlockWithLicense(JSON.stringify(license)); + return RNPhotoEditorSDK.unlockWithLicense(JSON.stringify(license)); } else { - RNPhotoEditorSDK.unlockWithLicense(license); + return RNPhotoEditorSDK.unlockWithLicense(license); } } } @@ -196,5 +196,6 @@ class PhotoEditorModal extends Component { } } -export { PESDK, PhotoEditorModal }; export * from './configuration'; +export { PESDK, PhotoEditorModal }; + diff --git a/ios/RNImglyKit.m b/ios/RNImglyKit.m index 5150cf4..114d46e 100644 --- a/ios/RNImglyKit.m +++ b/ios/RNImglyKit.m @@ -63,11 +63,6 @@ - (void)present:(nonnull IMGLYMediaEditViewControllerBlock)createMediaEditViewCo } dispatch_async(dispatch_get_main_queue(), ^{ - if (self.licenseError != nil) { - reject(RN_IMGLY.kErrorUnableToUnlock, [NSString RN_IMGLY_string:@"Unable to unlock with license." withError:self.licenseError], self.licenseError); - return; - } - PESDKAssetCatalog *assetCatalog = PESDKAssetCatalog.defaultItems; PESDKConfiguration *configuration = [[PESDKConfiguration alloc] initWithBuilder:^(PESDKConfigurationBuilder * _Nonnull builder) { builder.assetCatalog = assetCatalog; @@ -169,34 +164,24 @@ - (void)dismiss:(nullable PESDKMediaEditViewController *)mediaEditViewController }); } -- (void)handleLicenseError:(nullable NSError *)error +- (void)handleLicenseError:(nullable NSError *)error resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject { - self.licenseError = nil; if (error != nil) { - if ([error.domain isEqualToString:@"ImglyKit.IMGLY.Error"]) { - switch (error.code) { - case 3: - RCTLogWarn(@"%@: %@", NSStringFromClass(self.class), error.localizedDescription); - break; - default: - self.licenseError = error; - RCTLogError(@"%@: %@", NSStringFromClass(self.class), error.localizedDescription); - break; - } - } else { - self.licenseError = error; - RCTLogError(@"Error while unlocking with license: %@", error); - } + reject(RN_IMGLY.kErrorUnableToUnlock, [NSString RN_IMGLY_string:@"Unable to unlock with license." withError:error], error); + return; + } else { + resolve(nil); + return; } } -- (void)unlockWithLicenseURL:(nonnull NSURL *)url {} +- (void)unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {} -- (void)unlockWithLicenseString:(nonnull NSString *)string {} +- (void)unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {} -- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary {} +- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {} -- (void)unlockWithLicense:(nonnull id)json +- (void)unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject { NSString *string = nil; NSURL *url = nil; @@ -222,14 +207,14 @@ - (void)unlockWithLicense:(nonnull id)json } if (url != nil) { - [self unlockWithLicenseURL:url]; + [self unlockWithLicenseURL:url resolve:resolve reject:reject]; } else if (string != nil) { - [self unlockWithLicenseString:string]; + [self unlockWithLicenseString:string resolve:resolve reject:reject]; } else if ([json isKindOfClass:[NSDictionary class]]) { NSDictionary *dictionary = json; - [self unlockWithLicenseObject:dictionary]; + [self unlockWithLicenseObject:dictionary resolve:resolve reject:reject]; } else if (json) { RCTLogConvertError(json, @"a valid license format"); diff --git a/ios/RNImglyKitSubclass.h b/ios/RNImglyKitSubclass.h index 1007a7f..e42f7e0 100644 --- a/ios/RNImglyKitSubclass.h +++ b/ios/RNImglyKitSubclass.h @@ -50,7 +50,6 @@ typedef void (^IMGLYCompletionBlock)(void); @property (class, strong, atomic, nullable) IMGLYConfigurationBlock configureWithBuilder; -@property (strong, atomic, nullable) NSError* licenseError; @property (strong, atomic, nullable) NSString* exportType; @property (strong, atomic, nullable) NSURL* exportFile; @property (atomic) BOOL serializationEnabled; @@ -68,11 +67,11 @@ typedef void (^IMGLYCompletionBlock)(void); resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; - (void)dismiss:(nullable PESDKMediaEditViewController *)mediaEditViewController animated:(BOOL)animated completion:(nullable IMGLYCompletionBlock)completion; -- (void)handleLicenseError:(nullable NSError *)error; -- (void)unlockWithLicenseURL:(nonnull NSURL *)url; -- (void)unlockWithLicenseString:(nonnull NSString *)string; -- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary; -- (void)unlockWithLicense:(nonnull id)json; +- (void)handleLicenseError:(nullable NSError *)error resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; +- (void)unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; +- (void)unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; +- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; +- (void)unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; extern const struct RN_IMGLY_Constants { diff --git a/ios/RNPhotoEditorSDK.m b/ios/RNPhotoEditorSDK.m index ddeb397..893e2ca 100644 --- a/ios/RNPhotoEditorSDK.m +++ b/ios/RNPhotoEditorSDK.m @@ -78,36 +78,36 @@ - (void)present:(nullable PESDKPhoto *)photo withConfiguration:(nullable NSDicti } configuration:dictionary serialization:state resolve:resolve reject:reject]; } -RCT_EXPORT_METHOD(unlockWithLicenseURL:(nonnull NSURL *)url) +RCT_EXPORT_METHOD(unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = nil; [PESDK unlockWithLicenseFromURL:url error:&error]; - [self handleLicenseError:error]; + [self handleLicenseError:error resolve:resolve reject:reject]; }); } -RCT_EXPORT_METHOD(unlockWithLicenseString:(nonnull NSString *)string) +RCT_EXPORT_METHOD(unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = nil; [PESDK unlockWithLicenseFromString:string error:&error]; - [self handleLicenseError:error]; + [self handleLicenseError:error resolve:resolve reject:reject]; }); } -RCT_EXPORT_METHOD(unlockWithLicenseObject:(nonnull NSDictionary *)dictionary) +RCT_EXPORT_METHOD(unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = nil; [PESDK unlockWithLicenseFromDictionary:dictionary error:&error]; - [self handleLicenseError:error]; + [self handleLicenseError:error resolve:resolve reject:reject]; }); } -RCT_EXPORT_METHOD(unlockWithLicense:(nonnull id)json) +RCT_EXPORT_METHOD(unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject) { - [super unlockWithLicense:json]; + [super unlockWithLicense:json resolve:resolve reject:reject]; } RCT_EXPORT_METHOD(present:(nullable NSURLRequest *)request diff --git a/package.json b/package.json index 4ceae4c..449b0a3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-photoeditorsdk", "title": "React Native module for PhotoEditor SDK", - "version": "2.17.1", + "version": "3.0.0", "description": "A React Native module for PhotoEditor SDK. Integrate the photo editor into your own HTML5, iOS or Android app - in minutes!", "main": "index.js", "typings": "index.d.ts", @@ -38,6 +38,6 @@ "react-native": ">=0.60.0 <1.0.x" }, "dependencies": { - "react-native-imglysdk": "2.17.1" + "react-native-imglysdk": "3.0.0" } }