anyline-ocr-react-native-module 55.9.0 → 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.
- package/AnylineInfinityPlugin.ts +129 -0
- package/AnylineReact.podspec +1 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/anyline/reactnative/AnylineInfinityPlugin.java +195 -0
- package/android/src/main/java/com/anyline/reactnative/AnylinePackage.java +1 -0
- package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +5 -1
- package/android/src/main/java/com/anyline/reactnative/ResultReporter.java +1 -0
- package/index.js +3 -0
- package/ios/AnylineInfinityPlugin.h +9 -0
- package/ios/AnylineInfinityPlugin.m +197 -0
- package/ios/AnylineSDKPlugin.h +1 -0
- package/ios/AnylineSDKPlugin.m +1 -2
- package/package.json +1 -1
- package/types/sdk_config.ts +1750 -0
- package/types/wrapper_session_parameters.ts +1757 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { NativeModules, NativeEventEmitter, EmitterSubscription } from 'react-native';
|
|
2
|
+
import { version as pluginVersion } from './package.json';
|
|
3
|
+
import {
|
|
4
|
+
WrapperSessionSdkInitializationRequest,
|
|
5
|
+
WrapperSessionSdkInitializationResponse,
|
|
6
|
+
WrapperSessionScanStartRequest,
|
|
7
|
+
WrapperSessionScanResponse,
|
|
8
|
+
WrapperSessionScanResultsResponse,
|
|
9
|
+
WrapperSessionScanStopRequest,
|
|
10
|
+
WrapperSessionUcrReportRequest,
|
|
11
|
+
WrapperSessionUcrReportResponse,
|
|
12
|
+
WrapperSessionExportCachedEventsResponse,
|
|
13
|
+
} from './types/wrapper_session_parameters';
|
|
14
|
+
import { UiFeedbackElementConfig } from './types/sdk_config';
|
|
15
|
+
|
|
16
|
+
export * from './types/wrapper_session_parameters';
|
|
17
|
+
export * from './types/sdk_config';
|
|
18
|
+
|
|
19
|
+
const MODULE_NAME = 'AnylineInfinityPlugin';
|
|
20
|
+
const EVENT_ON_SCAN_RESULTS = 'INFINITY_ON_SCAN_RESULTS';
|
|
21
|
+
const EVENT_ON_UI_ELEMENT_CLICKED = 'INFINITY_ON_UI_ELEMENT_CLICKED';
|
|
22
|
+
|
|
23
|
+
const nativeModule = NativeModules[MODULE_NAME];
|
|
24
|
+
const emitter = new NativeEventEmitter(nativeModule);
|
|
25
|
+
|
|
26
|
+
let _sessionReady = false;
|
|
27
|
+
|
|
28
|
+
function _setupWrapperSessionOnce(): void {
|
|
29
|
+
if (_sessionReady) return;
|
|
30
|
+
_sessionReady = true;
|
|
31
|
+
nativeModule.setupWrapperSession(pluginVersion);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// Entrypoint for the Anyline Infinity scanning API.
|
|
35
|
+
///
|
|
36
|
+
/// Exposes a typed, schema-driven interface that mirrors WrapperSessionProvider
|
|
37
|
+
/// directly. JSON serialization/deserialization is handled in this TypeScript
|
|
38
|
+
/// layer; the native bridge only passes raw JSON strings.
|
|
39
|
+
export class AnylineInfinityPlugin {
|
|
40
|
+
/// Returns the plugin version string.
|
|
41
|
+
getPluginVersion(): string {
|
|
42
|
+
_setupWrapperSessionOnce();
|
|
43
|
+
return pluginVersion;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Returns the native SDK version string.
|
|
47
|
+
getSDKVersion(): Promise<string> {
|
|
48
|
+
_setupWrapperSessionOnce();
|
|
49
|
+
return nativeModule.getSDKVersion();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Initializes the Anyline SDK with the supplied request parameters.
|
|
53
|
+
requestSdkInitialization(
|
|
54
|
+
request: WrapperSessionSdkInitializationRequest
|
|
55
|
+
): Promise<WrapperSessionSdkInitializationResponse> {
|
|
56
|
+
_setupWrapperSessionOnce();
|
|
57
|
+
return nativeModule
|
|
58
|
+
.requestSdkInitialization(JSON.stringify(request))
|
|
59
|
+
.then((json: string) => JSON.parse(json) as WrapperSessionSdkInitializationResponse);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// Starts a scanning session.
|
|
63
|
+
///
|
|
64
|
+
/// Resolves with the lifecycle response when the session ends
|
|
65
|
+
/// (success / failure / abort). Intermediate scan results and UI element
|
|
66
|
+
/// click events arrive via onScanResults and onUIElementClicked.
|
|
67
|
+
requestScanStart(
|
|
68
|
+
request: WrapperSessionScanStartRequest
|
|
69
|
+
): Promise<WrapperSessionScanResponse> {
|
|
70
|
+
return nativeModule
|
|
71
|
+
.requestScanStart(JSON.stringify(request))
|
|
72
|
+
.then((json: string) => JSON.parse(json) as WrapperSessionScanResponse);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Switches to a new scan mode using the provided scan-start request.
|
|
76
|
+
requestScanSwitchWithScanStartRequestParams(
|
|
77
|
+
request: WrapperSessionScanStartRequest
|
|
78
|
+
): void {
|
|
79
|
+
nativeModule.requestScanSwitchWithScanStartRequestParams(JSON.stringify(request));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Switches to a new scan mode using a raw ScanViewConfig JSON string.
|
|
83
|
+
requestScanSwitchWithScanViewConfigContentString(
|
|
84
|
+
scanViewConfigContentString: string
|
|
85
|
+
): void {
|
|
86
|
+
nativeModule.requestScanSwitchWithScanViewConfigContentString(
|
|
87
|
+
scanViewConfigContentString
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// Stops the active scanning session.
|
|
92
|
+
requestScanStop(request?: WrapperSessionScanStopRequest): void {
|
|
93
|
+
nativeModule.requestScanStop(request ? JSON.stringify(request) : null);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/// Submits a User Corrected Result (UCR) report.
|
|
97
|
+
requestUCRReport(
|
|
98
|
+
request: WrapperSessionUcrReportRequest
|
|
99
|
+
): Promise<WrapperSessionUcrReportResponse> {
|
|
100
|
+
return nativeModule
|
|
101
|
+
.requestUCRReport(JSON.stringify(request))
|
|
102
|
+
.then((json: string) => JSON.parse(json) as WrapperSessionUcrReportResponse);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/// Exports all cached scan events as a ZIP archive.
|
|
106
|
+
requestExportCachedEvents(): Promise<WrapperSessionExportCachedEventsResponse> {
|
|
107
|
+
return nativeModule
|
|
108
|
+
.requestExportCachedEvents()
|
|
109
|
+
.then((json: string) => JSON.parse(json) as WrapperSessionExportCachedEventsResponse);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// Subscribes to scan results emitted during the active scan session (0..N).
|
|
113
|
+
onScanResults(
|
|
114
|
+
callback: (scanResults: WrapperSessionScanResultsResponse) => void
|
|
115
|
+
): EmitterSubscription {
|
|
116
|
+
return emitter.addListener(EVENT_ON_SCAN_RESULTS, (json: string) => {
|
|
117
|
+
callback(JSON.parse(json) as WrapperSessionScanResultsResponse);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// Subscribes to UI element click events during the active scan session (0..N).
|
|
122
|
+
onUIElementClicked(
|
|
123
|
+
callback: (uiElementClicked: UiFeedbackElementConfig) => void
|
|
124
|
+
): EmitterSubscription {
|
|
125
|
+
return emitter.addListener(EVENT_ON_UI_ELEMENT_CLICKED, (json: string) => {
|
|
126
|
+
callback(JSON.parse(json) as UiFeedbackElementConfig);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
package/AnylineReact.podspec
CHANGED
|
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
|
|
|
18
18
|
s.source = { :git => "https://github.com/Anyline/anyline-ocr-react-native-module.git", :tag => "#{s.version}" }
|
|
19
19
|
|
|
20
20
|
s.source_files = 'ios/**/*.{h,m,swift}'
|
|
21
|
-
s.dependency "Anyline", "
|
|
21
|
+
s.dependency "Anyline", "56.0.0"
|
|
22
22
|
s.dependency "React"
|
|
23
23
|
|
|
24
24
|
end
|
package/android/build.gradle
CHANGED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
package com.anyline.reactnative;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.view.ViewGroup;
|
|
5
|
+
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
import androidx.annotation.Nullable;
|
|
8
|
+
|
|
9
|
+
import com.anyline.reactnative.nativeview.NativeViewRegistry;
|
|
10
|
+
|
|
11
|
+
import com.facebook.react.bridge.Promise;
|
|
12
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
13
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
14
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
15
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
16
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
17
|
+
|
|
18
|
+
import org.jetbrains.annotations.NotNull;
|
|
19
|
+
|
|
20
|
+
import io.anyline.plugin.config.UIFeedbackElementConfig;
|
|
21
|
+
import io.anyline.wrapper.config.WrapperSessionExportCachedEventsResponse;
|
|
22
|
+
import io.anyline.wrapper.config.WrapperSessionScanResponse;
|
|
23
|
+
import io.anyline.wrapper.config.WrapperSessionScanResultConfig;
|
|
24
|
+
import io.anyline.wrapper.config.WrapperSessionScanResultsResponse;
|
|
25
|
+
import io.anyline.wrapper.config.WrapperSessionSdkInitializationResponse;
|
|
26
|
+
import io.anyline.wrapper.config.WrapperSessionUCRReportResponse;
|
|
27
|
+
import io.anyline2.WrapperInfo;
|
|
28
|
+
import io.anyline2.sdk.extension.UIFeedbackElementConfigExtensionKt;
|
|
29
|
+
import io.anyline2.wrapper.WrapperSessionClientInterface;
|
|
30
|
+
import io.anyline2.wrapper.WrapperSessionProvider;
|
|
31
|
+
import io.anyline2.wrapper.extensions.WrapperSessionExportCachedEventsResponseExtensionKt;
|
|
32
|
+
import io.anyline2.wrapper.extensions.WrapperSessionScanResponseExtensionKt;
|
|
33
|
+
import io.anyline2.wrapper.extensions.WrapperSessionScanResultsResponseExtensionKt;
|
|
34
|
+
import io.anyline2.wrapper.extensions.WrapperSessionSdkInitializationResponseExtensionKt;
|
|
35
|
+
import io.anyline2.wrapper.extensions.WrapperSessionUCRReportResponseExtensionKt;
|
|
36
|
+
|
|
37
|
+
class AnylineInfinityPlugin extends ReactContextBaseJavaModule
|
|
38
|
+
implements WrapperSessionClientInterface {
|
|
39
|
+
|
|
40
|
+
// Retain the WrapperSessionProvider instance to prevent GC-related crashes.
|
|
41
|
+
protected static final WrapperSessionProvider wrapperSessionProvider = WrapperSessionProvider.INSTANCE;
|
|
42
|
+
|
|
43
|
+
static final String REACT_CLASS = "AnylineInfinityPlugin";
|
|
44
|
+
private static final String EVENT_ON_SCAN_RESULTS = "INFINITY_ON_SCAN_RESULTS";
|
|
45
|
+
private static final String EVENT_ON_UI_ELEMENT_CLICKED = "INFINITY_ON_UI_ELEMENT_CLICKED";
|
|
46
|
+
|
|
47
|
+
private final ReactApplicationContext reactContext;
|
|
48
|
+
|
|
49
|
+
private Promise sdkInitializationPromise = null;
|
|
50
|
+
private Promise scanResponsePromise = null;
|
|
51
|
+
private Promise ucrReportPromise = null;
|
|
52
|
+
private Promise exportCachedEventsPromise = null;
|
|
53
|
+
|
|
54
|
+
AnylineInfinityPlugin(ReactApplicationContext context) {
|
|
55
|
+
super(context);
|
|
56
|
+
this.reactContext = context;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Override
|
|
60
|
+
public String getName() {
|
|
61
|
+
return REACT_CLASS;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@ReactMethod
|
|
65
|
+
public void getSDKVersion(final Promise promise) {
|
|
66
|
+
promise.resolve(at.nineyards.anyline.BuildConfig.VERSION_NAME);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@ReactMethod
|
|
70
|
+
protected void setupWrapperSession(final String pluginVersion) {
|
|
71
|
+
WrapperInfo wrapperInfo = new WrapperInfo(
|
|
72
|
+
WrapperInfo.WrapperType.ReactNative,
|
|
73
|
+
pluginVersion,
|
|
74
|
+
WrapperInfo.WrapperCodename.Infinity);
|
|
75
|
+
WrapperSessionProvider.setupWrapperSession(wrapperInfo, this);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@ReactMethod
|
|
79
|
+
public void requestSdkInitialization(String request, Promise promise) {
|
|
80
|
+
sdkInitializationPromise = promise;
|
|
81
|
+
WrapperSessionProvider.requestSdkInitialization(request);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@ReactMethod
|
|
85
|
+
public void requestScanStart(String request, Promise promise) {
|
|
86
|
+
scanResponsePromise = promise;
|
|
87
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
88
|
+
try {
|
|
89
|
+
WrapperSessionProvider.requestScanStart(request);
|
|
90
|
+
} catch (Exception e) {
|
|
91
|
+
promise.reject(e);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@ReactMethod
|
|
97
|
+
public void requestScanSwitchWithScanStartRequestParams(String request) {
|
|
98
|
+
WrapperSessionProvider.requestScanSwitchWithScanStartRequestParams(request);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@ReactMethod
|
|
102
|
+
public void requestScanSwitchWithScanViewConfigContentString(String request) {
|
|
103
|
+
WrapperSessionProvider.requestScanSwitchWithScanViewConfigContentString(request);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@ReactMethod
|
|
107
|
+
public void requestScanStop(@Nullable String request) {
|
|
108
|
+
WrapperSessionProvider.requestScanStop(request);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@ReactMethod
|
|
112
|
+
public void requestUCRReport(String request, Promise promise) {
|
|
113
|
+
ucrReportPromise = promise;
|
|
114
|
+
WrapperSessionProvider.requestUCRReport(request);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@ReactMethod
|
|
118
|
+
public void requestExportCachedEvents(Promise promise) {
|
|
119
|
+
exportCachedEventsPromise = promise;
|
|
120
|
+
WrapperSessionProvider.requestExportCachedEvents();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private void sendEvent(String eventName, String params) {
|
|
124
|
+
reactContext
|
|
125
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
126
|
+
.emit(eventName, params);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Override
|
|
130
|
+
public @NotNull Context getContext() {
|
|
131
|
+
return reactContext;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Override
|
|
135
|
+
public @Nullable ViewGroup getContainerView() {
|
|
136
|
+
return (ViewGroup) NativeViewRegistry.getLastOrNull();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@Override
|
|
140
|
+
public void onSdkInitializationResponse(
|
|
141
|
+
@NotNull WrapperSessionSdkInitializationResponse initializationResponse) {
|
|
142
|
+
if (sdkInitializationPromise != null) {
|
|
143
|
+
sdkInitializationPromise.resolve(
|
|
144
|
+
WrapperSessionSdkInitializationResponseExtensionKt
|
|
145
|
+
.toJsonObject(initializationResponse).toString());
|
|
146
|
+
sdkInitializationPromise = null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@Override
|
|
151
|
+
public void onScanResults(@NotNull WrapperSessionScanResultsResponse scanResultsResponse) {
|
|
152
|
+
sendEvent(EVENT_ON_SCAN_RESULTS,
|
|
153
|
+
WrapperSessionScanResultsResponseExtensionKt
|
|
154
|
+
.toJsonObject(scanResultsResponse).toString());
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@Override
|
|
158
|
+
public void onScanResponse(@NotNull WrapperSessionScanResponse scanResponse) {
|
|
159
|
+
if (scanResponsePromise != null) {
|
|
160
|
+
scanResponsePromise.resolve(
|
|
161
|
+
WrapperSessionScanResponseExtensionKt
|
|
162
|
+
.toJsonObject(scanResponse).toString());
|
|
163
|
+
scanResponsePromise = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@Override
|
|
168
|
+
public void onUIElementClicked(
|
|
169
|
+
@NonNull WrapperSessionScanResultConfig scanResultConfig,
|
|
170
|
+
@NonNull UIFeedbackElementConfig uiFeedbackElementConfig) {
|
|
171
|
+
sendEvent(EVENT_ON_UI_ELEMENT_CLICKED,
|
|
172
|
+
UIFeedbackElementConfigExtensionKt.toJsonObject(uiFeedbackElementConfig).toString());
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@Override
|
|
176
|
+
public void onUCRReportResponse(@NotNull WrapperSessionUCRReportResponse ucrReportResponse) {
|
|
177
|
+
if (ucrReportPromise != null) {
|
|
178
|
+
ucrReportPromise.resolve(
|
|
179
|
+
WrapperSessionUCRReportResponseExtensionKt
|
|
180
|
+
.toJsonObject(ucrReportResponse).toString());
|
|
181
|
+
ucrReportPromise = null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@Override
|
|
186
|
+
public void onExportCachedEventsResponse(
|
|
187
|
+
@NotNull WrapperSessionExportCachedEventsResponse exportCachedEventsResponse) {
|
|
188
|
+
if (exportCachedEventsPromise != null) {
|
|
189
|
+
exportCachedEventsPromise.resolve(
|
|
190
|
+
WrapperSessionExportCachedEventsResponseExtensionKt
|
|
191
|
+
.toJsonObject(exportCachedEventsResponse).toString());
|
|
192
|
+
exportCachedEventsPromise = null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -35,6 +35,7 @@ public class AnylinePackage implements ReactPackage {
|
|
|
35
35
|
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
36
36
|
List<NativeModule> modules = new ArrayList<>();
|
|
37
37
|
modules.add(new AnylineSDKPlugin(reactContext));
|
|
38
|
+
modules.add(new AnylineInfinityPlugin(reactContext));
|
|
38
39
|
return modules;
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -50,6 +50,10 @@ import io.anyline2.wrapper.extensions.WrapperSessionSdkInitializationResponseExt
|
|
|
50
50
|
import io.anyline2.wrapper.extensions.WrapperSessionUCRReportRequestExtensionKt;
|
|
51
51
|
import io.anyline2.wrapper.legacy.LegacyPluginHelper;
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use {@link AnylineInfinityPlugin} instead.
|
|
55
|
+
*/
|
|
56
|
+
@Deprecated
|
|
53
57
|
class AnylineSDKPlugin extends ReactContextBaseJavaModule
|
|
54
58
|
implements WrapperSessionClientInterface, ResultReporter.OnResultListener {
|
|
55
59
|
|
|
@@ -102,7 +106,7 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule
|
|
|
102
106
|
|
|
103
107
|
@ReactMethod
|
|
104
108
|
protected void setupWrapperSession(final String pluginVersion) {
|
|
105
|
-
WrapperInfo wrapperInfo = new WrapperInfo(WrapperInfo.WrapperType.ReactNative, pluginVersion);
|
|
109
|
+
WrapperInfo wrapperInfo = new WrapperInfo(WrapperInfo.WrapperType.ReactNative, pluginVersion, WrapperInfo.WrapperCodename.Legacy);
|
|
106
110
|
WrapperSessionProvider.setupWrapperSession(wrapperInfo,this);
|
|
107
111
|
}
|
|
108
112
|
|
package/index.js
CHANGED
|
@@ -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
|
package/ios/AnylineSDKPlugin.h
CHANGED
package/ios/AnylineSDKPlugin.m
CHANGED
|
@@ -251,8 +251,7 @@ RCT_EXPORT_METHOD(exportCachedEvents:(RCTPromiseResolveBlock)resolve rejecter:(R
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
- (void)setupWrapperSessionWithPluginVersion:(NSString *)pluginVersion {
|
|
254
|
-
|
|
255
|
-
ALWrapperConfig *wrapperConfig = [ALWrapperConfig reactNative:pluginVersion];
|
|
254
|
+
ALWrapperConfig *wrapperConfig = [ALWrapperConfig reactNative:pluginVersion codename:ALWrapperCodenameLegacy];
|
|
256
255
|
[ALWrapperSessionProvider setupWrapperSessionWithWrapperInfo:wrapperConfig
|
|
257
256
|
wrapperSessionClient:self];
|
|
258
257
|
}
|