Skip to content

Commit eb4631f

Browse files
committed
Add version 3.0.0
1 parent 3382241 commit eb4631f

File tree

8 files changed

+71
-61
lines changed

8 files changed

+71
-61
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [3.0.0]
2+
3+
### Changed
4+
5+
* Changed and aligned the error codes for the modules.
6+
* [react-native-videoeditorsdk] Unlocking the SDK via `VESDK.unlockWithLicense` now returns a `Promise<void>`.
7+
* [react-native-photoeditorsdk] Unlocking the SDK via `PESDK.unlockWithLicense` now returns a `Promise<void>`.
8+
9+
### Fixed
10+
11+
* [react-native-videoeditorsdk] Fixed unused types exports.
12+
113
## [2.17.1]
214

315
### Fixed

android/src/main/java/ly/img/react_native/pesdk/RNPhotoEditorSDKModule.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.net.Uri
66
import android.util.Log
77
import androidx.annotation.WorkerThread
88
import com.facebook.react.bridge.*
9+
import ly.img.android.AuthorizationException
910
import ly.img.android.IMGLY
1011
import ly.img.android.PESDK
1112
import ly.img.android.pesdk.PhotoEditorSettingsList
@@ -47,13 +48,23 @@ class RNPhotoEditorSDKModule(val reactContext: ReactApplicationContext) : ReactC
4748
reactContext.addActivityEventListener(this)
4849
}
4950

51+
/** IMGLY constants for the plugin use. */
52+
object IMGLYConstants {
53+
const val K_ERROR_UNABLE_TO_UNLOCK = "E_UNABLE_TO_UNLOCK"
54+
}
55+
5056
private var currentPromise: Promise? = null
5157
private var currentConfig: Configuration? = null
5258

5359
@ReactMethod
54-
fun unlockWithLicense(license: String) {
55-
PESDK.initSDKWithLicenseData(license)
56-
IMGLY.authorize()
60+
fun unlockWithLicense(license: String, promise: Promise) {
61+
try {
62+
PESDK.initSDKWithLicenseData(license)
63+
IMGLY.authorize()
64+
promise.resolve(null)
65+
} catch (e: AuthorizationException) {
66+
promise.reject(IMGLYConstants.K_ERROR_UNABLE_TO_UNLOCK, "Unlocking the SDK failed due to: ${e.message}.")
67+
}
5768
}
5869

5970
override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, intent: Intent?) {

index.d.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Component } from 'react';
2-
import { Configuration } from './configuration';
1+
import { Component } from "react";
2+
import { Configuration } from "./configuration";
33

44
/**
55
* The result of an export.
@@ -33,10 +33,10 @@ declare class PESDK {
3333
* is dismissed without exporting the edited image.
3434
*/
3535
static openEditor(
36-
image: string | {uri: string} | number,
36+
image: string | { uri: string } | number,
3737
configuration?: Configuration,
3838
serialization?: object
39-
): Promise<PhotoEditorResult | null>
39+
): Promise<PhotoEditorResult | null>;
4040

4141
/**
4242
* Unlock PhotoEditor SDK with a license.
@@ -48,9 +48,7 @@ declare class PESDK {
4848
* and `pesdk_license.android.json` for the Android license file in order to get automatically
4949
* resolved by the packager.
5050
*/
51-
static unlockWithLicense(
52-
license: string | object
53-
): void
51+
static unlockWithLicense(license: string | object): Promise<void>;
5452
}
5553

5654
/**
@@ -74,7 +72,7 @@ interface PhotoEditorModalProps {
7472
* @note EXIF meta data is only preserved in the edited image if and only if the source
7573
* image is loaded from a local `file://` resource.
7674
*/
77-
image?: string | {uri: string} | number;
75+
image?: string | { uri: string } | number;
7876

7977
/**
8078
* This prop determines the configuration used to initialize the editor.
@@ -118,7 +116,11 @@ interface PhotoEditorModalState {
118116
/**
119117
* A component that wraps the `PESDK.openEditor` function to modally present a photo editor.
120118
*/
121-
declare class PhotoEditorModal extends Component<PhotoEditorModalProps, PhotoEditorModalState> {}
119+
declare class PhotoEditorModal extends Component<
120+
PhotoEditorModalProps,
121+
PhotoEditorModalState
122+
> {}
122123

124+
export * from "./configuration";
123125
export { PESDK, PhotoEditorModal };
124-
export * from './configuration';
126+

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from 'react';
2-
import { NativeModules, Image, Platform } from 'react-native';
2+
import { Image, NativeModules, Platform } from 'react-native';
33
import { Configuration } from './configuration';
44

55
const { RNPhotoEditorSDK } = NativeModules;
@@ -158,9 +158,9 @@ class PESDK {
158158
*/
159159
static unlockWithLicense(license) {
160160
if (Platform.OS == 'android') {
161-
RNPhotoEditorSDK.unlockWithLicense(JSON.stringify(license));
161+
return RNPhotoEditorSDK.unlockWithLicense(JSON.stringify(license));
162162
} else {
163-
RNPhotoEditorSDK.unlockWithLicense(license);
163+
return RNPhotoEditorSDK.unlockWithLicense(license);
164164
}
165165
}
166166
}
@@ -196,5 +196,6 @@ class PhotoEditorModal extends Component {
196196
}
197197
}
198198

199-
export { PESDK, PhotoEditorModal };
200199
export * from './configuration';
200+
export { PESDK, PhotoEditorModal };
201+

ios/RNImglyKit.m

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ - (void)present:(nonnull IMGLYMediaEditViewControllerBlock)createMediaEditViewCo
6363
}
6464

6565
dispatch_async(dispatch_get_main_queue(), ^{
66-
if (self.licenseError != nil) {
67-
reject(RN_IMGLY.kErrorUnableToUnlock, [NSString RN_IMGLY_string:@"Unable to unlock with license." withError:self.licenseError], self.licenseError);
68-
return;
69-
}
70-
7166
PESDKAssetCatalog *assetCatalog = PESDKAssetCatalog.defaultItems;
7267
PESDKConfiguration *configuration = [[PESDKConfiguration alloc] initWithBuilder:^(PESDKConfigurationBuilder * _Nonnull builder) {
7368
builder.assetCatalog = assetCatalog;
@@ -169,34 +164,24 @@ - (void)dismiss:(nullable PESDKMediaEditViewController *)mediaEditViewController
169164
});
170165
}
171166

172-
- (void)handleLicenseError:(nullable NSError *)error
167+
- (void)handleLicenseError:(nullable NSError *)error resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject
173168
{
174-
self.licenseError = nil;
175169
if (error != nil) {
176-
if ([error.domain isEqualToString:@"ImglyKit.IMGLY.Error"]) {
177-
switch (error.code) {
178-
case 3:
179-
RCTLogWarn(@"%@: %@", NSStringFromClass(self.class), error.localizedDescription);
180-
break;
181-
default:
182-
self.licenseError = error;
183-
RCTLogError(@"%@: %@", NSStringFromClass(self.class), error.localizedDescription);
184-
break;
185-
}
186-
} else {
187-
self.licenseError = error;
188-
RCTLogError(@"Error while unlocking with license: %@", error);
189-
}
170+
reject(RN_IMGLY.kErrorUnableToUnlock, [NSString RN_IMGLY_string:@"Unable to unlock with license." withError:error], error);
171+
return;
172+
} else {
173+
resolve(nil);
174+
return;
190175
}
191176
}
192177

193-
- (void)unlockWithLicenseURL:(nonnull NSURL *)url {}
178+
- (void)unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {}
194179

195-
- (void)unlockWithLicenseString:(nonnull NSString *)string {}
180+
- (void)unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {}
196181

197-
- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary {}
182+
- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {}
198183

199-
- (void)unlockWithLicense:(nonnull id)json
184+
- (void)unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject
200185
{
201186
NSString *string = nil;
202187
NSURL *url = nil;
@@ -222,14 +207,14 @@ - (void)unlockWithLicense:(nonnull id)json
222207
}
223208

224209
if (url != nil) {
225-
[self unlockWithLicenseURL:url];
210+
[self unlockWithLicenseURL:url resolve:resolve reject:reject];
226211
}
227212
else if (string != nil) {
228-
[self unlockWithLicenseString:string];
213+
[self unlockWithLicenseString:string resolve:resolve reject:reject];
229214
}
230215
else if ([json isKindOfClass:[NSDictionary class]]) {
231216
NSDictionary *dictionary = json;
232-
[self unlockWithLicenseObject:dictionary];
217+
[self unlockWithLicenseObject:dictionary resolve:resolve reject:reject];
233218
}
234219
else if (json) {
235220
RCTLogConvertError(json, @"a valid license format");

ios/RNImglyKitSubclass.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ typedef void (^IMGLYCompletionBlock)(void);
5050

5151
@property (class, strong, atomic, nullable) IMGLYConfigurationBlock configureWithBuilder;
5252

53-
@property (strong, atomic, nullable) NSError* licenseError;
5453
@property (strong, atomic, nullable) NSString* exportType;
5554
@property (strong, atomic, nullable) NSURL* exportFile;
5655
@property (atomic) BOOL serializationEnabled;
@@ -68,11 +67,11 @@ typedef void (^IMGLYCompletionBlock)(void);
6867
resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject;
6968

7069
- (void)dismiss:(nullable PESDKMediaEditViewController *)mediaEditViewController animated:(BOOL)animated completion:(nullable IMGLYCompletionBlock)completion;
71-
- (void)handleLicenseError:(nullable NSError *)error;
72-
- (void)unlockWithLicenseURL:(nonnull NSURL *)url;
73-
- (void)unlockWithLicenseString:(nonnull NSString *)string;
74-
- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary;
75-
- (void)unlockWithLicense:(nonnull id)json;
70+
- (void)handleLicenseError:(nullable NSError *)error resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject;
71+
- (void)unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject;
72+
- (void)unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject;
73+
- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject;
74+
- (void)unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject;
7675

7776
extern const struct RN_IMGLY_Constants
7877
{

ios/RNPhotoEditorSDK.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,36 +78,36 @@ - (void)present:(nullable PESDKPhoto *)photo withConfiguration:(nullable NSDicti
7878
} configuration:dictionary serialization:state resolve:resolve reject:reject];
7979
}
8080

81-
RCT_EXPORT_METHOD(unlockWithLicenseURL:(nonnull NSURL *)url)
81+
RCT_EXPORT_METHOD(unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject)
8282
{
8383
dispatch_async(dispatch_get_main_queue(), ^{
8484
NSError *error = nil;
8585
[PESDK unlockWithLicenseFromURL:url error:&error];
86-
[self handleLicenseError:error];
86+
[self handleLicenseError:error resolve:resolve reject:reject];
8787
});
8888
}
8989

90-
RCT_EXPORT_METHOD(unlockWithLicenseString:(nonnull NSString *)string)
90+
RCT_EXPORT_METHOD(unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject)
9191
{
9292
dispatch_async(dispatch_get_main_queue(), ^{
9393
NSError *error = nil;
9494
[PESDK unlockWithLicenseFromString:string error:&error];
95-
[self handleLicenseError:error];
95+
[self handleLicenseError:error resolve:resolve reject:reject];
9696
});
9797
}
9898

99-
RCT_EXPORT_METHOD(unlockWithLicenseObject:(nonnull NSDictionary *)dictionary)
99+
RCT_EXPORT_METHOD(unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject)
100100
{
101101
dispatch_async(dispatch_get_main_queue(), ^{
102102
NSError *error = nil;
103103
[PESDK unlockWithLicenseFromDictionary:dictionary error:&error];
104-
[self handleLicenseError:error];
104+
[self handleLicenseError:error resolve:resolve reject:reject];
105105
});
106106
}
107107

108-
RCT_EXPORT_METHOD(unlockWithLicense:(nonnull id)json)
108+
RCT_EXPORT_METHOD(unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject)
109109
{
110-
[super unlockWithLicense:json];
110+
[super unlockWithLicense:json resolve:resolve reject:reject];
111111
}
112112

113113
RCT_EXPORT_METHOD(present:(nullable NSURLRequest *)request

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-photoeditorsdk",
33
"title": "React Native module for PhotoEditor SDK",
4-
"version": "2.17.1",
4+
"version": "3.0.0",
55
"description": "A React Native module for PhotoEditor SDK. Integrate the photo editor into your own HTML5, iOS or Android app - in minutes!",
66
"main": "index.js",
77
"typings": "index.d.ts",
@@ -38,6 +38,6 @@
3838
"react-native": ">=0.60.0 <1.0.x"
3939
},
4040
"dependencies": {
41-
"react-native-imglysdk": "2.17.1"
41+
"react-native-imglysdk": "3.0.0"
4242
}
4343
}

0 commit comments

Comments
 (0)