Skip to content

Commit

Permalink
Merge pull request #1 from wicked-tc130/master
Browse files Browse the repository at this point in the history
update version to 2.0.0
  • Loading branch information
wicked-tc130 committed Apr 16, 2019
2 parents 33fcaed + 04b04e9 commit ad11e0f
Show file tree
Hide file tree
Showing 55 changed files with 1,145 additions and 119 deletions.
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ repositories {
}

dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
// api fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
implementation 'cn.jiguang.sdk:jverification:2.1.0'
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cn.jpush.reactnativejvrification;

class JVerificationConstant {
//导航栏
static final String NAV_COLOR = "navColor";
static final String NAV_TEXT = "navText";
static final String NAV_TEXT_COLOR = "navTextColor";
static final String NAV_RETURN_IMAGE = "navReturnImage";
//logo
static final String LOGO_HIDDEN = "logoHidden";
static final String LOGO_Width = "logoWidth";
static final String LOGO_Height = "logoHeight";
static final String LOGO_Image = "logoImage";
static final String LOGO_OFFSET_Y = "logoOffsetY";
//手机号码
static final String NUM_COLOR = "numColor";
static final String NUM_OFFSET_Y = "numOffsetY";
//slogan
static final String SLOGAN_TEXT_COLOR = "sloganTextColor";
static final String SLOGAN_OFFSET_Y = "sloganOffsetY";
//登录按钮
static final String LOGIN_BTN_TEXT = "loginBtnText";
static final String LOGIN_BTN_TEXT_COLOR = "loginBtnTextColor";
static final String LOGIN_BTN_IMAGE = "loginBtnImage";
static final String LOGIN_BTN_OFFSET_Y = "loginBtnOffsetY";
//隐私条款
static final String PRIVACY_ONE_NAME = "privacyOneName";
static final String PRIVACY_ONE_URL = "privacyOneUrl";
static final String PRIVACY_TWO_NAME = "privacyTwoName";
static final String PRIVACY_TWO_URL = "privacyTwoUrl";
static final String PRIVACY_BASIC_COLOR = "privacyBasicColor";
static final String PRIVACY_PROTOCOL_COLOR = "privacyProtocolColor";
static final String PRIVACY_CHECK_IMAGE = "privacyCheckImage";
static final String PRIVACY_UNCHECK_IMAGE = "privacyUncheckImage";
static final String PRIVACY_OFFSET_Y = "privacyOffsetY";
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.jpush.reactnativejvrification;

import android.Manifest;
import android.util.Log;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
Expand All @@ -13,6 +12,7 @@
import com.facebook.react.bridge.WritableMap;

import cn.jiguang.verifysdk.api.JVerificationInterface;
import cn.jiguang.verifysdk.api.JVerifyUIConfig;
import cn.jiguang.verifysdk.api.VerifyListener;
import cn.jpush.reactnativejvrification.utils.AndroidUtils;

Expand Down Expand Up @@ -51,19 +51,13 @@ public void initialize() {
super.initialize();
}

@ReactMethod
public void setup(ReadableMap map) {
JVerificationInterface.init(getCurrentActivity());
}

@ReactMethod
public void requestPermission(Callback permissionCallback) {
if (AndroidUtils.checkPermission(getCurrentActivity(), REQUIRED_PERMISSIONS)) {
doCallback(permissionCallback,CODE_PERMISSION_GRANTED,MSG_PERMISSION_GRANTED);
doCallback(permissionCallback, CODE_PERMISSION_GRANTED, MSG_PERMISSION_GRANTED);
return;
}
this.permissionCallback = permissionCallback;
Log.i(TAG,"requestPermission");
try {
AndroidUtils.requestPermission(getCurrentActivity(), REQUIRED_PERMISSIONS);
requestPermissionSended = true;
Expand All @@ -72,46 +66,128 @@ public void requestPermission(Callback permissionCallback) {
}
}


@ReactMethod
public void setDebug(boolean enable) {
public void setDebugMode(boolean enable) {
JVerificationInterface.setDebugMode(enable);
}

@ReactMethod
public void init() {
JVerificationInterface.init(getCurrentActivity());
}

@ReactMethod
public void checkVerifyEnable(Callback callback) {
boolean isVerifyEnable = JVerificationInterface.checkVerifyEnable(getCurrentActivity());
WritableMap map = Arguments.createMap();
map.putBoolean("enable", isVerifyEnable);
callback.invoke(map);
}

@ReactMethod
public void getToken(final Callback callback) {
JVerificationInterface.getToken(getCurrentActivity(), new VerifyListener() {
@Override
public void onResult(int code, String content, String operato) {
doCallback(callback,code,content);
public void onResult(int code, String content, String operator) {
doCallback(callback, code, content, operator);
}
});
}

@ReactMethod
public void verifyNumber(ReadableMap map,final Callback callback) {
public void verifyNumber(ReadableMap map, final Callback callback) {
String number = map.getString("number");
String token = map.getString("token");

JVerificationInterface.verifyNumber(getCurrentActivity(), token, number, new VerifyListener() {
@Override
public void onResult(int code, String content, String operator) {
doCallback(callback,code,content);
doCallback(callback, code, content, operator);
}
});
}

@ReactMethod
public void loginAuth(final Callback callback) {
JVerificationInterface.loginAuth(getCurrentActivity(), new VerifyListener() {
@Override
public void onResult(int code, String token, String operator) {
doCallback(callback, code, token, operator);
}
});
}

@ReactMethod
public void setCustomUIWithConfig(ReadableMap map) {
JVerifyUIConfig uiConfig = convertMapToConfig(map);
JVerificationInterface.setCustomUIWithConfig(uiConfig);
}

private JVerifyUIConfig convertMapToConfig(ReadableMap map) {
int navColor = map.hasKey(JVerificationConstant.NAV_COLOR) ? map.getInt(JVerificationConstant.NAV_COLOR) : -16742704;
String navText = map.hasKey(JVerificationConstant.NAV_TEXT) ? map.getString(JVerificationConstant.NAV_TEXT) : "登录";
int navTextColor = map.hasKey(JVerificationConstant.NAV_TEXT_COLOR) ? map.getInt(JVerificationConstant.NAV_TEXT_COLOR) : -1;
String navReturnImage = map.hasKey(JVerificationConstant.NAV_RETURN_IMAGE) ? map.getString(JVerificationConstant.NAV_RETURN_IMAGE) : "umcsdk_return_bg";
boolean isLogoHidden = map.hasKey(JVerificationConstant.LOGO_HIDDEN) && map.getBoolean(JVerificationConstant.LOGO_HIDDEN);
String logoImage = map.hasKey(JVerificationConstant.LOGO_Image) ? map.getString(JVerificationConstant.LOGO_Image) : null;
int logoWidth = map.hasKey(JVerificationConstant.LOGO_Width) ? map.getInt(JVerificationConstant.LOGO_Width) : 70;
int logoHeight = map.hasKey(JVerificationConstant.LOGO_Height) ? map.getInt(JVerificationConstant.LOGO_Height) : 70;
int logoOffsetY = map.hasKey(JVerificationConstant.LOGO_OFFSET_Y) ? map.getInt(JVerificationConstant.LOGO_OFFSET_Y) : 50;
int numColor = map.hasKey(JVerificationConstant.NUM_COLOR) ? map.getInt(JVerificationConstant.NUM_COLOR) : -16742704;
int numOffsetY = map.hasKey(JVerificationConstant.NUM_OFFSET_Y) ? map.getInt(JVerificationConstant.NUM_OFFSET_Y) : 184;
int sloganTextColor = map.hasKey(JVerificationConstant.SLOGAN_TEXT_COLOR) ? map.getInt(JVerificationConstant.SLOGAN_TEXT_COLOR) : -1;
int sloganOffsetY = map.hasKey(JVerificationConstant.SLOGAN_OFFSET_Y) ? map.getInt(JVerificationConstant.SLOGAN_OFFSET_Y) : 224;
String loginBtnText = map.hasKey(JVerificationConstant.LOGIN_BTN_TEXT) ? map.getString(JVerificationConstant.LOGIN_BTN_TEXT) : "本机号码一键登录";
int loginBtnTextColor = map.hasKey(JVerificationConstant.LOGIN_BTN_TEXT_COLOR) ? map.getInt(JVerificationConstant.LOGIN_BTN_TEXT_COLOR) : -1;
String loginBtnImage = map.hasKey(JVerificationConstant.LOGIN_BTN_IMAGE) ? map.getString(JVerificationConstant.LOGIN_BTN_IMAGE) : "umcsdk_login_btn_bg";
int loginBtnOffsetY = map.hasKey(JVerificationConstant.LOGIN_BTN_OFFSET_Y) ? map.getInt(JVerificationConstant.LOGIN_BTN_OFFSET_Y) : 254;
String privacyOneName = map.hasKey(JVerificationConstant.PRIVACY_ONE_NAME) ? map.getString(JVerificationConstant.PRIVACY_ONE_NAME) : null;
String privacyOneUrl = map.hasKey(JVerificationConstant.PRIVACY_ONE_URL) ? map.getString(JVerificationConstant.PRIVACY_ONE_URL) : null;
String privacyTwoName = map.hasKey(JVerificationConstant.PRIVACY_TWO_NAME) ? map.getString(JVerificationConstant.PRIVACY_TWO_NAME) : null;
String privacyTwoUrl = map.hasKey(JVerificationConstant.PRIVACY_TWO_URL) ? map.getString(JVerificationConstant.PRIVACY_TWO_URL) : null;
int privacyBasicColor = map.hasKey(JVerificationConstant.PRIVACY_BASIC_COLOR) ? map.getInt(JVerificationConstant.PRIVACY_BASIC_COLOR) : -10066330;
int privacyProtocolColor = map.hasKey(JVerificationConstant.PRIVACY_PROTOCOL_COLOR) ? map.getInt(JVerificationConstant.PRIVACY_PROTOCOL_COLOR) : -16007674;
int privacyOffsetY = map.hasKey(JVerificationConstant.PRIVACY_OFFSET_Y) ? map.getInt(JVerificationConstant.PRIVACY_OFFSET_Y) : 30;
String checkImage = map.hasKey(JVerificationConstant.PRIVACY_CHECK_IMAGE) ? map.getString(JVerificationConstant.PRIVACY_CHECK_IMAGE) : "umcsdk_check_image";
String unCheckImage = map.hasKey(JVerificationConstant.PRIVACY_UNCHECK_IMAGE) ? map.getString(JVerificationConstant.PRIVACY_UNCHECK_IMAGE) : "umcsdk_uncheck_image";

return new JVerifyUIConfig.Builder()
.setNavColor(navColor)
.setNavText(navText)
.setNavTextColor(navTextColor)
.setNavReturnImgPath(navReturnImage)
.setLogoHidden(isLogoHidden)
.setLogoImgPath(logoImage)
.setLogoWidth(logoWidth)
.setLogoHeight(logoHeight)
.setLogoOffsetY(logoOffsetY)
.setNumberColor(numColor)
.setNumFieldOffsetY(numOffsetY)
.setSloganTextColor(sloganTextColor)
.setSloganOffsetY(sloganOffsetY)
.setLogBtnText(loginBtnText)
.setLogBtnTextColor(loginBtnTextColor)
.setLogBtnImgPath(loginBtnImage)
.setLogBtnOffsetY(loginBtnOffsetY)
.setAppPrivacyOne(privacyOneName, privacyOneUrl)
.setAppPrivacyTwo(privacyTwoName, privacyTwoUrl)
.setAppPrivacyColor(privacyBasicColor, privacyProtocolColor)
.setPrivacyOffsetY(privacyOffsetY)
.setCheckedImgPath(checkImage)
.setUncheckedImgPath(unCheckImage)
.build();
}

@Override
public void onHostResume() {
if (requestPermissionSended) {
if (AndroidUtils.checkPermission(getCurrentActivity(), REQUIRED_PERMISSIONS)) {
doCallback(permissionCallback,CODE_PERMISSION_GRANTED,MSG_PERMISSION_GRANTED);
doCallback(permissionCallback, CODE_PERMISSION_GRANTED, MSG_PERMISSION_GRANTED);
} else {
doCallback(permissionCallback,ERR_CODE_PERMISSION,ERR_MSG_PERMISSION);
doCallback(permissionCallback, ERR_CODE_PERMISSION, ERR_MSG_PERMISSION);
}
}
requestPermissionSended = false;

}

@Override
Expand All @@ -124,10 +200,18 @@ public void onHostDestroy() {

}

private void doCallback(Callback callback, int code, String content){
private void doCallback(Callback callback, int code, String content) {
WritableMap map = Arguments.createMap();
map.putInt("code", code);
map.putString("content", content);
callback.invoke(map);
}

private void doCallback(Callback callback, int code, String content, String operator) {
WritableMap map = Arguments.createMap();
map.putInt("code",code);
map.putString("content",content);
map.putInt("code", code);
map.putString("content", content);
map.putString("operator", operator);
callback.invoke(map);
}
}
Loading

0 comments on commit ad11e0f

Please sign in to comment.