Skip to content

Commit ad11e0f

Browse files
author
wicked-tc130
authored
Merge pull request #1 from wicked-tc130/master
update version to 2.0.0
2 parents 33fcaed + 04b04e9 commit ad11e0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1145
-119
lines changed

android/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ repositories {
3434
}
3535

3636
dependencies {
37-
api fileTree(include: ['*.jar'], dir: 'libs')
37+
// api fileTree(include: ['*.jar'], dir: 'libs')
3838
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
39+
implementation 'cn.jiguang.sdk:jverification:2.1.0'
3940
}
-174 KB
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cn.jpush.reactnativejvrification;
2+
3+
class JVerificationConstant {
4+
//导航栏
5+
static final String NAV_COLOR = "navColor";
6+
static final String NAV_TEXT = "navText";
7+
static final String NAV_TEXT_COLOR = "navTextColor";
8+
static final String NAV_RETURN_IMAGE = "navReturnImage";
9+
//logo
10+
static final String LOGO_HIDDEN = "logoHidden";
11+
static final String LOGO_Width = "logoWidth";
12+
static final String LOGO_Height = "logoHeight";
13+
static final String LOGO_Image = "logoImage";
14+
static final String LOGO_OFFSET_Y = "logoOffsetY";
15+
//手机号码
16+
static final String NUM_COLOR = "numColor";
17+
static final String NUM_OFFSET_Y = "numOffsetY";
18+
//slogan
19+
static final String SLOGAN_TEXT_COLOR = "sloganTextColor";
20+
static final String SLOGAN_OFFSET_Y = "sloganOffsetY";
21+
//登录按钮
22+
static final String LOGIN_BTN_TEXT = "loginBtnText";
23+
static final String LOGIN_BTN_TEXT_COLOR = "loginBtnTextColor";
24+
static final String LOGIN_BTN_IMAGE = "loginBtnImage";
25+
static final String LOGIN_BTN_OFFSET_Y = "loginBtnOffsetY";
26+
//隐私条款
27+
static final String PRIVACY_ONE_NAME = "privacyOneName";
28+
static final String PRIVACY_ONE_URL = "privacyOneUrl";
29+
static final String PRIVACY_TWO_NAME = "privacyTwoName";
30+
static final String PRIVACY_TWO_URL = "privacyTwoUrl";
31+
static final String PRIVACY_BASIC_COLOR = "privacyBasicColor";
32+
static final String PRIVACY_PROTOCOL_COLOR = "privacyProtocolColor";
33+
static final String PRIVACY_CHECK_IMAGE = "privacyCheckImage";
34+
static final String PRIVACY_UNCHECK_IMAGE = "privacyUncheckImage";
35+
static final String PRIVACY_OFFSET_Y = "privacyOffsetY";
36+
}

android/src/main/java/cn/jpush/reactnativejvrification/JVerificationModule.java

Lines changed: 104 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cn.jpush.reactnativejvrification;
22

33
import android.Manifest;
4-
import android.util.Log;
54

65
import com.facebook.react.bridge.Arguments;
76
import com.facebook.react.bridge.Callback;
@@ -13,6 +12,7 @@
1312
import com.facebook.react.bridge.WritableMap;
1413

1514
import cn.jiguang.verifysdk.api.JVerificationInterface;
15+
import cn.jiguang.verifysdk.api.JVerifyUIConfig;
1616
import cn.jiguang.verifysdk.api.VerifyListener;
1717
import cn.jpush.reactnativejvrification.utils.AndroidUtils;
1818

@@ -51,19 +51,13 @@ public void initialize() {
5151
super.initialize();
5252
}
5353

54-
@ReactMethod
55-
public void setup(ReadableMap map) {
56-
JVerificationInterface.init(getCurrentActivity());
57-
}
58-
5954
@ReactMethod
6055
public void requestPermission(Callback permissionCallback) {
6156
if (AndroidUtils.checkPermission(getCurrentActivity(), REQUIRED_PERMISSIONS)) {
62-
doCallback(permissionCallback,CODE_PERMISSION_GRANTED,MSG_PERMISSION_GRANTED);
57+
doCallback(permissionCallback, CODE_PERMISSION_GRANTED, MSG_PERMISSION_GRANTED);
6358
return;
6459
}
6560
this.permissionCallback = permissionCallback;
66-
Log.i(TAG,"requestPermission");
6761
try {
6862
AndroidUtils.requestPermission(getCurrentActivity(), REQUIRED_PERMISSIONS);
6963
requestPermissionSended = true;
@@ -72,46 +66,128 @@ public void requestPermission(Callback permissionCallback) {
7266
}
7367
}
7468

75-
7669
@ReactMethod
77-
public void setDebug(boolean enable) {
70+
public void setDebugMode(boolean enable) {
7871
JVerificationInterface.setDebugMode(enable);
7972
}
8073

74+
@ReactMethod
75+
public void init() {
76+
JVerificationInterface.init(getCurrentActivity());
77+
}
78+
79+
@ReactMethod
80+
public void checkVerifyEnable(Callback callback) {
81+
boolean isVerifyEnable = JVerificationInterface.checkVerifyEnable(getCurrentActivity());
82+
WritableMap map = Arguments.createMap();
83+
map.putBoolean("enable", isVerifyEnable);
84+
callback.invoke(map);
85+
}
86+
8187
@ReactMethod
8288
public void getToken(final Callback callback) {
8389
JVerificationInterface.getToken(getCurrentActivity(), new VerifyListener() {
8490
@Override
85-
public void onResult(int code, String content, String operato) {
86-
doCallback(callback,code,content);
91+
public void onResult(int code, String content, String operator) {
92+
doCallback(callback, code, content, operator);
8793
}
8894
});
8995
}
9096

9197
@ReactMethod
92-
public void verifyNumber(ReadableMap map,final Callback callback) {
98+
public void verifyNumber(ReadableMap map, final Callback callback) {
9399
String number = map.getString("number");
94100
String token = map.getString("token");
95101

96102
JVerificationInterface.verifyNumber(getCurrentActivity(), token, number, new VerifyListener() {
97103
@Override
98104
public void onResult(int code, String content, String operator) {
99-
doCallback(callback,code,content);
105+
doCallback(callback, code, content, operator);
100106
}
101107
});
102108
}
103109

110+
@ReactMethod
111+
public void loginAuth(final Callback callback) {
112+
JVerificationInterface.loginAuth(getCurrentActivity(), new VerifyListener() {
113+
@Override
114+
public void onResult(int code, String token, String operator) {
115+
doCallback(callback, code, token, operator);
116+
}
117+
});
118+
}
119+
120+
@ReactMethod
121+
public void setCustomUIWithConfig(ReadableMap map) {
122+
JVerifyUIConfig uiConfig = convertMapToConfig(map);
123+
JVerificationInterface.setCustomUIWithConfig(uiConfig);
124+
}
125+
126+
private JVerifyUIConfig convertMapToConfig(ReadableMap map) {
127+
int navColor = map.hasKey(JVerificationConstant.NAV_COLOR) ? map.getInt(JVerificationConstant.NAV_COLOR) : -16742704;
128+
String navText = map.hasKey(JVerificationConstant.NAV_TEXT) ? map.getString(JVerificationConstant.NAV_TEXT) : "登录";
129+
int navTextColor = map.hasKey(JVerificationConstant.NAV_TEXT_COLOR) ? map.getInt(JVerificationConstant.NAV_TEXT_COLOR) : -1;
130+
String navReturnImage = map.hasKey(JVerificationConstant.NAV_RETURN_IMAGE) ? map.getString(JVerificationConstant.NAV_RETURN_IMAGE) : "umcsdk_return_bg";
131+
boolean isLogoHidden = map.hasKey(JVerificationConstant.LOGO_HIDDEN) && map.getBoolean(JVerificationConstant.LOGO_HIDDEN);
132+
String logoImage = map.hasKey(JVerificationConstant.LOGO_Image) ? map.getString(JVerificationConstant.LOGO_Image) : null;
133+
int logoWidth = map.hasKey(JVerificationConstant.LOGO_Width) ? map.getInt(JVerificationConstant.LOGO_Width) : 70;
134+
int logoHeight = map.hasKey(JVerificationConstant.LOGO_Height) ? map.getInt(JVerificationConstant.LOGO_Height) : 70;
135+
int logoOffsetY = map.hasKey(JVerificationConstant.LOGO_OFFSET_Y) ? map.getInt(JVerificationConstant.LOGO_OFFSET_Y) : 50;
136+
int numColor = map.hasKey(JVerificationConstant.NUM_COLOR) ? map.getInt(JVerificationConstant.NUM_COLOR) : -16742704;
137+
int numOffsetY = map.hasKey(JVerificationConstant.NUM_OFFSET_Y) ? map.getInt(JVerificationConstant.NUM_OFFSET_Y) : 184;
138+
int sloganTextColor = map.hasKey(JVerificationConstant.SLOGAN_TEXT_COLOR) ? map.getInt(JVerificationConstant.SLOGAN_TEXT_COLOR) : -1;
139+
int sloganOffsetY = map.hasKey(JVerificationConstant.SLOGAN_OFFSET_Y) ? map.getInt(JVerificationConstant.SLOGAN_OFFSET_Y) : 224;
140+
String loginBtnText = map.hasKey(JVerificationConstant.LOGIN_BTN_TEXT) ? map.getString(JVerificationConstant.LOGIN_BTN_TEXT) : "本机号码一键登录";
141+
int loginBtnTextColor = map.hasKey(JVerificationConstant.LOGIN_BTN_TEXT_COLOR) ? map.getInt(JVerificationConstant.LOGIN_BTN_TEXT_COLOR) : -1;
142+
String loginBtnImage = map.hasKey(JVerificationConstant.LOGIN_BTN_IMAGE) ? map.getString(JVerificationConstant.LOGIN_BTN_IMAGE) : "umcsdk_login_btn_bg";
143+
int loginBtnOffsetY = map.hasKey(JVerificationConstant.LOGIN_BTN_OFFSET_Y) ? map.getInt(JVerificationConstant.LOGIN_BTN_OFFSET_Y) : 254;
144+
String privacyOneName = map.hasKey(JVerificationConstant.PRIVACY_ONE_NAME) ? map.getString(JVerificationConstant.PRIVACY_ONE_NAME) : null;
145+
String privacyOneUrl = map.hasKey(JVerificationConstant.PRIVACY_ONE_URL) ? map.getString(JVerificationConstant.PRIVACY_ONE_URL) : null;
146+
String privacyTwoName = map.hasKey(JVerificationConstant.PRIVACY_TWO_NAME) ? map.getString(JVerificationConstant.PRIVACY_TWO_NAME) : null;
147+
String privacyTwoUrl = map.hasKey(JVerificationConstant.PRIVACY_TWO_URL) ? map.getString(JVerificationConstant.PRIVACY_TWO_URL) : null;
148+
int privacyBasicColor = map.hasKey(JVerificationConstant.PRIVACY_BASIC_COLOR) ? map.getInt(JVerificationConstant.PRIVACY_BASIC_COLOR) : -10066330;
149+
int privacyProtocolColor = map.hasKey(JVerificationConstant.PRIVACY_PROTOCOL_COLOR) ? map.getInt(JVerificationConstant.PRIVACY_PROTOCOL_COLOR) : -16007674;
150+
int privacyOffsetY = map.hasKey(JVerificationConstant.PRIVACY_OFFSET_Y) ? map.getInt(JVerificationConstant.PRIVACY_OFFSET_Y) : 30;
151+
String checkImage = map.hasKey(JVerificationConstant.PRIVACY_CHECK_IMAGE) ? map.getString(JVerificationConstant.PRIVACY_CHECK_IMAGE) : "umcsdk_check_image";
152+
String unCheckImage = map.hasKey(JVerificationConstant.PRIVACY_UNCHECK_IMAGE) ? map.getString(JVerificationConstant.PRIVACY_UNCHECK_IMAGE) : "umcsdk_uncheck_image";
153+
154+
return new JVerifyUIConfig.Builder()
155+
.setNavColor(navColor)
156+
.setNavText(navText)
157+
.setNavTextColor(navTextColor)
158+
.setNavReturnImgPath(navReturnImage)
159+
.setLogoHidden(isLogoHidden)
160+
.setLogoImgPath(logoImage)
161+
.setLogoWidth(logoWidth)
162+
.setLogoHeight(logoHeight)
163+
.setLogoOffsetY(logoOffsetY)
164+
.setNumberColor(numColor)
165+
.setNumFieldOffsetY(numOffsetY)
166+
.setSloganTextColor(sloganTextColor)
167+
.setSloganOffsetY(sloganOffsetY)
168+
.setLogBtnText(loginBtnText)
169+
.setLogBtnTextColor(loginBtnTextColor)
170+
.setLogBtnImgPath(loginBtnImage)
171+
.setLogBtnOffsetY(loginBtnOffsetY)
172+
.setAppPrivacyOne(privacyOneName, privacyOneUrl)
173+
.setAppPrivacyTwo(privacyTwoName, privacyTwoUrl)
174+
.setAppPrivacyColor(privacyBasicColor, privacyProtocolColor)
175+
.setPrivacyOffsetY(privacyOffsetY)
176+
.setCheckedImgPath(checkImage)
177+
.setUncheckedImgPath(unCheckImage)
178+
.build();
179+
}
180+
104181
@Override
105182
public void onHostResume() {
106183
if (requestPermissionSended) {
107184
if (AndroidUtils.checkPermission(getCurrentActivity(), REQUIRED_PERMISSIONS)) {
108-
doCallback(permissionCallback,CODE_PERMISSION_GRANTED,MSG_PERMISSION_GRANTED);
185+
doCallback(permissionCallback, CODE_PERMISSION_GRANTED, MSG_PERMISSION_GRANTED);
109186
} else {
110-
doCallback(permissionCallback,ERR_CODE_PERMISSION,ERR_MSG_PERMISSION);
187+
doCallback(permissionCallback, ERR_CODE_PERMISSION, ERR_MSG_PERMISSION);
111188
}
112189
}
113190
requestPermissionSended = false;
114-
115191
}
116192

117193
@Override
@@ -124,10 +200,18 @@ public void onHostDestroy() {
124200

125201
}
126202

127-
private void doCallback(Callback callback, int code, String content){
203+
private void doCallback(Callback callback, int code, String content) {
204+
WritableMap map = Arguments.createMap();
205+
map.putInt("code", code);
206+
map.putString("content", content);
207+
callback.invoke(map);
208+
}
209+
210+
private void doCallback(Callback callback, int code, String content, String operator) {
128211
WritableMap map = Arguments.createMap();
129-
map.putInt("code",code);
130-
map.putString("content",content);
212+
map.putInt("code", code);
213+
map.putString("content", content);
214+
map.putString("operator", operator);
131215
callback.invoke(map);
132216
}
133217
}

0 commit comments

Comments
 (0)