@pyrocancode/react-native-vk-auth 0.4.1 → 1.0.0
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 +7 -11
- package/android/src/main/java/com/vkauth/VkAuthModule.kt +18 -16
- package/android/src/main/java/com/vkauth/VkAuthPackage.kt +10 -5
- package/android/src/main/java/com/vkauth/vkid/AuthDelegate.kt +92 -84
- package/android/src/main/java/com/vkauth/vkid/InitDelegate.kt +8 -2
- package/android/src/main/java/com/vkauth/vkid/VkAuthPayload.kt +61 -0
- package/android/src/main/java/com/vkauth/vkid/VkAuthServiceHolder.kt +8 -0
- package/android/src/main/java/com/vkauth/vkid/onetapbutton/OneTapButtonManager.kt +32 -129
- package/ios/Event.swift +3 -19
- package/ios/RCTDomain.swift +17 -13
- package/ios/VkAuth.swift +113 -97
- package/package.json +2 -2
- package/react-native-vk-auth.podspec +17 -10
- package/src/index.tsx +99 -77
- package/android/src/main/java/com/vkauth/vkid/JSSilentTokenExchanger.kt +0 -33
- package/android/src/main/java/com/vkauth/vkid/SuperAppKitInitUtils.kt +0 -75
- package/android/src/main/java/com/vkauth/vkid/dto/AcessToken.kt +0 -19
- package/android/src/main/java/com/vkauth/vkid/dto/DtoExt.kt +0 -24
- package/android/src/main/java/com/vkauth/vkid/dto/SilentAuthInfo.kt +0 -22
- package/android/src/main/java/com/vkauth/vkid/dto/Token.kt +0 -15
- package/android/src/main/java/com/vkauth/vkid/dto/UserSession.kt +0 -28
- package/android/src/main/java/com/vkauth/vkid/jstutils/JsCbSender.kt +0 -16
- package/android/src/main/java/com/vkauth/vkid/jstutils/JsOutputParam.kt +0 -7
package/android/build.gradle
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
-
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
2
|
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['VkAuth_kotlinVersion']
|
|
4
3
|
|
|
5
4
|
repositories {
|
|
@@ -9,7 +8,6 @@ buildscript {
|
|
|
9
8
|
|
|
10
9
|
dependencies {
|
|
11
10
|
classpath 'com.android.tools.build:gradle:3.5.3'
|
|
12
|
-
// noinspection DifferentKotlinGradleVersion
|
|
13
11
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
12
|
}
|
|
15
13
|
}
|
|
@@ -33,6 +31,7 @@ def getExtOrIntegerDefault(name) {
|
|
|
33
31
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['VkAuth_' + name]).toInteger()
|
|
34
32
|
}
|
|
35
33
|
|
|
34
|
+
def vkidVersion = "2.6.2"
|
|
36
35
|
|
|
37
36
|
android {
|
|
38
37
|
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
|
@@ -62,9 +61,9 @@ android {
|
|
|
62
61
|
repositories {
|
|
63
62
|
mavenCentral()
|
|
64
63
|
google()
|
|
65
|
-
maven {
|
|
66
|
-
|
|
67
|
-
}
|
|
64
|
+
maven { url = "https://artifactory-external.vkpartner.ru/artifactory/vkid-sdk-android/" }
|
|
65
|
+
maven { url = "https://artifactory-external.vkpartner.ru/artifactory/maven/" }
|
|
66
|
+
maven { url = "https://artifactory-external.vkpartner.ru/artifactory/vk-id-captcha/android/" }
|
|
68
67
|
|
|
69
68
|
def found = false
|
|
70
69
|
def defaultDir = null
|
|
@@ -133,17 +132,14 @@ repositories {
|
|
|
133
132
|
}
|
|
134
133
|
|
|
135
134
|
def kotlin_version = getExtOrDefault('kotlinVersion')
|
|
136
|
-
def vkSdkVersion = "0.104-24412"
|
|
137
135
|
|
|
138
136
|
dependencies {
|
|
139
|
-
//noinspection GradleDynamicVersion
|
|
140
137
|
implementation "com.facebook.react:react-native:+"
|
|
141
|
-
implementation "com.vk:
|
|
142
|
-
implementation "com.vk:
|
|
138
|
+
implementation "com.vk.id:vkid:${vkidVersion}"
|
|
139
|
+
implementation "com.vk.id:onetap-xml:${vkidVersion}"
|
|
143
140
|
implementation "androidx.appcompat:appcompat:1.6.1"
|
|
144
|
-
|
|
141
|
+
implementation "androidx.fragment:fragment-ktx:1.6.2"
|
|
145
142
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
146
|
-
// From node_modules
|
|
147
143
|
}
|
|
148
144
|
|
|
149
145
|
if (isNewArchitectureEnabled()) {
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
package com.vkauth
|
|
2
2
|
|
|
3
|
-
import com.facebook.react.bridge
|
|
3
|
+
import com.facebook.react.bridge.Promise
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
4
8
|
import com.vkauth.vkid.AuthDelegate
|
|
5
9
|
import com.vkauth.vkid.InitDelegate
|
|
6
10
|
import com.vkauth.vkid.jsinput.App
|
|
7
|
-
import com.vkauth.vkid.jsinput.VKID
|
|
11
|
+
import com.vkauth.vkid.jsinput.VKID as VkIdInput
|
|
8
12
|
|
|
9
13
|
class VkAuthModule(
|
|
10
14
|
reactContext: ReactApplicationContext,
|
|
11
15
|
private val initDelegate: InitDelegate,
|
|
12
|
-
private val authDelegate: AuthDelegate
|
|
13
|
-
) :
|
|
14
|
-
ReactContextBaseJavaModule(reactContext) {
|
|
16
|
+
private val authDelegate: AuthDelegate,
|
|
17
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
15
18
|
|
|
16
|
-
override fun getName(): String
|
|
17
|
-
return "VkAuth"
|
|
18
|
-
}
|
|
19
|
+
override fun getName(): String = "VkAuth"
|
|
19
20
|
|
|
20
21
|
@ReactMethod
|
|
21
22
|
fun initialize(app: ReadableMap, vkid: ReadableMap) {
|
|
22
|
-
initDelegate.initialize(App.fromMap(app),
|
|
23
|
+
initDelegate.initialize(App.fromMap(app), VkIdInput.fromMap(vkid))
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
@ReactMethod
|
|
@@ -32,17 +33,18 @@ class VkAuthModule(
|
|
|
32
33
|
authDelegate.closeAuth()
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
// to ignore react warning
|
|
36
36
|
@ReactMethod
|
|
37
|
-
fun addListener(eventName: String) {
|
|
38
|
-
}
|
|
37
|
+
fun addListener(@Suppress("UNUSED_PARAMETER") eventName: String) {}
|
|
39
38
|
|
|
40
39
|
@ReactMethod
|
|
41
|
-
fun removeAllListeners() {
|
|
42
|
-
|
|
40
|
+
fun removeAllListeners() {}
|
|
41
|
+
|
|
42
|
+
@ReactMethod
|
|
43
|
+
fun removeListeners(@Suppress("UNUSED_PARAMETER") type: Int?) {}
|
|
43
44
|
|
|
44
45
|
@ReactMethod
|
|
45
|
-
fun
|
|
46
|
+
fun openURL(@Suppress("UNUSED_PARAMETER") url: String) {
|
|
47
|
+
// Редирект обрабатывает VK ID SDK / система; при необходимости дополните.
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
@ReactMethod
|
|
@@ -51,7 +53,7 @@ class VkAuthModule(
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
@ReactMethod
|
|
54
|
-
fun accessTokenChangedFailed(error: ReadableMap) {
|
|
56
|
+
fun accessTokenChangedFailed(@Suppress("UNUSED_PARAMETER") error: ReadableMap) {
|
|
55
57
|
authDelegate.accessTokenChangedFailed()
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -6,15 +6,20 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
6
6
|
import com.facebook.react.uimanager.ViewManager
|
|
7
7
|
import com.vkauth.vkid.AuthDelegate
|
|
8
8
|
import com.vkauth.vkid.InitDelegate
|
|
9
|
+
import com.vkauth.vkid.VkAuthServiceHolder
|
|
9
10
|
import com.vkauth.vkid.onetapbutton.OneTabButtonManager
|
|
10
11
|
|
|
11
|
-
|
|
12
12
|
class VkAuthPackage : ReactPackage {
|
|
13
13
|
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
val authDelegate = AuthDelegate(reactContext)
|
|
15
|
+
VkAuthServiceHolder.authDelegate = authDelegate
|
|
16
|
+
return listOf(
|
|
17
|
+
VkAuthModule(
|
|
18
|
+
reactContext,
|
|
19
|
+
InitDelegate(reactContext),
|
|
20
|
+
authDelegate,
|
|
21
|
+
),
|
|
22
|
+
)
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
@@ -5,119 +5,127 @@ import androidx.fragment.app.FragmentActivity
|
|
|
5
5
|
import com.facebook.react.bridge.Arguments
|
|
6
6
|
import com.facebook.react.bridge.Promise
|
|
7
7
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
-
import com.
|
|
9
|
-
import com.
|
|
10
|
-
import com.vk.
|
|
11
|
-
import com.vk.
|
|
12
|
-
import com.vk.auth.
|
|
13
|
-
import com.vk.auth.
|
|
14
|
-
import com.vk.auth.
|
|
15
|
-
import com.vk.
|
|
16
|
-
import com.vk.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
private val context: ReactApplicationContext
|
|
24
|
-
) {
|
|
25
|
-
private val jsCallbackSender = JsCbSender()
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
import com.vk.id.VKID
|
|
11
|
+
import com.vk.id.VKIDAuthFail
|
|
12
|
+
import com.vk.id.auth.AuthCodeData
|
|
13
|
+
import com.vk.id.auth.VKIDAuthCallback
|
|
14
|
+
import com.vk.id.auth.VKIDAuthParams
|
|
15
|
+
import com.vk.id.logout.VKIDLogoutCallback
|
|
16
|
+
import com.vk.id.logout.VKIDLogoutFail
|
|
17
|
+
|
|
18
|
+
class AuthDelegate(private val reactContext: ReactApplicationContext) {
|
|
19
|
+
|
|
20
|
+
companion object {
|
|
21
|
+
private const val TAG = "VkAuth"
|
|
22
|
+
}
|
|
26
23
|
|
|
27
24
|
init {
|
|
28
|
-
|
|
29
|
-
override fun onLogout(logoutReason: LogoutReason) {
|
|
30
|
-
super.onLogout(logoutReason)
|
|
31
|
-
jsCallbackSender.sendCallback(context, ON_LOGOUT_EVENT, null)
|
|
32
|
-
}
|
|
33
|
-
})
|
|
25
|
+
VKID.logsEnabled = true
|
|
34
26
|
}
|
|
35
27
|
|
|
36
28
|
fun startAuth() {
|
|
37
|
-
val activity =
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
val activity = reactContext.currentActivity as? FragmentActivity
|
|
30
|
+
if (activity == null) {
|
|
31
|
+
Log.e(TAG, "startAuth: no FragmentActivity")
|
|
32
|
+
emitAuthFail("No activity")
|
|
40
33
|
return
|
|
41
34
|
}
|
|
35
|
+
VKID.instance.authorize(
|
|
36
|
+
activity,
|
|
37
|
+
object : VKIDAuthCallback {
|
|
38
|
+
override fun onAuth(accessToken: com.vk.id.AccessToken) {
|
|
39
|
+
Log.d(
|
|
40
|
+
TAG,
|
|
41
|
+
"VKID onAuth: userID=${accessToken.userID} expire=${accessToken.expireTime}",
|
|
42
|
+
)
|
|
43
|
+
emitAuthSuccess(accessToken)
|
|
44
|
+
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
override fun onAuthCode(data: AuthCodeData, isCompletion: Boolean) {
|
|
47
|
+
Log.d(TAG, "VKID onAuthCode: isCompletion=$isCompletion code=${data.code} deviceId=${data.deviceId}")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun onFail(fail: VKIDAuthFail) {
|
|
51
|
+
Log.e(TAG, "VKID onFail: $fail")
|
|
52
|
+
emitAuthFail(fail.toString())
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
VKIDAuthParams.Builder().build(),
|
|
56
|
+
)
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
fun closeAuth() {
|
|
49
|
-
|
|
50
|
-
(activity.supportFragmentManager.findFragmentByTag(FAST_LOGIN_TAG) as? BottomSheetDialogFragment)
|
|
51
|
-
?.dismissAllowingStateLoss()
|
|
52
|
-
?: run {
|
|
53
|
-
(activity.supportFragmentManager
|
|
54
|
-
.fragments
|
|
55
|
-
.find { it is VkFastLoginBottomSheetFragment } as? BottomSheetDialogFragment)
|
|
56
|
-
?.dismissAllowingStateLoss()
|
|
57
|
-
}
|
|
60
|
+
// VK ID SDK не требует явного закрытия веб-view из нативного модуля.
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
fun
|
|
61
|
-
val
|
|
62
|
-
|
|
63
|
+
fun logout() {
|
|
64
|
+
val activity = reactContext.currentActivity as? FragmentActivity
|
|
65
|
+
if (activity == null) {
|
|
66
|
+
Log.e(TAG, "logout: no FragmentActivity")
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
VKID.instance.logout(
|
|
70
|
+
object : VKIDLogoutCallback {
|
|
71
|
+
override fun onSuccess() {
|
|
72
|
+
Log.d(TAG, "VKID logout success")
|
|
73
|
+
sendEvent("onLogout", null)
|
|
74
|
+
}
|
|
63
75
|
|
|
64
|
-
|
|
76
|
+
override fun onFail(fail: VKIDLogoutFail) {
|
|
77
|
+
Log.e(TAG, "VKID logout fail: $fail")
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
activity,
|
|
81
|
+
)
|
|
65
82
|
}
|
|
66
83
|
|
|
67
|
-
fun
|
|
68
|
-
|
|
84
|
+
fun accessTokenChangedSuccess(token: String, userId: Int) {
|
|
85
|
+
// Старый поток silent token; оставлено для совместимости с JS до миграции приложения.
|
|
86
|
+
Log.d(TAG, "accessTokenChangedSuccess (legacy): userId=$userId")
|
|
69
87
|
}
|
|
70
88
|
|
|
71
|
-
fun
|
|
72
|
-
|
|
89
|
+
fun accessTokenChangedFailed() {
|
|
90
|
+
Log.d(TAG, "accessTokenChangedFailed (legacy)")
|
|
73
91
|
}
|
|
74
92
|
|
|
75
93
|
fun getUserSessions(promise: Promise) {
|
|
76
|
-
val
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
val token = VKID.instance.accessToken
|
|
95
|
+
val arr = com.facebook.react.bridge.Arguments.createArray()
|
|
96
|
+
if (token != null) {
|
|
97
|
+
val m = com.facebook.react.bridge.Arguments.createMap()
|
|
98
|
+
m.putString("type", "authorized")
|
|
99
|
+
arr.pushMap(m)
|
|
79
100
|
}
|
|
80
|
-
|
|
81
|
-
val array = Arguments.createArray().apply {
|
|
82
|
-
pushMap(UserSession.Authorized.toMap())
|
|
83
|
-
}
|
|
84
|
-
promise.resolve(array)
|
|
101
|
+
promise.resolve(arr)
|
|
85
102
|
}
|
|
86
103
|
|
|
87
|
-
|
|
88
|
-
val
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (byTag) {
|
|
93
|
-
return true
|
|
104
|
+
fun getUserProfile(promise: Promise) {
|
|
105
|
+
val token = VKID.instance.accessToken
|
|
106
|
+
if (token == null) {
|
|
107
|
+
promise.reject("E_VK_NOT_AUTHORIZED", "No VK ID access token")
|
|
108
|
+
return
|
|
94
109
|
}
|
|
110
|
+
promise.resolve(VkAuthPayload.profileForJs(token.userID, token.userData))
|
|
111
|
+
}
|
|
95
112
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
113
|
+
fun emitAuthSuccess(accessToken: com.vk.id.AccessToken) {
|
|
114
|
+
val map = VkAuthPayload.fromAccessToken(accessToken)
|
|
115
|
+
map.putMap("profile", VkAuthPayload.profileForJs(accessToken.userID, accessToken.userData))
|
|
116
|
+
sendEvent("onAuth", map)
|
|
99
117
|
}
|
|
100
118
|
|
|
101
|
-
fun
|
|
102
|
-
val
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
promise.reject(error)
|
|
107
|
-
}
|
|
108
|
-
override fun success(result: ProfileShortInfo) {
|
|
109
|
-
promise.resolve(result.toMap())
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
)
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
promise.resolve(profile)
|
|
119
|
+
fun emitAuthFail(message: String) {
|
|
120
|
+
val map = Arguments.createMap()
|
|
121
|
+
map.putString("type", "error")
|
|
122
|
+
map.putString("error", message)
|
|
123
|
+
sendEvent("onAuth", map)
|
|
116
124
|
}
|
|
117
125
|
|
|
118
|
-
private
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
private fun sendEvent(eventName: String, params: WritableMap?) {
|
|
127
|
+
reactContext
|
|
128
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
129
|
+
.emit(eventName, params)
|
|
122
130
|
}
|
|
123
131
|
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
package com.vkauth.vkid
|
|
2
2
|
|
|
3
|
+
import android.util.Log
|
|
3
4
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
5
|
import com.vkauth.vkid.jsinput.App
|
|
5
6
|
import com.vkauth.vkid.jsinput.VKID
|
|
6
7
|
|
|
7
8
|
class InitDelegate(
|
|
8
|
-
private val context: ReactApplicationContext
|
|
9
|
+
@Suppress("unused") private val context: ReactApplicationContext,
|
|
9
10
|
) {
|
|
10
11
|
fun initialize(app: App, vkid: VKID) {
|
|
11
|
-
|
|
12
|
+
// Конфигурация клиента — через manifest placeholders (VKIDClientID и т.д.) и VKID.init в Application.
|
|
13
|
+
Log.d(TAG, "initialize mode=${app.mode} appName=${vkid.appName}")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private companion object {
|
|
17
|
+
private const val TAG = "VkAuth"
|
|
12
18
|
}
|
|
13
19
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package com.vkauth.vkid
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.vk.id.AccessToken
|
|
6
|
+
import com.vk.id.VKIDUser
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Сериализация ответа VK ID SDK в WritableMap для JS (событие onAuth и отладка).
|
|
10
|
+
* Документация: https://vkcom.github.io/vkid-android-sdk/
|
|
11
|
+
*/
|
|
12
|
+
internal object VkAuthPayload {
|
|
13
|
+
|
|
14
|
+
fun fromAccessToken(token: AccessToken): WritableMap {
|
|
15
|
+
val map = Arguments.createMap()
|
|
16
|
+
map.putString("type", "authorized")
|
|
17
|
+
map.putMap("vkid", buildVkidDebugMap(token))
|
|
18
|
+
return map
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fun buildVkidDebugMap(token: AccessToken): WritableMap {
|
|
22
|
+
val vkid = Arguments.createMap()
|
|
23
|
+
vkid.putString("accessToken", token.token)
|
|
24
|
+
vkid.putDouble("userID", token.userID.toDouble())
|
|
25
|
+
vkid.putDouble("expireTime", token.expireTime.toDouble())
|
|
26
|
+
token.idToken?.let { vkid.putString("idToken", it) }
|
|
27
|
+
token.scopes?.let { scopes ->
|
|
28
|
+
val arr = Arguments.createArray()
|
|
29
|
+
scopes.forEach { arr.pushString(it) }
|
|
30
|
+
vkid.putArray("scopes", arr)
|
|
31
|
+
}
|
|
32
|
+
vkid.putMap("userData", fromVKIDUser(token.userData))
|
|
33
|
+
return vkid
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fun fromVKIDUser(user: VKIDUser): WritableMap {
|
|
37
|
+
val m = Arguments.createMap()
|
|
38
|
+
m.putString("firstName", user.firstName)
|
|
39
|
+
m.putString("lastName", user.lastName)
|
|
40
|
+
user.phone?.let { m.putString("phone", it) }
|
|
41
|
+
user.email?.let { m.putString("email", it) }
|
|
42
|
+
user.photo50?.let { m.putString("photo50", it) }
|
|
43
|
+
user.photo100?.let { m.putString("photo100", it) }
|
|
44
|
+
user.photo200?.let { m.putString("photo200", it) }
|
|
45
|
+
return m
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fun profileForJs(userId: Long, user: VKIDUser): WritableMap {
|
|
49
|
+
val m = Arguments.createMap()
|
|
50
|
+
val userIdMap = Arguments.createMap()
|
|
51
|
+
userIdMap.putString("value", userId.toString())
|
|
52
|
+
m.putMap("userID", userIdMap)
|
|
53
|
+
m.putString("firstName", user.firstName)
|
|
54
|
+
m.putString("lastName", user.lastName)
|
|
55
|
+
m.putString("phone", user.phone)
|
|
56
|
+
m.putString("photo200", user.photo200)
|
|
57
|
+
m.putString("email", user.email)
|
|
58
|
+
m.putNull("userHash")
|
|
59
|
+
return m
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,166 +1,69 @@
|
|
|
1
1
|
package com.vkauth.vkid.onetapbutton
|
|
2
2
|
|
|
3
|
-
import android.
|
|
4
|
-
import android.graphics.Color
|
|
3
|
+
import android.util.Log
|
|
5
4
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
5
|
import com.facebook.react.bridge.ReadableMap
|
|
7
|
-
import com.facebook.react.uimanager.LayoutShadowNode
|
|
8
6
|
import com.facebook.react.uimanager.SimpleViewManager
|
|
9
7
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
10
8
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
11
|
-
import com.
|
|
12
|
-
import com.
|
|
9
|
+
import com.vk.id.onetap.xml.OneTap
|
|
10
|
+
import com.vkauth.vkid.VkAuthServiceHolder
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/**
|
|
13
|
+
* VK ID One Tap (XML). См. [OneTap.setCallbacks](https://vkcom.github.io/vkid-android-sdk/onetap-xml/com.vk.id.onetap.xml/-one-tap/set-callbacks.html).
|
|
14
|
+
*/
|
|
15
|
+
class OneTabButtonManager : SimpleViewManager<OneTap>() {
|
|
16
16
|
|
|
17
|
-
override fun
|
|
18
|
-
return ReactTextShadowNode()
|
|
19
|
-
}
|
|
17
|
+
override fun getName(): String = COMPONENT_NAME
|
|
20
18
|
|
|
21
|
-
override fun createViewInstance(context: ThemedReactContext):
|
|
22
|
-
|
|
19
|
+
override fun createViewInstance(context: ThemedReactContext): OneTap {
|
|
20
|
+
val view = OneTap(context)
|
|
21
|
+
view.setCallbacks(
|
|
22
|
+
onAuth = { _, accessToken ->
|
|
23
|
+
VkAuthServiceHolder.authDelegate?.emitAuthSuccess(accessToken)
|
|
24
|
+
},
|
|
25
|
+
onFail = { _, fail ->
|
|
26
|
+
Log.e(TAG, "OneTap onFail: $fail")
|
|
27
|
+
VkAuthServiceHolder.authDelegate?.emitAuthFail(fail.toString())
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
return view
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
@ReactProp(name = "backgroundStyle")
|
|
26
|
-
fun
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
val vkStyle = when (style.getString("style")) {
|
|
30
|
-
"BLUE" -> VkFastLoginButton.ButtonStyle.BLUE
|
|
31
|
-
"WHITE" -> VkFastLoginButton.ButtonStyle.WHITE
|
|
32
|
-
"CUSTOM" -> VkFastLoginButton.ButtonStyle.CUSTOM
|
|
33
|
-
else -> null
|
|
34
|
-
} ?: return
|
|
35
|
-
|
|
36
|
-
if (vkStyle == VkFastLoginButton.ButtonStyle.CUSTOM) {
|
|
37
|
-
val vkIconColor = when (style.getString("customVkIconColor")) {
|
|
38
|
-
"BLUE" -> VkFastLoginButton.VkIconColor.BLUE
|
|
39
|
-
"WHITE" -> VkFastLoginButton.VkIconColor.WHITE
|
|
40
|
-
else -> null
|
|
41
|
-
} ?: return
|
|
42
|
-
|
|
43
|
-
view.setCustomStyle(
|
|
44
|
-
bgColor = Color.parseColor(style.getString("customBackgroundColor")),
|
|
45
|
-
textColor = Color.parseColor(style.getString("customTextColor")),
|
|
46
|
-
vkIconColor = vkIconColor
|
|
47
|
-
)
|
|
48
|
-
} else {
|
|
49
|
-
view.setButtonStyle(vkStyle)
|
|
50
|
-
}
|
|
51
|
-
|
|
34
|
+
fun setBackgroundStyle(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") style: ReadableMap) {
|
|
35
|
+
// Стили One Tap задаются через [OneTap.style]; при необходимости сопоставьте с [com.vk.id.onetap.common.OneTapStyle].
|
|
52
36
|
}
|
|
53
37
|
|
|
54
38
|
@ReactProp(name = "iconGravity")
|
|
55
|
-
fun
|
|
56
|
-
android.util.Log.d(TAG, "setGravity($gravity)")
|
|
57
|
-
|
|
58
|
-
val vkGravity = when (gravity) {
|
|
59
|
-
"START" -> VkFastLoginButton.VkIconGravity.START
|
|
60
|
-
"TEXT" -> VkFastLoginButton.VkIconGravity.TEXT
|
|
61
|
-
else -> null
|
|
62
|
-
} ?: return
|
|
63
|
-
|
|
64
|
-
view.setVkIconGravity(vkGravity)
|
|
65
|
-
}
|
|
39
|
+
fun setIconGravity(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") gravity: String) {}
|
|
66
40
|
|
|
67
41
|
@ReactProp(name = "firstLineFieldType")
|
|
68
|
-
fun setFirstLineField(view:
|
|
69
|
-
android.util.Log.d(TAG, "setFirstLineField($type)")
|
|
70
|
-
|
|
71
|
-
val vkType = when (type) {
|
|
72
|
-
"ACTION" -> VkFastLoginButton.LineFieldType.ACTION
|
|
73
|
-
"PHONE" -> VkFastLoginButton.LineFieldType.PHONE
|
|
74
|
-
"NONE" -> VkFastLoginButton.LineFieldType.NONE
|
|
75
|
-
else -> null
|
|
76
|
-
} ?: return
|
|
77
|
-
|
|
78
|
-
view.setFirstLineField(vkType)
|
|
79
|
-
}
|
|
42
|
+
fun setFirstLineField(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") type: String) {}
|
|
80
43
|
|
|
81
44
|
@ReactProp(name = "secondLineFieldType")
|
|
82
|
-
fun setSecondLineField(view:
|
|
83
|
-
android.util.Log.d(TAG, "setSecondLineField($type)")
|
|
84
|
-
val vkType = when (type) {
|
|
85
|
-
"ACTION" -> VkFastLoginButton.LineFieldType.ACTION
|
|
86
|
-
"PHONE" -> VkFastLoginButton.LineFieldType.PHONE
|
|
87
|
-
"NONE" -> VkFastLoginButton.LineFieldType.NONE
|
|
88
|
-
else -> null
|
|
89
|
-
} ?: return
|
|
90
|
-
|
|
91
|
-
view.setSecondLineField(vkType)
|
|
92
|
-
}
|
|
45
|
+
fun setSecondLineField(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") type: String) {}
|
|
93
46
|
|
|
94
47
|
@ReactProp(name = "oneLineTextSize")
|
|
95
|
-
fun setOneLineTextSize(view:
|
|
96
|
-
android.util.Log.d(TAG, "setOneLineTextSize($size)")
|
|
97
|
-
view.setOneLineTextSize(size)
|
|
98
|
-
}
|
|
48
|
+
fun setOneLineTextSize(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") size: Float) {}
|
|
99
49
|
|
|
100
50
|
@ReactProp(name = "firstLineTextSize")
|
|
101
|
-
fun setFirstLineTextSize(view:
|
|
102
|
-
android.util.Log.d(TAG, "setFirstLineTextSize($size)")
|
|
103
|
-
view.setFirstLineTextSize(size)
|
|
104
|
-
}
|
|
51
|
+
fun setFirstLineTextSize(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") size: Float) {}
|
|
105
52
|
|
|
106
53
|
@ReactProp(name = "secondLineTextSize")
|
|
107
|
-
fun setSecondLineTextSize(view:
|
|
108
|
-
android.util.Log.d(TAG, "setSecondLineTextSize($size)")
|
|
109
|
-
view.setSecondLineTextSize(size)
|
|
110
|
-
}
|
|
54
|
+
fun setSecondLineTextSize(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") size: Float) {}
|
|
111
55
|
|
|
112
56
|
@ReactProp(name = "avatarSize")
|
|
113
|
-
fun setAvatarSize(view:
|
|
114
|
-
android.util.Log.d(TAG, "setAvatarSize($size)")
|
|
115
|
-
|
|
116
|
-
view.setAvatarSize(size.toInt())
|
|
117
|
-
}
|
|
57
|
+
fun setAvatarSize(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") size: Float) {}
|
|
118
58
|
|
|
119
59
|
@ReactProp(name = "iconSize")
|
|
120
|
-
fun setVkIconSize(view:
|
|
121
|
-
android.util.Log.d(TAG, "setVkIconSize($size)")
|
|
122
|
-
view.setVkIconSize(size.toInt())
|
|
123
|
-
}
|
|
60
|
+
fun setVkIconSize(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") size: Float) {}
|
|
124
61
|
|
|
125
62
|
@ReactProp(name = "progressSize")
|
|
126
|
-
fun setProgressSize(view:
|
|
127
|
-
android.util.Log.d(TAG, "setProgressSize($size)")
|
|
128
|
-
view.setProgressSize(size.toInt())
|
|
129
|
-
}
|
|
63
|
+
fun setProgressSize(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") size: Float) {}
|
|
130
64
|
|
|
131
65
|
@ReactProp(name = "texts")
|
|
132
|
-
fun setTexts(view:
|
|
133
|
-
android.util.Log.d(TAG, "setTexts($texts)")
|
|
134
|
-
|
|
135
|
-
view.setTextGetter(
|
|
136
|
-
object : VkFastLoginButton.TextGetter() {
|
|
137
|
-
override fun getNoUserText(
|
|
138
|
-
context: Context,
|
|
139
|
-
actionTextSize: VkFastLoginButton.ActionTextSize
|
|
140
|
-
): String {
|
|
141
|
-
return texts.getString("noUserText") ?: super.getNoUserText(context, VkFastLoginButton.ActionTextSize.BIG)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
override fun getActionText(
|
|
145
|
-
context: Context,
|
|
146
|
-
firstName: String,
|
|
147
|
-
lastName: String,
|
|
148
|
-
actionTextSize: VkFastLoginButton.ActionTextSize
|
|
149
|
-
): String {
|
|
150
|
-
val text = texts.getString("actionText")
|
|
151
|
-
?.replace("{firstName}", firstName)
|
|
152
|
-
?.replace("{lastName}", lastName)
|
|
153
|
-
return text ?: super.getActionText(context, firstName, lastName, VkFastLoginButton.ActionTextSize.BIG)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
override fun getPhoneText(context: Context, phone: String): String {
|
|
157
|
-
val text = texts.getString("phoneText")
|
|
158
|
-
?.replace("{phone}", phone)
|
|
159
|
-
return text ?: super.getPhoneText(context, phone)
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
)
|
|
163
|
-
}
|
|
66
|
+
fun setTexts(@Suppress("UNUSED_PARAMETER") view: OneTap, @Suppress("UNUSED_PARAMETER") texts: ReadableMap) {}
|
|
164
67
|
|
|
165
68
|
private companion object {
|
|
166
69
|
private const val COMPONENT_NAME = "RTCVkOneTapButton"
|