diff --git a/android/build.gradle b/android/build.gradle index 3da0b5d..e9f1558 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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' } diff --git a/android/libs/jverification-android-release-1.1.2.jar b/android/libs/jverification-android-release-1.1.2.jar deleted file mode 100644 index 425de96..0000000 Binary files a/android/libs/jverification-android-release-1.1.2.jar and /dev/null differ diff --git a/android/src/main/java/cn/jpush/reactnativejvrification/JVerificationConstant.java b/android/src/main/java/cn/jpush/reactnativejvrification/JVerificationConstant.java new file mode 100644 index 0000000..24c88bd --- /dev/null +++ b/android/src/main/java/cn/jpush/reactnativejvrification/JVerificationConstant.java @@ -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"; +} diff --git a/android/src/main/java/cn/jpush/reactnativejvrification/JVerificationModule.java b/android/src/main/java/cn/jpush/reactnativejvrification/JVerificationModule.java index e84f91a..debcf1e 100644 --- a/android/src/main/java/cn/jpush/reactnativejvrification/JVerificationModule.java +++ b/android/src/main/java/cn/jpush/reactnativejvrification/JVerificationModule.java @@ -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; @@ -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; @@ -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; @@ -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 @@ -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); } } diff --git a/example/App.js b/example/App.js index c5cedc8..6b89e7e 100644 --- a/example/App.js +++ b/example/App.js @@ -3,15 +3,16 @@ import { StyleSheet, Text, View, TouchableHighlight, ScrollView, TextInput, Aler import JVerification from 'jverification-react-native' var styles = StyleSheet.create({ - parent: { - padding: 35, - - flexDirection: 'column', + container: { + flex: 1, justifyContent: 'center', alignItems: 'center', + backgroundColor: '#F5FCFF', }, setBtnStyle: { - width: 180, + width: 280, + justifyContent: 'center', + alignItems: 'center', marginTop: 10, borderWidth: 1, borderColor: '#3e83d7', @@ -51,7 +52,44 @@ class Button extends React.Component { } } -// type Props = {}; +//一键登录页面自定义配置,需要在调用login之前设置 +var config = { + navColor:-16742704, //导航栏颜色 + navText: "一键登录", //导航栏标题 + navTextColor:-1, //导航栏标题文字颜色 + navReturnImage:"自定义返回按钮图片", //导航栏左侧返回按钮 + + logoHidden:false, //logo是否隐藏 + logoImage:"umcsdk_mobile_logo", //logo(android默认为应用图标;ios默认无) + logoWidth:100, //logo宽 + logoHeight:100, //logo高 + logoOffsetY:75, //logo相对导航栏向下偏移量 + + numberColor:-16742704, //手机号码文字颜色 + numOffsetY:200, //手机号码相对导航栏向下偏移量 + + sloganTextColor:-16742704, //slogan文字颜色 + sloganOffsetY:250, //slogan相对导航栏向下偏移量 + + loginBtnText:"本机号码登录", //登录按钮文字 + loginBtnTextColor:-1, //登录按钮文字颜色 + loginBtnImageStyle:"自定义登录按钮样式", //登录按钮selector选择样式 (仅android) + loginBtnNormalImage:"自定义登录按钮正常图片", //登录按钮正常图片 (仅ios,三个同时设置生效) + loginBtnUnableImage:"自定义登录按钮失效图片", //登录按钮失效图片 (仅ios,三个同时设置生效) + loginBtnPressedImage:"自定义登录按钮按下图片", //登录按钮按下图片 (仅ios,三个同时设置生效) + + loginBtnOffsetY:280, //登录按钮相对导航栏向下偏移量 + + privacyOneName:"自定义隐私条款一", //隐私条款一 + privacyOneUrl:"https://www.jiguang.cn", //隐私条款一链接 + privacyTwoName:"自定义隐私条款二", //隐私条款二 + privacyTwoUrl:"https://www.jiguang.cn", //隐私条款二链接 + privacyBasicColor:-16742704, //隐私条款基础文字颜色 + privacyProtocolColor:-16777216, //隐私条款文字颜色 + privacyCheckImage:"自定义选择图片", //隐私条款复选框选中图片 + privacyUncheckImage:"自定义未选择图片", //隐私条款复选框未选中图片 + privacyOffsetY:20 //隐私条款相对底部向上偏移量 +} export default class App extends React.Component { constructor(props){ @@ -63,18 +101,23 @@ export default class App extends React.Component { return (