@sodyo/react-native-sodyo-sdk 3.1.2

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,59 @@
1
+ #if __has_include(<React/RCTViewManager.h>)
2
+ #import <React/RCTViewManager.h>
3
+ #import <React/RCTConvert.h>
4
+ #else
5
+ #import "RCTConvert.h"
6
+ #import "RCTViewManager.h"
7
+ #endif
8
+
9
+ #if __has_include(<SodyoSDK/SodyoSDK.h>)
10
+ #import <SodyoSDK/SodyoSDK.h>
11
+ #else
12
+ #import "SodyoSDK.h"
13
+ #endif
14
+
15
+ #import <UIKit/UIKit.h>
16
+ #import "RNSodyoSdkView.m"
17
+
18
+ @interface RNSodyoSdkManager : RCTViewManager {
19
+ UIViewController *sodyoScanner;
20
+ }
21
+ @end
22
+
23
+ @implementation RNSodyoSdkManager
24
+
25
+ RCT_EXPORT_MODULE(RNSodyoSdkView)
26
+
27
+ RCT_CUSTOM_VIEW_PROPERTY(isEnabled, BOOL, UIView)
28
+ {
29
+ NSLog(@"RNSodyoSdkManager set isEnabled");
30
+
31
+ if (!self->sodyoScanner) {
32
+ return;
33
+ }
34
+
35
+ if ([RCTConvert BOOL:json]) {
36
+ [SodyoSDK startScanning:self->sodyoScanner];
37
+ return;
38
+ }
39
+
40
+ [SodyoSDK stopScanning:self->sodyoScanner];
41
+ }
42
+
43
+ - (UIView *)view
44
+ {
45
+ UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
46
+
47
+ self->sodyoScanner = [SodyoSDK initSodyoScanner];
48
+ [rootViewController addChildViewController:sodyoScanner];
49
+
50
+ RNSodyoSdkView *view = [[RNSodyoSdkView alloc] initWithView:sodyoScanner.view];
51
+
52
+ [SodyoSDK setPresentingViewController:rootViewController];
53
+ [sodyoScanner didMoveToParentViewController:rootViewController];
54
+
55
+ return view;
56
+ }
57
+
58
+ @end
59
+
@@ -0,0 +1,4 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ @interface RNSodyoSdkView : UIView
4
+ @end
@@ -0,0 +1,28 @@
1
+ #import "RNSodyoSdkView.h"
2
+
3
+ @implementation RNSodyoSdkView
4
+
5
+ - (instancetype)initWithView:(UIView*) view {
6
+ NSLog(@"RNSodyoSdkView init");
7
+ self = [super init];
8
+
9
+ if ( self ) {
10
+ [self setUp:view];
11
+ }
12
+
13
+ return self;
14
+ }
15
+
16
+ - (void)setUp:(UIView*) view {
17
+ NSLog(@"RNSodyoSdkView setup");
18
+ [self addSubview:view];
19
+ }
20
+
21
+ - (void) layoutSubviews {
22
+ [super layoutSubviews];
23
+ for(UIView* view in self.subviews) {
24
+ [view setFrame:self.bounds];
25
+ }
26
+ }
27
+
28
+ @end
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@sodyo/react-native-sodyo-sdk",
3
+ "version": "3.1.2",
4
+ "description": "RNSodyoSdk",
5
+ "main": "sodyosdk.js",
6
+ "typings": "./sodyosdk.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/sodyo-ltd/react-native-sodyo-sdk"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/sodyo-ltd/react-native-sodyo-sdk/issues"
13
+ },
14
+ "scripts": {
15
+ "test": "echo \"no test specified\""
16
+ },
17
+ "keywords": [
18
+ "react-native",
19
+ "sodyo"
20
+ ],
21
+ "author": "Sodyo",
22
+ "license": "MIT",
23
+ "homepage": "https://www.sodyo.com",
24
+ "peerDependencies": {
25
+ "react-native": "^0.41.2"
26
+ }
27
+ }
package/sodyosdk.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import * as React from 'react'
2
+
3
+ type TEnv = 'DEV' | 'QA' | 'PROD';
4
+
5
+ declare const _default: {
6
+ init (apiKey: string, successCallback?: () => void, errorCallback?: (msg: string) => void, env?: TEnv): void
7
+ onError (callback: (err: string) => void): () => void,
8
+ onCloseScanner (callback: () => void): () => void,
9
+ onCloseContent (callback: () => void): () => void,
10
+ start (successCallback?: (immediateData?: string) => void, errorCallback?: (msg: string) => void): void
11
+ close (): void
12
+ setUserInfo (userInfo: { [key: string]: string | number }): void
13
+ setScannerParams (scannerPreferences: { [key: string]: string }): void
14
+ addScannerParam (key: string, value: string): void
15
+ setDynamicProfileValue (key: string, value: string): void
16
+ setCustomAdLabel (label: string): void
17
+ setAppUserId (appUserId: string): void
18
+ removeAllListeners (eventType?: string): void
19
+ onMarkerContent (callback: (markerId: string, data: { [key: string]: any }) => void): () => void,
20
+ performMarker (markerId: string): void,
21
+ setSodyoLogoVisible (isVisible: boolean): void,
22
+ setEnv(env: TEnv): void,
23
+ }
24
+
25
+ interface IScannerProps {
26
+ isEnabled?: boolean
27
+ }
28
+
29
+ export declare class Scanner extends React.PureComponent<IScannerProps> {
30
+ }
31
+
32
+ export declare const SODYO_ENV: {
33
+ [key in TEnv]: TEnv
34
+ }
35
+
36
+ export default _default
package/sodyosdk.js ADDED
@@ -0,0 +1,199 @@
1
+ import React, { Component, Fragment } from 'react';
2
+ import {
3
+ View,
4
+ requireNativeComponent,
5
+ NativeModules,
6
+ NativeEventEmitter,
7
+ Platform,
8
+ StyleSheet,
9
+ } from 'react-native';
10
+
11
+ const { RNSodyoSdk } = NativeModules;
12
+
13
+ const eventEmitter = new NativeEventEmitter(RNSodyoSdk);
14
+
15
+ export default {
16
+ init: (apiKey, successCallback, errorCallback) => {
17
+ return RNSodyoSdk.init(apiKey, successCallback, errorCallback);
18
+ },
19
+
20
+ onError: (callback) => {
21
+ eventEmitter.removeAllListeners('EventSodyoError');
22
+
23
+ const subscription = eventEmitter.addListener('EventSodyoError', (e) => {
24
+ if (typeof callback === 'function') {
25
+ callback(e.error);
26
+ }
27
+ });
28
+
29
+ return () => {
30
+ return subscription.remove();
31
+ };
32
+ },
33
+
34
+ onCloseScanner: (callback) => {
35
+ if (Platform.OS === 'ios') {
36
+ return () => undefined;
37
+ }
38
+
39
+ eventEmitter.removeAllListeners('EventCloseSodyoScanner');
40
+
41
+ const subscription = eventEmitter.addListener('EventCloseSodyoScanner', () => {
42
+ if (typeof callback === 'function') {
43
+ callback();
44
+ }
45
+ });
46
+
47
+ return () => {
48
+ return subscription.remove();
49
+ };
50
+ },
51
+
52
+ onMarkerContent: (callback) => {
53
+ eventEmitter.removeAllListeners('EventMarkerContent');
54
+
55
+ const subscription = eventEmitter.addListener('EventMarkerContent', (e) => {
56
+ if (typeof callback === 'function') {
57
+ const data = typeof e.data === 'string'
58
+ ? JSON.parse(e.data)
59
+ : e.data || {};
60
+ callback(e.markerId, data);
61
+ }
62
+ });
63
+
64
+ return () => {
65
+ return subscription.remove();
66
+ };
67
+ },
68
+
69
+ onCloseContent: (callback) => {
70
+ if (Platform.OS !== 'ios') {
71
+ return () => undefined;
72
+ }
73
+
74
+ RNSodyoSdk.createCloseContentListener();
75
+ eventEmitter.removeAllListeners('EventCloseSodyoContent');
76
+
77
+ const subscription = eventEmitter.addListener('EventCloseSodyoContent', () => {
78
+ if (typeof callback === 'function') {
79
+ callback();
80
+ }
81
+ });
82
+
83
+ return () => {
84
+ return subscription.remove();
85
+ };
86
+ },
87
+
88
+ performMarker: (markerId) => {
89
+ return RNSodyoSdk.performMarker(markerId);
90
+ },
91
+
92
+ start: (successCallback, errorCallback) => {
93
+ eventEmitter.removeAllListeners('EventMarkerDetectSuccess');
94
+ eventEmitter.removeAllListeners('EventMarkerDetectError');
95
+
96
+ RNSodyoSdk.start();
97
+
98
+ eventEmitter.addListener('EventMarkerDetectSuccess', (e) => {
99
+ if (typeof successCallback === 'function') {
100
+ successCallback(e.data);
101
+ }
102
+ });
103
+
104
+ eventEmitter.addListener('EventMarkerDetectError', (e) => {
105
+ if (typeof errorCallback === 'function') {
106
+ errorCallback(e.error);
107
+ }
108
+ });
109
+ },
110
+
111
+ removeAllListeners: () => {
112
+ return eventEmitter.removeAllListeners();
113
+ },
114
+
115
+ close: () => {
116
+ eventEmitter.removeAllListeners('EventMarkerDetectSuccess');
117
+ eventEmitter.removeAllListeners('EventMarkerDetectError');
118
+
119
+ return RNSodyoSdk.close();
120
+ },
121
+
122
+ setUserInfo: (userInfo) => {
123
+ return RNSodyoSdk.setUserInfo(userInfo);
124
+ },
125
+
126
+ setScannerParams: (scannerPreferences) => {
127
+ return RNSodyoSdk.setScannerParams(scannerPreferences);
128
+ },
129
+
130
+ addScannerParam: (key, value) => {
131
+ return RNSodyoSdk.addScannerParam(key, value);
132
+ },
133
+
134
+ setDynamicProfileValue: (key, value) => {
135
+ return RNSodyoSdk.setDynamicProfileValue(key, value);
136
+ },
137
+
138
+ setCustomAdLabel: (label) => {
139
+ return RNSodyoSdk.setCustomAdLabel(label);
140
+ },
141
+
142
+ setAppUserId: (appUserId) => {
143
+ return RNSodyoSdk.setAppUserId(appUserId);
144
+ },
145
+
146
+ setSodyoLogoVisible: (isVisible) => {
147
+ return RNSodyoSdk.setSodyoLogoVisible(isVisible);
148
+ },
149
+
150
+ setEnv: (env) => {
151
+ return RNSodyoSdk.setEnv(env);
152
+ },
153
+ };
154
+
155
+ export class Scanner extends Component {
156
+ static defaultProps = {
157
+ isEnabled: true,
158
+ };
159
+
160
+ render () {
161
+ const { isEnabled, children } = this.props;
162
+ return (
163
+ <Fragment>
164
+ <RNSodyoSdkView
165
+ isEnabled={isEnabled}
166
+ style={{ height: '100%', width: '100%' }}
167
+ />
168
+
169
+ <View style={styles.container} pointerEvents="box-none">
170
+ {children}
171
+ </View>
172
+ </Fragment>
173
+ );
174
+ }
175
+ }
176
+
177
+ export const SODYO_ENV = {
178
+ DEV: 'DEV',
179
+ QA: 'QA',
180
+ PROD: 'PROD',
181
+ }
182
+
183
+ const RNSodyoSdkView = requireNativeComponent('RNSodyoSdkView', Scanner, {
184
+ nativeOnly: {},
185
+ });
186
+
187
+
188
+ const styles = StyleSheet.create({
189
+ container: {
190
+ position: 'absolute',
191
+ top: 0,
192
+ bottom: 0,
193
+ left: 0,
194
+ right: 0,
195
+ width: '100%',
196
+ height: '100%',
197
+ flex: 1,
198
+ },
199
+ })