@norcy/react-native-toolkit 0.3.9 → 0.3.11
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/android/build.gradle +3 -0
- package/android/root.gradle +1 -0
- package/android/src/main/java/com/norcy/reactnativetoolkit/HuaweiLoginModule.java +130 -0
- package/android/src/main/java/com/norcy/reactnativetoolkit/ReactNativeToolkitPackage.kt +2 -2
- package/lib/commonjs/HuaweiLoginUtil.js +8 -2
- package/lib/commonjs/HuaweiLoginUtil.js.map +1 -1
- package/lib/module/HuaweiLoginUtil.js +8 -2
- package/lib/module/HuaweiLoginUtil.js.map +1 -1
- package/lib/typescript/HuaweiLoginUtil.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/HuaweiLoginUtil.ts +6 -2
package/android/build.gradle
CHANGED
|
@@ -35,6 +35,7 @@ android {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
repositories {
|
|
38
|
+
maven { url 'https://developer.huawei.com/repo/' }
|
|
38
39
|
mavenCentral()
|
|
39
40
|
google()
|
|
40
41
|
}
|
|
@@ -48,4 +49,6 @@ dependencies {
|
|
|
48
49
|
// 友盟统计
|
|
49
50
|
implementation 'com.umeng.umsdk:common:9.6.3'
|
|
50
51
|
implementation 'com.umeng.umsdk:asms:1.8.0'
|
|
52
|
+
|
|
53
|
+
implementation 'com.huawei.hms:hwid:6.11.0.300'
|
|
51
54
|
}
|
package/android/root.gradle
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
package com.norcy.reactnativetoolkit;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.ActivityEventListener;
|
|
9
|
+
import com.facebook.react.bridge.Arguments;
|
|
10
|
+
import com.facebook.react.bridge.Promise;
|
|
11
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
12
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
13
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
14
|
+
import com.facebook.react.bridge.WritableMap;
|
|
15
|
+
import com.huawei.hmf.tasks.Task;
|
|
16
|
+
import com.huawei.hms.common.ApiException;
|
|
17
|
+
import com.huawei.hms.support.account.AccountAuthManager;
|
|
18
|
+
import com.huawei.hms.support.account.request.AccountAuthParams;
|
|
19
|
+
import com.huawei.hms.support.account.request.AccountAuthParamsHelper;
|
|
20
|
+
import com.huawei.hms.support.account.result.AuthAccount;
|
|
21
|
+
import com.huawei.hms.support.account.service.AccountAuthService;
|
|
22
|
+
|
|
23
|
+
public class HuaweiLoginModule extends ReactContextBaseJavaModule implements ActivityEventListener {
|
|
24
|
+
|
|
25
|
+
private static final String NAME = "HuaweiLoginModule";
|
|
26
|
+
private static final int REQUEST_SIGN_IN = 0x8AC1;
|
|
27
|
+
|
|
28
|
+
private Promise pendingPromise;
|
|
29
|
+
|
|
30
|
+
public HuaweiLoginModule(ReactApplicationContext reactContext) {
|
|
31
|
+
super(reactContext);
|
|
32
|
+
reactContext.addActivityEventListener(this);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@NonNull
|
|
36
|
+
@Override
|
|
37
|
+
public String getName() {
|
|
38
|
+
return NAME;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@ReactMethod
|
|
42
|
+
public void signIn(Promise promise) {
|
|
43
|
+
Activity activity = getCurrentActivity();
|
|
44
|
+
if (activity == null) {
|
|
45
|
+
promise.reject("E_NO_ACTIVITY", "No current activity");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (pendingPromise != null) {
|
|
49
|
+
promise.reject("E_BUSY", "Huawei sign-in already in progress");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
AccountAuthParams authParams = new AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)
|
|
54
|
+
.setProfile()
|
|
55
|
+
.createParams();
|
|
56
|
+
AccountAuthService service = AccountAuthManager.getService(activity, authParams);
|
|
57
|
+
Task<AuthAccount> task = service.silentSignIn();
|
|
58
|
+
task.addOnSuccessListener(account -> resolvePromise(promise, account));
|
|
59
|
+
task.addOnFailureListener(e -> {
|
|
60
|
+
pendingPromise = promise;
|
|
61
|
+
try {
|
|
62
|
+
activity.startActivityForResult(service.getSignInIntent(), REQUEST_SIGN_IN);
|
|
63
|
+
} catch (Exception ex) {
|
|
64
|
+
pendingPromise = null;
|
|
65
|
+
promise.reject("E_INTENT", ex.getMessage(), ex);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private void resolvePromise(Promise promise, AuthAccount account) {
|
|
71
|
+
try {
|
|
72
|
+
promise.resolve(accountToMap(account));
|
|
73
|
+
} catch (Exception e) {
|
|
74
|
+
promise.reject("E_ACCOUNT", e.getMessage(), e);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private WritableMap accountToMap(AuthAccount account) {
|
|
79
|
+
WritableMap map = Arguments.createMap();
|
|
80
|
+
map.putString("openid", safe(account.getOpenId()));
|
|
81
|
+
map.putString("unionid", safe(account.getUnionId()));
|
|
82
|
+
map.putString("nickname", safe(account.getDisplayName()));
|
|
83
|
+
map.putString("headimgurl", safe(pickAvatar(account)));
|
|
84
|
+
return map;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private static String pickAvatar(AuthAccount account) {
|
|
88
|
+
String u = account.getAvatarUriString();
|
|
89
|
+
return u != null ? u : "";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private static String safe(String s) {
|
|
93
|
+
return s != null ? s : "";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Override
|
|
97
|
+
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) {
|
|
98
|
+
if (requestCode != REQUEST_SIGN_IN || pendingPromise == null) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
Promise promise = pendingPromise;
|
|
102
|
+
pendingPromise = null;
|
|
103
|
+
if (resultCode != Activity.RESULT_OK || intent == null) {
|
|
104
|
+
promise.reject("E_CANCELED", "Huawei sign-in canceled");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
Task<AuthAccount> authAccountTask = AccountAuthManager.parseAuthResultFromIntent(intent);
|
|
108
|
+
if (authAccountTask == null) {
|
|
109
|
+
promise.reject("E_PARSE", "null auth result");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (authAccountTask.isSuccessful()) {
|
|
113
|
+
AuthAccount account = authAccountTask.getResult();
|
|
114
|
+
resolvePromise(promise, account);
|
|
115
|
+
} else {
|
|
116
|
+
Exception ex = authAccountTask.getException();
|
|
117
|
+
String code = "E_SIGN_IN";
|
|
118
|
+
int status = -1;
|
|
119
|
+
if (ex instanceof ApiException) {
|
|
120
|
+
status = ((ApiException) ex).getStatusCode();
|
|
121
|
+
code = String.valueOf(status);
|
|
122
|
+
}
|
|
123
|
+
promise.reject(code, ex != null ? ex.getMessage() : "sign in failed", ex);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@Override
|
|
128
|
+
public void onNewIntent(Intent intent) {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -15,7 +15,8 @@ class ReactNativeToolkitPackage : ReactPackage {
|
|
|
15
15
|
ReactNativeToolkitModule(reactContext),
|
|
16
16
|
NCYReport(reactContext),
|
|
17
17
|
NCYAPI(reactContext),
|
|
18
|
-
CheckPackageInstallationModule(reactContext)
|
|
18
|
+
CheckPackageInstallationModule(reactContext),
|
|
19
|
+
HuaweiLoginModule(reactContext)
|
|
19
20
|
)
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -23,4 +24,3 @@ class ReactNativeToolkitPackage : ReactPackage {
|
|
|
23
24
|
return emptyList<ViewManager<*, *>>()
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
|
|
@@ -9,9 +9,15 @@ var _PlatformHelper = require("./PlatformHelper");
|
|
|
9
9
|
const HuaweiLoginModule = _reactNative.NativeModules.HuaweiLoginModule ?? _reactNative.TurboModuleRegistry.get('HuaweiLoginModule');
|
|
10
10
|
const HuaweiLoginUtil = exports.HuaweiLoginUtil = {
|
|
11
11
|
doLogin: async callback => {
|
|
12
|
-
if (
|
|
12
|
+
if (_PlatformHelper.PlatformHelper.isIOS()) {
|
|
13
13
|
callback({
|
|
14
|
-
error: 'Huawei Login
|
|
14
|
+
error: 'Huawei Login is not supported on iOS'
|
|
15
|
+
});
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!HuaweiLoginModule || typeof HuaweiLoginModule.signIn !== 'function') {
|
|
19
|
+
callback({
|
|
20
|
+
error: 'HuaweiLoginModule not available'
|
|
15
21
|
});
|
|
16
22
|
return;
|
|
17
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_PlatformHelper","HuaweiLoginModule","NativeModules","TurboModuleRegistry","get","HuaweiLoginUtil","exports","doLogin","callback","PlatformHelper","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_PlatformHelper","HuaweiLoginModule","NativeModules","TurboModuleRegistry","get","HuaweiLoginUtil","exports","doLogin","callback","PlatformHelper","isIOS","error","signIn","result","nickname","headimgurl","openid","unionid","e"],"sourceRoot":"../../src","sources":["HuaweiLoginUtil.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,MAAME,iBAAiB,GACrBC,0BAAa,CAACD,iBAAiB,IAC/BE,gCAAmB,CAACC,GAAG,CAAM,mBAAmB,CAAC;AAE5C,MAAMC,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG;EAC7BE,OAAO,EAAE,MACPC,QAMU,IACP;IACH,IAAIC,8BAAc,CAACC,KAAK,CAAC,CAAC,EAAE;MAC1BF,QAAQ,CAAC;QAAEG,KAAK,EAAE;MAAuC,CAAC,CAAC;MAC3D;IACF;IACA,IAAI,CAACV,iBAAiB,IAAI,OAAOA,iBAAiB,CAACW,MAAM,KAAK,UAAU,EAAE;MACxEJ,QAAQ,CAAC;QAAEG,KAAK,EAAE;MAAkC,CAAC,CAAC;MACtD;IACF;IACA,IAAI;MACF,MAAME,MAAM,GAAG,MAAMZ,iBAAiB,CAACW,MAAM,CAAC,CAAC;MAC/CJ,QAAQ,CAAC;QACPM,QAAQ,EAAED,MAAM,CAACC,QAAQ;QACzBC,UAAU,EAAEF,MAAM,CAACE,UAAU;QAC7BC,MAAM,EAAEH,MAAM,CAACG,MAAM;QACrBC,OAAO,EAAEJ,MAAM,CAACI;MAClB,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOC,CAAC,EAAE;MACVV,QAAQ,CAAC;QAAEG,KAAK,EAAEO;MAAE,CAAC,CAAC;IACxB;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -5,9 +5,15 @@ import { PlatformHelper } from './PlatformHelper';
|
|
|
5
5
|
const HuaweiLoginModule = NativeModules.HuaweiLoginModule ?? TurboModuleRegistry.get('HuaweiLoginModule');
|
|
6
6
|
export const HuaweiLoginUtil = {
|
|
7
7
|
doLogin: async callback => {
|
|
8
|
-
if (
|
|
8
|
+
if (PlatformHelper.isIOS()) {
|
|
9
9
|
callback({
|
|
10
|
-
error: 'Huawei Login
|
|
10
|
+
error: 'Huawei Login is not supported on iOS'
|
|
11
|
+
});
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (!HuaweiLoginModule || typeof HuaweiLoginModule.signIn !== 'function') {
|
|
15
|
+
callback({
|
|
16
|
+
error: 'HuaweiLoginModule not available'
|
|
11
17
|
});
|
|
12
18
|
return;
|
|
13
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","TurboModuleRegistry","PlatformHelper","HuaweiLoginModule","get","HuaweiLoginUtil","doLogin","callback","
|
|
1
|
+
{"version":3,"names":["NativeModules","TurboModuleRegistry","PlatformHelper","HuaweiLoginModule","get","HuaweiLoginUtil","doLogin","callback","isIOS","error","signIn","result","nickname","headimgurl","openid","unionid","e"],"sourceRoot":"../../src","sources":["HuaweiLoginUtil.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,mBAAmB,QAAQ,cAAc;AACjE,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,MAAMC,iBAAiB,GACrBH,aAAa,CAACG,iBAAiB,IAC/BF,mBAAmB,CAACG,GAAG,CAAM,mBAAmB,CAAC;AAEnD,OAAO,MAAMC,eAAe,GAAG;EAC7BC,OAAO,EAAE,MACPC,QAMU,IACP;IACH,IAAIL,cAAc,CAACM,KAAK,CAAC,CAAC,EAAE;MAC1BD,QAAQ,CAAC;QAAEE,KAAK,EAAE;MAAuC,CAAC,CAAC;MAC3D;IACF;IACA,IAAI,CAACN,iBAAiB,IAAI,OAAOA,iBAAiB,CAACO,MAAM,KAAK,UAAU,EAAE;MACxEH,QAAQ,CAAC;QAAEE,KAAK,EAAE;MAAkC,CAAC,CAAC;MACtD;IACF;IACA,IAAI;MACF,MAAME,MAAM,GAAG,MAAMR,iBAAiB,CAACO,MAAM,CAAC,CAAC;MAC/CH,QAAQ,CAAC;QACPK,QAAQ,EAAED,MAAM,CAACC,QAAQ;QACzBC,UAAU,EAAEF,MAAM,CAACE,UAAU;QAC7BC,MAAM,EAAEH,MAAM,CAACG,MAAM;QACrBC,OAAO,EAAEJ,MAAM,CAACI;MAClB,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOC,CAAC,EAAE;MACVT,QAAQ,CAAC;QAAEE,KAAK,EAAEO;MAAE,CAAC,CAAC;IACxB;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HuaweiLoginUtil.d.ts","sourceRoot":"","sources":["../../src/HuaweiLoginUtil.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,eAAe;iCAEL;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,GAAG,CAAC;KACb,KAAK,IAAI;
|
|
1
|
+
{"version":3,"file":"HuaweiLoginUtil.d.ts","sourceRoot":"","sources":["../../src/HuaweiLoginUtil.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,eAAe;iCAEL;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,GAAG,CAAC;KACb,KAAK,IAAI;CAsBb,CAAC"}
|
package/package.json
CHANGED
package/src/HuaweiLoginUtil.ts
CHANGED
|
@@ -15,8 +15,12 @@ export const HuaweiLoginUtil = {
|
|
|
15
15
|
error?: any;
|
|
16
16
|
}) => void
|
|
17
17
|
) => {
|
|
18
|
-
if (
|
|
19
|
-
callback({ error: 'Huawei Login
|
|
18
|
+
if (PlatformHelper.isIOS()) {
|
|
19
|
+
callback({ error: 'Huawei Login is not supported on iOS' });
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!HuaweiLoginModule || typeof HuaweiLoginModule.signIn !== 'function') {
|
|
23
|
+
callback({ error: 'HuaweiLoginModule not available' });
|
|
20
24
|
return;
|
|
21
25
|
}
|
|
22
26
|
try {
|