anyline-ocr-react-native-module 55.8.1 → 56.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,197 @@
1
+
2
+ #import <React/RCTEventEmitter.h>
3
+ #import <React/RCTBridge.h>
4
+ #import "AnylineInfinityPlugin.h"
5
+ #import "NativeView/NativeViewRegistry.h"
6
+ #import "RCTUtils.h"
7
+
8
+ // Static instance to retain the ALWrapperSessionProvider reference.
9
+ static ALWrapperSessionProvider *_infinityWrapperSessionProvider;
10
+
11
+ static NSString * const kEventOnScanResults = @"INFINITY_ON_SCAN_RESULTS";
12
+ static NSString * const kEventOnUiElementClicked = @"INFINITY_ON_UI_ELEMENT_CLICKED";
13
+
14
+ @interface AnylineInfinityPlugin ()
15
+
16
+ @property (nonatomic, strong) RCTPromiseResolveBlock sdkInitializationResolve;
17
+ @property (nonatomic, strong) RCTPromiseRejectBlock sdkInitializationReject;
18
+
19
+ @property (nonatomic, strong) RCTPromiseResolveBlock scanResponseResolve;
20
+ @property (nonatomic, strong) RCTPromiseRejectBlock scanResponseReject;
21
+
22
+ @property (nonatomic, strong) RCTPromiseResolveBlock ucrReportResolve;
23
+ @property (nonatomic, strong) RCTPromiseRejectBlock ucrReportReject;
24
+
25
+ @property (nonatomic, strong) RCTPromiseResolveBlock exportCachedEventsResolve;
26
+ @property (nonatomic, strong) RCTPromiseRejectBlock exportCachedEventsReject;
27
+
28
+ @end
29
+
30
+ @implementation AnylineInfinityPlugin
31
+
32
+ - (instancetype)init {
33
+ self = [super initWithDisabledObservation];
34
+ if (self && !_infinityWrapperSessionProvider) {
35
+ _infinityWrapperSessionProvider = [[ALWrapperSessionProvider alloc] init];
36
+ }
37
+ return self;
38
+ }
39
+
40
+ RCT_EXPORT_MODULE();
41
+
42
+ - (NSArray<NSString *> *)supportedEvents {
43
+ return @[kEventOnScanResults, kEventOnUiElementClicked];
44
+ }
45
+
46
+ RCT_EXPORT_METHOD(getSDKVersion:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
47
+ resolve(AnylineSDK.versionNumber);
48
+ }
49
+
50
+ RCT_EXPORT_METHOD(setupWrapperSession:(NSString *)pluginVersion) {
51
+ ALWrapperConfig *wrapperConfig = [ALWrapperConfig reactNative:pluginVersion codename:ALWrapperCodenameInfinity];
52
+ [ALWrapperSessionProvider setupWrapperSessionWithWrapperInfo:wrapperConfig
53
+ wrapperSessionClient:self];
54
+ }
55
+
56
+ RCT_EXPORT_METHOD(requestSdkInitialization:(NSString *)request
57
+ resolver:(RCTPromiseResolveBlock)resolve
58
+ rejecter:(RCTPromiseRejectBlock)reject) {
59
+ self.sdkInitializationResolve = resolve;
60
+ self.sdkInitializationReject = reject;
61
+ [ALWrapperSessionProvider
62
+ requestSdkInitializationWithInitializationRequestParamsString:request];
63
+ }
64
+
65
+ RCT_EXPORT_METHOD(requestScanStart:(NSString *)request
66
+ resolver:(RCTPromiseResolveBlock)resolve
67
+ rejecter:(RCTPromiseRejectBlock)reject) {
68
+ self.scanResponseResolve = resolve;
69
+ self.scanResponseReject = reject;
70
+ [ALWrapperSessionProvider requestScanStartWithScanStartRequestParamsString:[self resolvedScanStartRequestJsonString:request]];
71
+ }
72
+
73
+ RCT_EXPORT_METHOD(requestScanSwitchWithScanStartRequestParams:(NSString *)request) {
74
+ [ALWrapperSessionProvider requestScanSwitchWithScanStartRequestParamsString:[self resolvedScanStartRequestJsonString:request]];
75
+ }
76
+
77
+ RCT_EXPORT_METHOD(requestScanSwitchWithScanViewConfigContentString:(NSString *)request) {
78
+ [ALWrapperSessionProvider requestScanSwitchWithScanViewConfigContentString:request];
79
+ }
80
+
81
+ RCT_EXPORT_METHOD(requestScanStop:(NSString * _Nullable)request) {
82
+ [ALWrapperSessionProvider requestScanStopWithScanStopRequestParamsString:request];
83
+ }
84
+
85
+ RCT_EXPORT_METHOD(requestUCRReport:(NSString *)request
86
+ resolver:(RCTPromiseResolveBlock)resolve
87
+ rejecter:(RCTPromiseRejectBlock)reject) {
88
+ self.ucrReportResolve = resolve;
89
+ self.ucrReportReject = reject;
90
+ [ALWrapperSessionProvider
91
+ requestUCRReportWithWrapperSessionUCRReportRequestString:request];
92
+ }
93
+
94
+ RCT_EXPORT_METHOD(requestExportCachedEvents:(RCTPromiseResolveBlock)resolve
95
+ rejecter:(RCTPromiseRejectBlock)reject) {
96
+ self.exportCachedEventsResolve = resolve;
97
+ self.exportCachedEventsReject = reject;
98
+ [ALWrapperSessionProvider requestExportCachedEvents];
99
+ }
100
+
101
+ -(NSString *)bundlePathFromScanViewConfigPath:(NSString * _Nullable)scanViewConfigPath {
102
+ // Guard against NSNull from JSON deserialization when the field is absent
103
+ if ([scanViewConfigPath isKindOfClass:[NSNull class]]) scanViewConfigPath = nil;
104
+ NSString *absoluteScanViewConfigPath = [[NSBundle mainBundle] bundlePath];
105
+ if (scanViewConfigPath) {
106
+ //append scanViewConfigPath
107
+ absoluteScanViewConfigPath = [absoluteScanViewConfigPath stringByAppendingPathComponent:scanViewConfigPath];
108
+ }
109
+ return absoluteScanViewConfigPath;
110
+ }
111
+
112
+ - (NSString *)resolvedScanStartRequestJsonString:(NSString *)requestJsonString {
113
+ if (!requestJsonString) return requestJsonString;
114
+ NSData *jsonData = [requestJsonString dataUsingEncoding:NSUTF8StringEncoding];
115
+ NSMutableDictionary *requestDict = [[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil] mutableCopy];
116
+ if (!requestDict) return requestJsonString;
117
+ NSString *scanViewConfigPath = requestDict[@"scanViewConfigPath"];
118
+ requestDict[@"scanViewConfigPath"] = [self bundlePathFromScanViewConfigPath:scanViewConfigPath];
119
+
120
+ NSData *fixedData = [NSJSONSerialization dataWithJSONObject:requestDict options:0 error:nil];
121
+ return fixedData ? [[NSString alloc] initWithData:fixedData encoding:NSUTF8StringEncoding] : requestJsonString;
122
+ }
123
+
124
+ #pragma mark - ALWrapperSessionClientDelegate
125
+
126
+ - (nullable UIViewController *)getTopViewController {
127
+ UIViewController *topViewController = RCTPresentedViewController();
128
+ if (!topViewController) {
129
+ for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
130
+ if ([scene isKindOfClass:[UIWindowScene class]] &&
131
+ scene.activationState == UISceneActivationStateForegroundActive) {
132
+ topViewController = ((UIWindowScene *)scene).windows.firstObject.rootViewController;
133
+ break;
134
+ }
135
+ }
136
+ }
137
+ return topViewController;
138
+ }
139
+
140
+ - (nullable UIView *)getContainerView {
141
+ return [[NativeViewRegistry shared] getLastOrNull];
142
+ }
143
+
144
+ - (void)onSdkInitializationResponse:(nonnull ALWrapperSessionSDKInitializationResponse *)initializationResponse {
145
+ if (self.sdkInitializationResolve) {
146
+ NSDictionary *dict = [initializationResponse toJSONDictionary];
147
+ self.sdkInitializationResolve([dict asJSONString]);
148
+ self.sdkInitializationResolve = nil;
149
+ self.sdkInitializationReject = nil;
150
+ }
151
+ }
152
+
153
+ - (void)onScanResults:(nonnull ALWrapperSessionScanResultsResponse *)scanResultsResponse {
154
+ NSArray<ALExportedScanResult *> *results = (NSArray<ALExportedScanResult *> *)scanResultsResponse.exportedScanResults;
155
+ NSMutableArray<NSDictionary *> *resultDicts = [NSMutableArray array];
156
+ for (ALExportedScanResult *result in results) {
157
+ [resultDicts addObject:[result toJSONDictionary]];
158
+ }
159
+ NSMutableDictionary *dict = [[scanResultsResponse toJSONDictionary] mutableCopy];
160
+ dict[@"exportedScanResults"] = resultDicts;
161
+ [self sendEventWithName:kEventOnScanResults body:[dict asJSONString]];
162
+ }
163
+
164
+ - (void)onScanResponse:(nonnull ALWrapperSessionScanResponse *)scanResponse {
165
+ if (self.scanResponseResolve) {
166
+ NSDictionary *dict = [scanResponse toJSONDictionary];
167
+ self.scanResponseResolve([dict asJSONString]);
168
+ self.scanResponseResolve = nil;
169
+ self.scanResponseReject = nil;
170
+ }
171
+ }
172
+
173
+ - (void)onUIElementClicked:(nonnull ALWrapperSessionScanResultConfig *)scanResultConfig
174
+ uiFeedbackElementConfig:(nonnull ALUIFeedbackElementConfig *)uiFeedbackElementConfig {
175
+ NSDictionary *dict = [uiFeedbackElementConfig performSelector:@selector(JSONDictionary)];
176
+ [self sendEventWithName:kEventOnUiElementClicked body:[dict asJSONString]];
177
+ }
178
+
179
+ - (void)onUCRReportResponse:(nonnull ALWrapperSessionUCRReportResponse *)ucrReportResponse {
180
+ if (self.ucrReportResolve) {
181
+ NSDictionary *dict = [ucrReportResponse toJSONDictionary];
182
+ self.ucrReportResolve([dict asJSONString]);
183
+ self.ucrReportResolve = nil;
184
+ self.ucrReportReject = nil;
185
+ }
186
+ }
187
+
188
+ - (void)onExportCachedEventsResponse:(nonnull ALWrapperSessionExportCachedEventsResponse *)exportCachedEventsResponse {
189
+ if (self.exportCachedEventsResolve) {
190
+ NSDictionary *dict = [exportCachedEventsResponse toJSONDictionary];
191
+ self.exportCachedEventsResolve([dict asJSONString]);
192
+ self.exportCachedEventsResolve = nil;
193
+ self.exportCachedEventsReject = nil;
194
+ }
195
+ }
196
+
197
+ @end
@@ -4,6 +4,7 @@
4
4
  #import <React/RCTEventEmitter.h>
5
5
  #import <React/RCTBridgeModule.h>
6
6
 
7
+ __attribute__((deprecated("Use AnylineInfinityPlugin instead.")))
7
8
  @interface AnylineSDKPlugin : RCTEventEmitter <RCTBridgeModule, ALWrapperSessionClientDelegate>
8
9
 
9
10
  @end
@@ -2,6 +2,7 @@
2
2
  #import <React/RCTEventEmitter.h>
3
3
  #import <React/RCTBridge.h>
4
4
  #import "AnylineSDKPlugin.h"
5
+ #import "NativeView/NativeViewRegistry.h"
5
6
  #import "RCTUtils.h"
6
7
 
7
8
  // Static instance to retain the ALWrapperSessionProvider instance
@@ -116,6 +117,18 @@ RCT_EXPORT_METHOD(licenseKeyExpiryDate:(RCTPromiseResolveBlock)resolve rejecter:
116
117
  return;
117
118
  }
118
119
 
120
+ RCT_EXPORT_METHOD(setDefaultScanStartPlatformOptions:(nullable NSString *)scanStartPlatformOptionsString
121
+ resolver:(RCTPromiseResolveBlock)resolve
122
+ rejecter:(RCTPromiseRejectBlock)reject) {
123
+ @try {
124
+ [ALWrapperSessionProvider setDefaultScanStartPlatformOptionsWithString:scanStartPlatformOptionsString];
125
+ resolve(@"");
126
+ }
127
+ @catch (NSException *exception) {
128
+ reject(@"ANYLINE_ERROR", exception.reason, nil);
129
+ }
130
+ }
131
+
119
132
  // Deprecated
120
133
  RCT_EXPORT_METHOD(setupScanViewWithConfigJson:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
121
134
  [self setupWithInitializationParameters:nil config:config scanMode:scanMode onResultCallback:onResult onErrorCallback:onError];
@@ -181,6 +194,10 @@ RCT_EXPORT_METHOD(setupPromiseWithInitializationParametersAndScanCallbackConfig:
181
194
  scanCallbackConfigString:scanCallbackConfigString];
182
195
  }
183
196
 
197
+ RCT_EXPORT_METHOD(trySwitchScan:(NSString *)scanViewConfigContent) {
198
+ [ALWrapperSessionProvider requestScanSwitchWithScanViewConfigContentString:scanViewConfigContent];
199
+ }
200
+
184
201
  RCT_EXPORT_METHOD(tryStopScan:(NSString * _Nullable)scanStopRequestParams) {
185
202
  [ALWrapperSessionProvider requestScanStopWithScanStopRequestParamsString:scanStopRequestParams];
186
203
  }
@@ -234,8 +251,7 @@ RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(R
234
251
  }
235
252
 
236
253
  - (void)setupWrapperSessionWithPluginVersion:(NSString *)pluginVersion {
237
- // Setup wrapper session with this view controller as delegate
238
- ALWrapperConfig *wrapperConfig = [ALWrapperConfig reactNative:pluginVersion];
254
+ ALWrapperConfig *wrapperConfig = [ALWrapperConfig reactNative:pluginVersion codename:ALWrapperCodenameLegacy];
239
255
  [ALWrapperSessionProvider setupWrapperSessionWithWrapperInfo:wrapperConfig
240
256
  wrapperSessionClient:self];
241
257
  }
@@ -336,6 +352,10 @@ RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(R
336
352
  return nil;
337
353
  }
338
354
 
355
+ - (nullable UIView *)getContainerView {
356
+ return [[NativeViewRegistry shared] getLastOrNull];
357
+ }
358
+
339
359
  - (void)onSdkInitializationResponse:(nonnull ALWrapperSessionSDKInitializationResponse *)initializationResponse {
340
360
  if ([initializationResponse.initialized isEqualToNumber:@YES]) {
341
361
  self.wrapperSessionSdkInitializationResponsePromiseResolve(@"success");
@@ -0,0 +1,4 @@
1
+ #import <React/RCTViewManager.h>
2
+
3
+ @interface AnylineNativeViewManager : RCTViewManager
4
+ @end
@@ -0,0 +1,27 @@
1
+ #import "AnylineNativeViewManager.h"
2
+ #import "NativeViewRegistry.h"
3
+ #import <UIKit/UIKit.h>
4
+
5
+ @implementation AnylineNativeViewManager
6
+
7
+ RCT_EXPORT_MODULE()
8
+
9
+ - (UIView *)view {
10
+ UIView *containerView = [[UIView alloc] init];
11
+
12
+ NSString *containerId = [NSString stringWithFormat:@"%d", 0];
13
+ [[NativeViewRegistry shared] registerView:containerView withId:containerId];
14
+
15
+ UIViewController *vc = [[UIViewController alloc] init];
16
+ vc.view.frame = containerView.bounds;
17
+ vc.view.backgroundColor = [UIColor lightGrayColor];
18
+
19
+ UIViewController *rootVC = UIApplication.sharedApplication.delegate.window.rootViewController;
20
+ [rootVC addChildViewController:vc];
21
+ [containerView addSubview:vc.view];
22
+ [vc didMoveToParentViewController:rootVC];
23
+
24
+ return containerView;
25
+ }
26
+
27
+ @end
@@ -0,0 +1,11 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <UIKit/UIKit.h>
3
+
4
+ @interface NativeViewRegistry : NSObject
5
+
6
+ + (instancetype)shared;
7
+ - (void)registerView:(UIView *)view withId:(NSString *)viewId;
8
+ - (UIView *)getViewById:(NSString *)viewId;
9
+ - (UIView *)getLastOrNull;
10
+
11
+ @end
@@ -0,0 +1,37 @@
1
+ #import "NativeViewRegistry.h"
2
+
3
+ @interface NativeViewRegistry ()
4
+ @property(nonatomic, strong) NSMapTable<NSString *, UIView *> *views;
5
+ @end
6
+
7
+ @implementation NativeViewRegistry
8
+
9
+ + (instancetype)shared {
10
+ static NativeViewRegistry *instance;
11
+ static dispatch_once_t onceToken;
12
+ dispatch_once(&onceToken, ^{
13
+ instance = [[NativeViewRegistry alloc] init];
14
+ instance.views = [NSMapTable strongToWeakObjectsMapTable];
15
+ });
16
+ return instance;
17
+ }
18
+
19
+ - (void)registerView:(UIView *)view withId:(NSString *)viewId {
20
+ [self.views setObject:view forKey:viewId];
21
+ }
22
+
23
+ - (UIView *)getViewById:(NSString *)viewId {
24
+ return [self.views objectForKey:viewId];
25
+ }
26
+
27
+ - (UIView *)getLastOrNull {
28
+ NSArray *allKeys = self.views.keyEnumerator.allObjects;
29
+ if (allKeys.count > 0) {
30
+ NSString *lastKey = [allKeys lastObject];
31
+ return [self.views objectForKey:lastKey];
32
+ } else {
33
+ return nil;
34
+ }
35
+ }
36
+
37
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anyline-ocr-react-native-module",
3
- "version": "55.8.1",
3
+ "version": "56.0.0",
4
4
  "description": "A Plugin for connecting Anyline with React-Native",
5
5
  "keywords": [
6
6
  "reactnative",