Skip to content

Commit

Permalink
Add version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
leontobias committed May 2, 2023
1 parent 3382241 commit eb4631f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 61 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<void>`.
* [react-native-photoeditorsdk] Unlocking the SDK via `PESDK.unlockWithLicense` now returns a `Promise<void>`.

### Fixed

* [react-native-videoeditorsdk] Fixed unused types exports.

## [2.17.1]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?) {
Expand Down
22 changes: 12 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<PhotoEditorResult | null>
): Promise<PhotoEditorResult | null>;

/**
* Unlock PhotoEditor SDK with a license.
Expand All @@ -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<void>;
}

/**
Expand All @@ -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.
Expand Down Expand Up @@ -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<PhotoEditorModalProps, PhotoEditorModalState> {}
declare class PhotoEditorModal extends Component<
PhotoEditorModalProps,
PhotoEditorModalState
> {}

export * from "./configuration";
export { PESDK, PhotoEditorModal };
export * from './configuration';

9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -196,5 +196,6 @@ class PhotoEditorModal extends Component {
}
}

export { PESDK, PhotoEditorModal };
export * from './configuration';
export { PESDK, PhotoEditorModal };

41 changes: 13 additions & 28 deletions ios/RNImglyKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down
11 changes: 5 additions & 6 deletions ios/RNImglyKitSubclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
16 changes: 8 additions & 8 deletions ios/RNPhotoEditorSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}

0 comments on commit eb4631f

Please sign in to comment.