expo-modules-core 1.5.5 → 1.5.7
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/CHANGELOG.md +14 -0
- package/android/build.gradle +2 -2
- package/android/src/main/AndroidManifest.xml +6 -1
- package/android/src/main/java/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +8 -8
- package/android/src/main/java/expo/modules/kotlin/devtools/ExpoRequestCdpInterceptor.kt +6 -7
- package/android/src/main/java/expo/modules/kotlin/devtools/cdp/CdpNetworkTypes.kt +2 -4
- package/android/src/main/java/expo/modules/kotlin/functions/AnyFunction.kt +16 -5
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +8 -8
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +2 -2
- package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +23 -23
- package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponentBuilder.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +2 -1
- package/android/src/main/java/expo/modules/kotlin/types/AnyType.kt +50 -2
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +54 -45
- package/android/src/main/java/expo/modules/kotlin/views/GroupViewManagerWrapper.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/views/SimpleViewManagerWrapper.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +17 -17
- package/ios/Swift/DevTools/CdpNetworkTypes.swift +8 -8
- package/ios/Swift/DevTools/ExpoRequestCdpInterceptor.swift +23 -11
- package/ios/Swift/DevTools/ExpoRequestInterceptorProtocol.swift +26 -39
- package/ios/Tests/ExpoRequestCdpInterceptorSpec.swift +35 -10
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,20 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 1.5.7 — 2023-07-12
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Fixed regressions and crashes in the dev client introduced by [#23405](https://github.com/expo/expo/pull/23405). ([#23491](https://github.com/expo/expo/pull/23491) by [@kudo](https://github.com/kudo))
|
|
18
|
+
|
|
19
|
+
## 1.5.6 — 2023-07-10
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug fixes
|
|
22
|
+
|
|
23
|
+
- Fixed the Network Inspector cannot preview response body for response without the `Content-Length` header. ([#23405](https://github.com/expo/expo/pull/23405) by [@kudo](https://github.com/kudo))
|
|
24
|
+
- Fixed `SoLoader` does not work on Android. ([#23415](https://github.com/expo/expo/pull/23415) by [@kudo](https://github.com/kudo))
|
|
25
|
+
- Fixed slower boot time on Android. ([#23345](https://github.com/expo/expo/pull/23345) by [@lukmccall](https://github.com/lukmccall))
|
|
26
|
+
|
|
13
27
|
## 1.5.5 — 2023-07-07
|
|
14
28
|
|
|
15
29
|
### 🐛 Bug fixes
|
package/android/build.gradle
CHANGED
|
@@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
|
|
|
6
6
|
apply plugin: "de.undercouch.download"
|
|
7
7
|
|
|
8
8
|
group = 'host.exp.exponent'
|
|
9
|
-
version = '1.5.
|
|
9
|
+
version = '1.5.7'
|
|
10
10
|
|
|
11
11
|
buildscript {
|
|
12
12
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -160,7 +160,7 @@ android {
|
|
|
160
160
|
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
161
161
|
consumerProguardFiles 'proguard-rules.pro'
|
|
162
162
|
versionCode 1
|
|
163
|
-
versionName "1.5.
|
|
163
|
+
versionName "1.5.7"
|
|
164
164
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled.toString()
|
|
165
165
|
|
|
166
166
|
testInstrumentationRunner "expo.modules.TestRunner"
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
xmlns:tools="http://schemas.android.com/tools">
|
|
2
3
|
|
|
3
4
|
<application>
|
|
4
5
|
<meta-data
|
|
5
6
|
android:name="org.unimodules.core.AppLoader#react-native-headless"
|
|
6
7
|
android:value="expo.modules.adapters.react.apploader.RNHeadlessAppLoader" />
|
|
8
|
+
<meta-data
|
|
9
|
+
android:name="com.facebook.soloader.enabled"
|
|
10
|
+
android:value="true"
|
|
11
|
+
tools:replace="android:value" />
|
|
7
12
|
</application>
|
|
8
13
|
|
|
9
14
|
</manifest>
|
|
@@ -49,7 +49,7 @@ class ClassComponentBuilder<SharedObjectType : Any>(
|
|
|
49
49
|
inline fun <reified P0> Constructor(
|
|
50
50
|
crossinline body: (p0: P0) -> SharedObjectType
|
|
51
51
|
): SyncFunctionComponent {
|
|
52
|
-
return SyncFunctionComponent("constructor", arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }.also {
|
|
52
|
+
return SyncFunctionComponent("constructor", arrayOf({ typeOf<P0>() }.toAnyType<P0>())) { body(it[0] as P0) }.also {
|
|
53
53
|
constructor = it
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -57,7 +57,7 @@ class ClassComponentBuilder<SharedObjectType : Any>(
|
|
|
57
57
|
inline fun <reified P0, reified P1> Constructor(
|
|
58
58
|
crossinline body: (p0: P0, p1: P1) -> SharedObjectType
|
|
59
59
|
): SyncFunctionComponent {
|
|
60
|
-
return SyncFunctionComponent("constructor", arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }.also {
|
|
60
|
+
return SyncFunctionComponent("constructor", arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>())) { body(it[0] as P0, it[1] as P1) }.also {
|
|
61
61
|
constructor = it
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -65,7 +65,7 @@ class ClassComponentBuilder<SharedObjectType : Any>(
|
|
|
65
65
|
inline fun <reified P0, reified P1, reified P2> Constructor(
|
|
66
66
|
crossinline body: (p0: P0, p1: P1, p2: P2) -> SharedObjectType
|
|
67
67
|
): SyncFunctionComponent {
|
|
68
|
-
return SyncFunctionComponent("constructor", arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }.also {
|
|
68
|
+
return SyncFunctionComponent("constructor", arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }.also {
|
|
69
69
|
constructor = it
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -73,7 +73,7 @@ class ClassComponentBuilder<SharedObjectType : Any>(
|
|
|
73
73
|
inline fun <reified P0, reified P1, reified P2, reified P3> Constructor(
|
|
74
74
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> SharedObjectType
|
|
75
75
|
): SyncFunctionComponent {
|
|
76
|
-
return SyncFunctionComponent("constructor", arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }.also {
|
|
76
|
+
return SyncFunctionComponent("constructor", arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }.also {
|
|
77
77
|
constructor = it
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -81,7 +81,7 @@ class ClassComponentBuilder<SharedObjectType : Any>(
|
|
|
81
81
|
inline fun <reified P0, reified P1, reified P2, reified P3, reified P4> Constructor(
|
|
82
82
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> SharedObjectType
|
|
83
83
|
): SyncFunctionComponent {
|
|
84
|
-
return SyncFunctionComponent("constructor", arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }.also {
|
|
84
|
+
return SyncFunctionComponent("constructor", arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }.also {
|
|
85
85
|
constructor = it
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -89,7 +89,7 @@ class ClassComponentBuilder<SharedObjectType : Any>(
|
|
|
89
89
|
inline fun <reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> Constructor(
|
|
90
90
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> SharedObjectType
|
|
91
91
|
): SyncFunctionComponent {
|
|
92
|
-
return SyncFunctionComponent("constructor", arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }.also {
|
|
92
|
+
return SyncFunctionComponent("constructor", arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }.also {
|
|
93
93
|
constructor = it
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -97,7 +97,7 @@ class ClassComponentBuilder<SharedObjectType : Any>(
|
|
|
97
97
|
inline fun <reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> Constructor(
|
|
98
98
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> SharedObjectType
|
|
99
99
|
): SyncFunctionComponent {
|
|
100
|
-
return SyncFunctionComponent("constructor", arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }.also {
|
|
100
|
+
return SyncFunctionComponent("constructor", arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }.also {
|
|
101
101
|
constructor = it
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -105,7 +105,7 @@ class ClassComponentBuilder<SharedObjectType : Any>(
|
|
|
105
105
|
inline fun <reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> Constructor(
|
|
106
106
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> SharedObjectType
|
|
107
107
|
): SyncFunctionComponent {
|
|
108
|
-
return SyncFunctionComponent("constructor", arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }.also {
|
|
108
|
+
return SyncFunctionComponent("constructor", arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>(), { typeOf<P7>() }.toAnyType<P7>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }.also {
|
|
109
109
|
constructor = it
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -54,14 +54,13 @@ object ExpoRequestCdpInterceptor : ExpoNetworkInspectOkHttpInterceptorsDelegate
|
|
|
54
54
|
val params = ResponseReceivedParams(now, requestId, request, response)
|
|
55
55
|
dispatchEvent(Event("Network.responseReceived", params))
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
val contentLength = response.body?.contentLength() ?: 0
|
|
61
|
-
if (contentLength >= 0 && contentLength <= ExpoNetworkInspectOkHttpNetworkInterceptor.MAX_BODY_SIZE) {
|
|
62
|
-
val params3 = ExpoReceivedResponseBodyParams(now, requestId, request, response)
|
|
63
|
-
dispatchEvent(Event("Expo(Network.receivedResponseBody)", params3))
|
|
57
|
+
if (response.peekBody(ExpoNetworkInspectOkHttpNetworkInterceptor.MAX_BODY_SIZE + 1).contentLength() <= ExpoNetworkInspectOkHttpNetworkInterceptor.MAX_BODY_SIZE) {
|
|
58
|
+
val params2 = ExpoReceivedResponseBodyParams(now, requestId, request, response)
|
|
59
|
+
dispatchEvent(Event("Expo(Network.receivedResponseBody)", params2))
|
|
64
60
|
}
|
|
61
|
+
|
|
62
|
+
val params3 = LoadingFinishedParams(now, requestId, request, response)
|
|
63
|
+
dispatchEvent(Event("Network.loadingFinished", params3))
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
//endregion ExpoNetworkInspectOkHttpInterceptorsDelegate implementations
|
|
@@ -205,10 +205,10 @@ data class LoadingFinishedParams(
|
|
|
205
205
|
val timestamp: MonotonicTime,
|
|
206
206
|
val encodedDataLength: Long,
|
|
207
207
|
) : JsonSerializable {
|
|
208
|
-
constructor(now: BigDecimal, requestId: RequestId, request: okhttp3.Request,
|
|
208
|
+
constructor(now: BigDecimal, requestId: RequestId, request: okhttp3.Request, response: okhttp3.Response) : this(
|
|
209
209
|
requestId = requestId,
|
|
210
210
|
timestamp = now,
|
|
211
|
-
encodedDataLength =
|
|
211
|
+
encodedDataLength = response.body?.contentLength() ?: 0,
|
|
212
212
|
)
|
|
213
213
|
|
|
214
214
|
override fun toJSONObject(): JSONObject {
|
|
@@ -230,8 +230,6 @@ data class ExpoReceivedResponseBodyParams(
|
|
|
230
230
|
body = "",
|
|
231
231
|
base64Encoded = false,
|
|
232
232
|
) {
|
|
233
|
-
val contentLength = response.body?.contentLength() ?: 0
|
|
234
|
-
check(contentLength >= 0 && contentLength <= ExpoNetworkInspectOkHttpNetworkInterceptor.MAX_BODY_SIZE)
|
|
235
233
|
val rawBody = response.peekBody(ExpoNetworkInspectOkHttpNetworkInterceptor.MAX_BODY_SIZE)
|
|
236
234
|
val contentType = rawBody.contentType()
|
|
237
235
|
val isText = contentType?.type == "text" || (contentType?.type == "application" && contentType.subtype == "json")
|
|
@@ -12,9 +12,8 @@ import expo.modules.kotlin.jni.JavaScriptModuleObject
|
|
|
12
12
|
import expo.modules.kotlin.jni.JavaScriptObject
|
|
13
13
|
import expo.modules.kotlin.recycle
|
|
14
14
|
import expo.modules.kotlin.types.AnyType
|
|
15
|
+
import kotlin.reflect.KClass
|
|
15
16
|
import kotlin.reflect.KType
|
|
16
|
-
import kotlin.reflect.full.isSubtypeOf
|
|
17
|
-
import kotlin.reflect.typeOf
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* Base class of all exported functions
|
|
@@ -31,9 +30,21 @@ abstract class AnyFunction(
|
|
|
31
30
|
internal var ownerType: KType? = null
|
|
32
31
|
|
|
33
32
|
internal val takesOwner: Boolean
|
|
34
|
-
get()
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
get() {
|
|
34
|
+
if (canTakeOwner) {
|
|
35
|
+
val firstArgumentType = desiredArgsTypes.firstOrNull()?.kType?.classifier as? KClass<*>
|
|
36
|
+
?: return false
|
|
37
|
+
|
|
38
|
+
if (firstArgumentType == JavaScriptObject::class) {
|
|
39
|
+
return true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
val ownerClass = ownerType?.classifier as? KClass<*> ?: return false
|
|
43
|
+
|
|
44
|
+
return firstArgumentType == ownerClass
|
|
45
|
+
}
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
37
48
|
|
|
38
49
|
/**
|
|
39
50
|
* A minimum number of arguments the functions needs which equals to `argumentsCount` reduced by the number of trailing optional arguments.
|
|
@@ -17,49 +17,49 @@ class AsyncFunctionBuilder(@PublishedApi internal val name: String) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
inline fun <reified R, reified P0> SuspendBody(crossinline block: suspend (p0: P0) -> R): SuspendFunctionComponent {
|
|
20
|
-
return SuspendFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0) }.also {
|
|
20
|
+
return SuspendFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>())) { block(it[0] as P0) }.also {
|
|
21
21
|
suspendFunctionComponent = it
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
inline fun <reified R, reified P0, reified P1> SuspendBody(crossinline block: suspend (p0: P0, p1: P1) -> R): SuspendFunctionComponent {
|
|
26
|
-
return SuspendFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { block(it[0] as P0, it[1] as P1) }.also {
|
|
26
|
+
return SuspendFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>())) { block(it[0] as P0, it[1] as P1) }.also {
|
|
27
27
|
suspendFunctionComponent = it
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
inline fun <reified R, reified P0, reified P1, reified P2> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2) -> R): SuspendFunctionComponent {
|
|
32
|
-
return SuspendFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2) }.also {
|
|
32
|
+
return SuspendFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>())) { block(it[0] as P0, it[1] as P1, it[2] as P2) }.also {
|
|
33
33
|
suspendFunctionComponent = it
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3) -> R): SuspendFunctionComponent {
|
|
38
|
-
return SuspendFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }.also {
|
|
38
|
+
return SuspendFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }.also {
|
|
39
39
|
suspendFunctionComponent = it
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R): SuspendFunctionComponent {
|
|
44
|
-
return SuspendFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }.also {
|
|
44
|
+
return SuspendFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }.also {
|
|
45
45
|
suspendFunctionComponent = it
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R): SuspendFunctionComponent {
|
|
50
|
-
return SuspendFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }.also {
|
|
50
|
+
return SuspendFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }.also {
|
|
51
51
|
suspendFunctionComponent = it
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R): SuspendFunctionComponent {
|
|
56
|
-
return SuspendFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }.also {
|
|
56
|
+
return SuspendFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }.also {
|
|
57
57
|
suspendFunctionComponent = it
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R): SuspendFunctionComponent {
|
|
62
|
-
return SuspendFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }.also {
|
|
62
|
+
return SuspendFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>(), { typeOf<P7>() }.toAnyType<P7>())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }.also {
|
|
63
63
|
suspendFunctionComponent = it
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -16,6 +16,7 @@ import expo.modules.kotlin.events.EventName
|
|
|
16
16
|
import expo.modules.kotlin.events.OnActivityResultPayload
|
|
17
17
|
import expo.modules.kotlin.objects.ObjectDefinitionBuilder
|
|
18
18
|
import expo.modules.kotlin.sharedobjects.SharedObject
|
|
19
|
+
import expo.modules.kotlin.types.LazyKType
|
|
19
20
|
import expo.modules.kotlin.views.ViewDefinitionBuilder
|
|
20
21
|
import expo.modules.kotlin.views.ViewManagerDefinition
|
|
21
22
|
import kotlin.reflect.KClass
|
|
@@ -62,8 +63,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
62
63
|
*/
|
|
63
64
|
inline fun <reified T : View> View(viewClass: KClass<T>, body: ViewDefinitionBuilder<T>.() -> Unit) {
|
|
64
65
|
require(viewManagerDefinition == null) { "The module definition may have exported only one view manager." }
|
|
65
|
-
|
|
66
|
-
val viewDefinitionBuilder = ViewDefinitionBuilder(viewClass, typeOf<T>())
|
|
66
|
+
val viewDefinitionBuilder = ViewDefinitionBuilder(viewClass, LazyKType(classifier = T::class, kTypeProvider = { typeOf<T>() }))
|
|
67
67
|
body.invoke(viewDefinitionBuilder)
|
|
68
68
|
viewManagerDefinition = viewDefinitionBuilder.build()
|
|
69
69
|
}
|
|
@@ -111,7 +111,7 @@ open class ObjectDefinitionBuilder {
|
|
|
111
111
|
name: String,
|
|
112
112
|
crossinline body: (p0: P0) -> R
|
|
113
113
|
): SyncFunctionComponent {
|
|
114
|
-
return SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }.also {
|
|
114
|
+
return SyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>())) { body(it[0] as P0) }.also {
|
|
115
115
|
syncFunctions[name] = it
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -120,7 +120,7 @@ open class ObjectDefinitionBuilder {
|
|
|
120
120
|
name: String,
|
|
121
121
|
crossinline body: (p0: P0, p1: P1) -> R
|
|
122
122
|
): SyncFunctionComponent {
|
|
123
|
-
return SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }.also {
|
|
123
|
+
return SyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>())) { body(it[0] as P0, it[1] as P1) }.also {
|
|
124
124
|
syncFunctions[name] = it
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -129,7 +129,7 @@ open class ObjectDefinitionBuilder {
|
|
|
129
129
|
name: String,
|
|
130
130
|
crossinline body: (p0: P0, p1: P1, p2: P2) -> R
|
|
131
131
|
): SyncFunctionComponent {
|
|
132
|
-
return SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }.also {
|
|
132
|
+
return SyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }.also {
|
|
133
133
|
syncFunctions[name] = it
|
|
134
134
|
}
|
|
135
135
|
}
|
|
@@ -138,7 +138,7 @@ open class ObjectDefinitionBuilder {
|
|
|
138
138
|
name: String,
|
|
139
139
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
|
|
140
140
|
): SyncFunctionComponent {
|
|
141
|
-
return SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }.also {
|
|
141
|
+
return SyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }.also {
|
|
142
142
|
syncFunctions[name] = it
|
|
143
143
|
}
|
|
144
144
|
}
|
|
@@ -147,7 +147,7 @@ open class ObjectDefinitionBuilder {
|
|
|
147
147
|
name: String,
|
|
148
148
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
|
|
149
149
|
): SyncFunctionComponent {
|
|
150
|
-
return SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }.also {
|
|
150
|
+
return SyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }.also {
|
|
151
151
|
syncFunctions[name] = it
|
|
152
152
|
}
|
|
153
153
|
}
|
|
@@ -156,7 +156,7 @@ open class ObjectDefinitionBuilder {
|
|
|
156
156
|
name: String,
|
|
157
157
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
|
|
158
158
|
): SyncFunctionComponent {
|
|
159
|
-
return SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }.also {
|
|
159
|
+
return SyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }.also {
|
|
160
160
|
syncFunctions[name] = it
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -165,7 +165,7 @@ open class ObjectDefinitionBuilder {
|
|
|
165
165
|
name: String,
|
|
166
166
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
|
|
167
167
|
): SyncFunctionComponent {
|
|
168
|
-
return SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }.also {
|
|
168
|
+
return SyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }.also {
|
|
169
169
|
syncFunctions[name] = it
|
|
170
170
|
}
|
|
171
171
|
}
|
|
@@ -174,7 +174,7 @@ open class ObjectDefinitionBuilder {
|
|
|
174
174
|
name: String,
|
|
175
175
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
|
|
176
176
|
): SyncFunctionComponent {
|
|
177
|
-
return SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }.also {
|
|
177
|
+
return SyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>(), { typeOf<P7>() }.toAnyType<P7>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }.also {
|
|
178
178
|
syncFunctions[name] = it
|
|
179
179
|
}
|
|
180
180
|
}
|
|
@@ -205,7 +205,7 @@ open class ObjectDefinitionBuilder {
|
|
|
205
205
|
return if (P0::class == Promise::class) {
|
|
206
206
|
AsyncFunctionWithPromiseComponent(name, arrayOf()) { _, promise -> body(promise as P0) }
|
|
207
207
|
} else {
|
|
208
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
|
|
208
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>())) { body(it[0] as P0) }
|
|
209
209
|
}.also {
|
|
210
210
|
asyncFunctions[name] = it
|
|
211
211
|
}
|
|
@@ -216,9 +216,9 @@ open class ObjectDefinitionBuilder {
|
|
|
216
216
|
crossinline body: (p0: P0, p1: P1) -> R
|
|
217
217
|
): AsyncFunction {
|
|
218
218
|
return if (P1::class == Promise::class) {
|
|
219
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
|
|
219
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>())) { args, promise -> body(args[0] as P0, promise as P1) }
|
|
220
220
|
} else {
|
|
221
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
|
|
221
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>())) { body(it[0] as P0, it[1] as P1) }
|
|
222
222
|
}.also {
|
|
223
223
|
asyncFunctions[name] = it
|
|
224
224
|
}
|
|
@@ -229,9 +229,9 @@ open class ObjectDefinitionBuilder {
|
|
|
229
229
|
crossinline body: (p0: P0, p1: P1, p2: P2) -> R
|
|
230
230
|
): AsyncFunction {
|
|
231
231
|
return if (P2::class == Promise::class) {
|
|
232
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
|
|
232
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
|
|
233
233
|
} else {
|
|
234
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
|
|
234
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
|
|
235
235
|
}.also {
|
|
236
236
|
asyncFunctions[name] = it
|
|
237
237
|
}
|
|
@@ -242,9 +242,9 @@ open class ObjectDefinitionBuilder {
|
|
|
242
242
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
|
|
243
243
|
): AsyncFunction {
|
|
244
244
|
return if (P3::class == Promise::class) {
|
|
245
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, promise as P3) }
|
|
245
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, promise as P3) }
|
|
246
246
|
} else {
|
|
247
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
|
|
247
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
|
|
248
248
|
}.also {
|
|
249
249
|
asyncFunctions[name] = it
|
|
250
250
|
}
|
|
@@ -255,9 +255,9 @@ open class ObjectDefinitionBuilder {
|
|
|
255
255
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
|
|
256
256
|
): AsyncFunction {
|
|
257
257
|
return if (P4::class == Promise::class) {
|
|
258
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, promise as P4) }
|
|
258
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, promise as P4) }
|
|
259
259
|
} else {
|
|
260
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
|
|
260
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
|
|
261
261
|
}.also {
|
|
262
262
|
asyncFunctions[name] = it
|
|
263
263
|
}
|
|
@@ -268,9 +268,9 @@ open class ObjectDefinitionBuilder {
|
|
|
268
268
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
|
|
269
269
|
): AsyncFunction {
|
|
270
270
|
return if (P5::class == Promise::class) {
|
|
271
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, promise as P5) }
|
|
271
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, promise as P5) }
|
|
272
272
|
} else {
|
|
273
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
|
|
273
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
|
|
274
274
|
}.also {
|
|
275
275
|
asyncFunctions[name] = it
|
|
276
276
|
}
|
|
@@ -281,9 +281,9 @@ open class ObjectDefinitionBuilder {
|
|
|
281
281
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
|
|
282
282
|
): AsyncFunction {
|
|
283
283
|
return if (P6::class == Promise::class) {
|
|
284
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, promise as P6) }
|
|
284
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, promise as P6) }
|
|
285
285
|
} else {
|
|
286
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }
|
|
286
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }
|
|
287
287
|
}.also {
|
|
288
288
|
asyncFunctions[name] = it
|
|
289
289
|
}
|
|
@@ -294,9 +294,9 @@ open class ObjectDefinitionBuilder {
|
|
|
294
294
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
|
|
295
295
|
): AsyncFunction {
|
|
296
296
|
return if (P7::class == Promise::class) {
|
|
297
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, args[6] as P6, promise as P7) }
|
|
297
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, args[6] as P6, promise as P7) }
|
|
298
298
|
} else {
|
|
299
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }
|
|
299
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>(), { typeOf<P7>() }.toAnyType<P7>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }
|
|
300
300
|
}.also {
|
|
301
301
|
asyncFunctions[name] = it
|
|
302
302
|
}
|
|
@@ -23,7 +23,7 @@ class PropertyComponentBuilder(
|
|
|
23
23
|
* Modifier that sets property setter that receives only the new value as an argument.
|
|
24
24
|
*/
|
|
25
25
|
inline fun <reified T> set(crossinline body: (newValue: T) -> Unit) = apply {
|
|
26
|
-
setter = SyncFunctionComponent("set", arrayOf(typeOf<T>().toAnyType())) { body(it[0] as T) }
|
|
26
|
+
setter = SyncFunctionComponent("set", arrayOf({ typeOf<T>() }.toAnyType<T>())) { body(it[0] as T) }
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
fun build(): PropertyComponent {
|
|
@@ -27,7 +27,7 @@ class RecordTypeConverter<T : Record>(
|
|
|
27
27
|
val type: KType,
|
|
28
28
|
) : DynamicAwareTypeConverters<T>(type.isMarkedNullable) {
|
|
29
29
|
private val objectConstructorFactory = ObjectConstructorFactory()
|
|
30
|
-
private val propertyDescriptors: Map<KProperty1<out Any, *>, PropertyDescriptor>
|
|
30
|
+
private val propertyDescriptors: Map<KProperty1<out Any, *>, PropertyDescriptor> by lazy {
|
|
31
31
|
(type.classifier as KClass<*>)
|
|
32
32
|
.memberProperties
|
|
33
33
|
.map { property ->
|
|
@@ -43,6 +43,7 @@ class RecordTypeConverter<T : Record>(
|
|
|
43
43
|
}
|
|
44
44
|
.filterNotNull()
|
|
45
45
|
.toMap()
|
|
46
|
+
}
|
|
46
47
|
|
|
47
48
|
override fun convertFromDynamic(value: Dynamic): T = exceptionDecorator({ cause -> RecordCastException(type, cause) }) {
|
|
48
49
|
val jsMap = value.asMap()
|
|
@@ -2,11 +2,59 @@ package expo.modules.kotlin.types
|
|
|
2
2
|
|
|
3
3
|
import expo.modules.kotlin.AppContext
|
|
4
4
|
import expo.modules.kotlin.jni.ExpectedType
|
|
5
|
+
import kotlin.reflect.KClass
|
|
5
6
|
import kotlin.reflect.KType
|
|
7
|
+
import kotlin.reflect.KTypeProjection
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
class LazyKType(
|
|
10
|
+
override val classifier: KClass<*>,
|
|
11
|
+
override val isMarkedNullable: Boolean = false,
|
|
12
|
+
val kTypeProvider: () -> KType
|
|
13
|
+
) : KType {
|
|
14
|
+
private var _kType: KType? = null
|
|
15
|
+
private val kType: KType
|
|
16
|
+
get() {
|
|
17
|
+
if (_kType == null) {
|
|
18
|
+
_kType = kTypeProvider()
|
|
19
|
+
}
|
|
20
|
+
return _kType!!
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override val annotations: List<Annotation>
|
|
24
|
+
get() = kType.annotations
|
|
25
|
+
override val arguments: List<KTypeProjection>
|
|
26
|
+
get() = kType.arguments
|
|
27
|
+
|
|
28
|
+
override fun equals(other: Any?): Boolean {
|
|
29
|
+
if (this === other) return true
|
|
30
|
+
if (other !is LazyKType) return this.kType == other
|
|
31
|
+
|
|
32
|
+
return classifier == other.classifier && isMarkedNullable == other.isMarkedNullable
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun hashCode(): Int {
|
|
36
|
+
var result = classifier.hashCode()
|
|
37
|
+
result = 31 * result + isMarkedNullable.hashCode()
|
|
38
|
+
return result
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override fun toString(): String {
|
|
42
|
+
return kType.toString()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
inline fun <reified T> (() -> KType).toAnyType() = AnyType(
|
|
47
|
+
LazyKType(
|
|
48
|
+
classifier = T::class,
|
|
49
|
+
isMarkedNullable = null is T,
|
|
50
|
+
kTypeProvider = this
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
class AnyType(
|
|
55
|
+
val kType: KType,
|
|
56
|
+
) {
|
|
8
57
|
|
|
9
|
-
class AnyType(val kType: KType) {
|
|
10
58
|
private val converter: TypeConverter<*> by lazy {
|
|
11
59
|
TypeConverterProviderImpl.obtainTypeConverter(kType)
|
|
12
60
|
}
|
|
@@ -44,7 +44,6 @@ import java.net.URL
|
|
|
44
44
|
import java.nio.file.Path
|
|
45
45
|
import kotlin.reflect.KClass
|
|
46
46
|
import kotlin.reflect.KType
|
|
47
|
-
import kotlin.reflect.full.createType
|
|
48
47
|
import kotlin.reflect.full.isSubclassOf
|
|
49
48
|
import kotlin.reflect.typeOf
|
|
50
49
|
|
|
@@ -73,12 +72,22 @@ fun convert(value: Dynamic, type: KType): Any? {
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
object TypeConverterProviderImpl : TypeConverterProvider {
|
|
76
|
-
private val cachedConverters =
|
|
75
|
+
private val cachedConverters = createCachedConverters(false)
|
|
76
|
+
private val nullableCachedConverters = createCachedConverters(true)
|
|
77
|
+
|
|
77
78
|
private val cachedRecordConverters = mutableMapOf<KClass<*>, TypeConverter<*>>()
|
|
78
79
|
private val cachedCustomConverters = mutableMapOf<KType, TypeConverter<*>>()
|
|
79
80
|
|
|
81
|
+
private fun getCachedConverter(inputType: KType): TypeConverter<*>? {
|
|
82
|
+
return if (inputType.isMarkedNullable) {
|
|
83
|
+
nullableCachedConverters[inputType.classifier]
|
|
84
|
+
} else {
|
|
85
|
+
cachedConverters[inputType.classifier]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
override fun obtainTypeConverter(type: KType): TypeConverter<*> {
|
|
81
|
-
|
|
90
|
+
getCachedConverter(type)?.let {
|
|
82
91
|
return it
|
|
83
92
|
}
|
|
84
93
|
|
|
@@ -175,7 +184,7 @@ object TypeConverterProviderImpl : TypeConverterProvider {
|
|
|
175
184
|
}
|
|
176
185
|
}
|
|
177
186
|
|
|
178
|
-
private fun
|
|
187
|
+
private fun createCachedConverters(isOptional: Boolean): Map<KClass<*>, TypeConverter<*>> {
|
|
179
188
|
val intTypeConverter = createTrivialTypeConverter(
|
|
180
189
|
isOptional, ExpectedType(CppType.INT)
|
|
181
190
|
) { it.asDouble().toInt() }
|
|
@@ -193,33 +202,33 @@ object TypeConverterProviderImpl : TypeConverterProvider {
|
|
|
193
202
|
) { it.asBoolean() }
|
|
194
203
|
|
|
195
204
|
val converters = mapOf(
|
|
196
|
-
Int::class
|
|
197
|
-
java.lang.Integer::class
|
|
205
|
+
Int::class to intTypeConverter,
|
|
206
|
+
java.lang.Integer::class to intTypeConverter,
|
|
198
207
|
|
|
199
|
-
Long::class
|
|
200
|
-
java.lang.Long::class
|
|
208
|
+
Long::class to longTypeConverter,
|
|
209
|
+
java.lang.Long::class to longTypeConverter,
|
|
201
210
|
|
|
202
|
-
Double::class
|
|
203
|
-
java.lang.Double::class
|
|
211
|
+
Double::class to doubleTypeConverter,
|
|
212
|
+
java.lang.Double::class to doubleTypeConverter,
|
|
204
213
|
|
|
205
|
-
Float::class
|
|
206
|
-
java.lang.Float::class
|
|
214
|
+
Float::class to floatTypeConverter,
|
|
215
|
+
java.lang.Float::class to floatTypeConverter,
|
|
207
216
|
|
|
208
|
-
Boolean::class
|
|
209
|
-
java.lang.Boolean::class
|
|
217
|
+
Boolean::class to boolTypeConverter,
|
|
218
|
+
java.lang.Boolean::class to boolTypeConverter,
|
|
210
219
|
|
|
211
|
-
String::class
|
|
220
|
+
String::class to createTrivialTypeConverter(
|
|
212
221
|
isOptional, ExpectedType(CppType.STRING)
|
|
213
222
|
) { it.asString() },
|
|
214
223
|
|
|
215
|
-
ReadableArray::class
|
|
224
|
+
ReadableArray::class to createTrivialTypeConverter(
|
|
216
225
|
isOptional, ExpectedType(CppType.READABLE_ARRAY)
|
|
217
226
|
) { it.asArray() },
|
|
218
|
-
ReadableMap::class
|
|
227
|
+
ReadableMap::class to createTrivialTypeConverter(
|
|
219
228
|
isOptional, ExpectedType(CppType.READABLE_MAP)
|
|
220
229
|
) { it.asMap() },
|
|
221
230
|
|
|
222
|
-
IntArray::class
|
|
231
|
+
IntArray::class to createTrivialTypeConverter(
|
|
223
232
|
isOptional, ExpectedType.forPrimitiveArray(CppType.INT)
|
|
224
233
|
) {
|
|
225
234
|
val jsArray = it.asArray()
|
|
@@ -227,7 +236,7 @@ object TypeConverterProviderImpl : TypeConverterProvider {
|
|
|
227
236
|
jsArray.getInt(index)
|
|
228
237
|
}
|
|
229
238
|
},
|
|
230
|
-
DoubleArray::class
|
|
239
|
+
DoubleArray::class to createTrivialTypeConverter(
|
|
231
240
|
isOptional, ExpectedType.forPrimitiveArray(CppType.DOUBLE)
|
|
232
241
|
) {
|
|
233
242
|
val jsArray = it.asArray()
|
|
@@ -235,7 +244,7 @@ object TypeConverterProviderImpl : TypeConverterProvider {
|
|
|
235
244
|
jsArray.getDouble(index)
|
|
236
245
|
}
|
|
237
246
|
},
|
|
238
|
-
FloatArray::class
|
|
247
|
+
FloatArray::class to createTrivialTypeConverter(
|
|
239
248
|
isOptional, ExpectedType.forPrimitiveArray(CppType.FLOAT)
|
|
240
249
|
) {
|
|
241
250
|
val jsArray = it.asArray()
|
|
@@ -243,7 +252,7 @@ object TypeConverterProviderImpl : TypeConverterProvider {
|
|
|
243
252
|
jsArray.getDouble(index).toFloat()
|
|
244
253
|
}
|
|
245
254
|
},
|
|
246
|
-
BooleanArray::class
|
|
255
|
+
BooleanArray::class to createTrivialTypeConverter(
|
|
247
256
|
isOptional, ExpectedType.forPrimitiveArray(CppType.BOOLEAN)
|
|
248
257
|
) {
|
|
249
258
|
val jsArray = it.asArray()
|
|
@@ -252,39 +261,39 @@ object TypeConverterProviderImpl : TypeConverterProvider {
|
|
|
252
261
|
}
|
|
253
262
|
},
|
|
254
263
|
|
|
255
|
-
JavaScriptValue::class
|
|
264
|
+
JavaScriptValue::class to createTrivialTypeConverter(
|
|
256
265
|
isOptional, ExpectedType(CppType.JS_VALUE)
|
|
257
266
|
),
|
|
258
|
-
JavaScriptObject::class
|
|
267
|
+
JavaScriptObject::class to createTrivialTypeConverter(
|
|
259
268
|
isOptional, ExpectedType(CppType.JS_OBJECT)
|
|
260
269
|
),
|
|
261
270
|
|
|
262
|
-
Int8Array::class
|
|
263
|
-
Int16Array::class
|
|
264
|
-
Int32Array::class
|
|
265
|
-
Uint8Array::class
|
|
266
|
-
Uint8ClampedArray::class
|
|
267
|
-
Uint16Array::class
|
|
268
|
-
Uint32Array::class
|
|
269
|
-
Float32Array::class
|
|
270
|
-
Float64Array::class
|
|
271
|
-
BigInt64Array::class
|
|
272
|
-
BigUint64Array::class
|
|
273
|
-
TypedArray::class
|
|
274
|
-
|
|
275
|
-
URL::class
|
|
276
|
-
Uri::class
|
|
277
|
-
URI::class
|
|
278
|
-
|
|
279
|
-
File::class
|
|
280
|
-
|
|
281
|
-
Any::class
|
|
271
|
+
Int8Array::class to Int8ArrayTypeConverter(isOptional),
|
|
272
|
+
Int16Array::class to Int16ArrayTypeConverter(isOptional),
|
|
273
|
+
Int32Array::class to Int32ArrayTypeConverter(isOptional),
|
|
274
|
+
Uint8Array::class to Uint8ArrayTypeConverter(isOptional),
|
|
275
|
+
Uint8ClampedArray::class to Uint8ClampedArrayTypeConverter(isOptional),
|
|
276
|
+
Uint16Array::class to Uint16ArrayTypeConverter(isOptional),
|
|
277
|
+
Uint32Array::class to Uint32ArrayTypeConverter(isOptional),
|
|
278
|
+
Float32Array::class to Float32ArrayTypeConverter(isOptional),
|
|
279
|
+
Float64Array::class to Float64ArrayTypeConverter(isOptional),
|
|
280
|
+
BigInt64Array::class to BigInt64ArrayTypeConverter(isOptional),
|
|
281
|
+
BigUint64Array::class to BigUint64ArrayTypeConverter(isOptional),
|
|
282
|
+
TypedArray::class to TypedArrayTypeConverter(isOptional),
|
|
283
|
+
|
|
284
|
+
URL::class to URLTypConverter(isOptional),
|
|
285
|
+
Uri::class to UriTypeConverter(isOptional),
|
|
286
|
+
URI::class to JavaURITypeConverter(isOptional),
|
|
287
|
+
|
|
288
|
+
File::class to FileTypeConverter(isOptional),
|
|
289
|
+
|
|
290
|
+
Any::class to AnyTypeConverter(isOptional),
|
|
282
291
|
)
|
|
283
292
|
|
|
284
293
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
285
294
|
return converters + mapOf(
|
|
286
|
-
Path::class
|
|
287
|
-
Color::class
|
|
295
|
+
Path::class to PathTypeConverter(isOptional),
|
|
296
|
+
Color::class to ColorTypeConverter(isOptional),
|
|
288
297
|
)
|
|
289
298
|
}
|
|
290
299
|
|
|
@@ -37,7 +37,7 @@ class GroupViewManagerWrapper(
|
|
|
37
37
|
override fun getNativeProps(): MutableMap<String, String> {
|
|
38
38
|
val props = super.getNativeProps()
|
|
39
39
|
viewWrapperDelegate.props.forEach { (key, prop) ->
|
|
40
|
-
props[key] = prop.type.kType.toString()
|
|
40
|
+
props[key] = prop.type.kType.classifier.toString()
|
|
41
41
|
}
|
|
42
42
|
return props
|
|
43
43
|
}
|
|
@@ -35,7 +35,7 @@ class SimpleViewManagerWrapper(
|
|
|
35
35
|
override fun getNativeProps(): MutableMap<String, String> {
|
|
36
36
|
val props = super.getNativeProps()
|
|
37
37
|
viewWrapperDelegate.props.forEach { (key, prop) ->
|
|
38
|
-
props[key] = prop.type.kType.toString()
|
|
38
|
+
props[key] = prop.type.kType.classifier.toString()
|
|
39
39
|
}
|
|
40
40
|
return props
|
|
41
41
|
}
|
|
@@ -111,7 +111,7 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
111
111
|
) {
|
|
112
112
|
props[name] = ConcreteViewProp(
|
|
113
113
|
name,
|
|
114
|
-
typeOf<PropType>().toAnyType(),
|
|
114
|
+
{ typeOf<PropType>() }.toAnyType<PropType>(),
|
|
115
115
|
body
|
|
116
116
|
)
|
|
117
117
|
}
|
|
@@ -126,7 +126,7 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
126
126
|
) {
|
|
127
127
|
props[name] = ConcreteViewProp(
|
|
128
128
|
name,
|
|
129
|
-
typeOf<PropType>().toAnyType(),
|
|
129
|
+
{ typeOf<PropType>() }.toAnyType<PropType>(),
|
|
130
130
|
body
|
|
131
131
|
)
|
|
132
132
|
}
|
|
@@ -184,7 +184,7 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
184
184
|
return if (P0::class == Promise::class) {
|
|
185
185
|
AsyncFunctionWithPromiseComponent(name, arrayOf()) { _, promise -> body(promise as P0) }
|
|
186
186
|
} else {
|
|
187
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
|
|
187
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>())) { body(it[0] as P0) }
|
|
188
188
|
}.also {
|
|
189
189
|
it.ownerType = viewType
|
|
190
190
|
asyncFunctions[name] = it
|
|
@@ -196,9 +196,9 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
196
196
|
crossinline body: (p0: P0, p1: P1) -> R
|
|
197
197
|
): AsyncFunction {
|
|
198
198
|
return if (P1::class == Promise::class) {
|
|
199
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
|
|
199
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>())) { args, promise -> body(args[0] as P0, promise as P1) }
|
|
200
200
|
} else {
|
|
201
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
|
|
201
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>())) { body(it[0] as P0, it[1] as P1) }
|
|
202
202
|
}.also {
|
|
203
203
|
asyncFunctions[name] = it
|
|
204
204
|
}
|
|
@@ -209,9 +209,9 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
209
209
|
crossinline body: (p0: P0, p1: P1, p2: P2) -> R
|
|
210
210
|
): AsyncFunction {
|
|
211
211
|
return if (P2::class == Promise::class) {
|
|
212
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
|
|
212
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
|
|
213
213
|
} else {
|
|
214
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
|
|
214
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
|
|
215
215
|
}.also {
|
|
216
216
|
asyncFunctions[name] = it
|
|
217
217
|
}
|
|
@@ -222,9 +222,9 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
222
222
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
|
|
223
223
|
): AsyncFunction {
|
|
224
224
|
return if (P3::class == Promise::class) {
|
|
225
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, promise as P3) }
|
|
225
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, promise as P3) }
|
|
226
226
|
} else {
|
|
227
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
|
|
227
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
|
|
228
228
|
}.also {
|
|
229
229
|
asyncFunctions[name] = it
|
|
230
230
|
}
|
|
@@ -235,9 +235,9 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
235
235
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
|
|
236
236
|
): AsyncFunction {
|
|
237
237
|
return if (P4::class == Promise::class) {
|
|
238
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, promise as P4) }
|
|
238
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, promise as P4) }
|
|
239
239
|
} else {
|
|
240
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
|
|
240
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
|
|
241
241
|
}.also {
|
|
242
242
|
asyncFunctions[name] = it
|
|
243
243
|
}
|
|
@@ -248,9 +248,9 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
248
248
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
|
|
249
249
|
): AsyncFunction {
|
|
250
250
|
return if (P5::class == Promise::class) {
|
|
251
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, promise as P5) }
|
|
251
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, promise as P5) }
|
|
252
252
|
} else {
|
|
253
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
|
|
253
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
|
|
254
254
|
}.also {
|
|
255
255
|
asyncFunctions[name] = it
|
|
256
256
|
}
|
|
@@ -261,9 +261,9 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
261
261
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
|
|
262
262
|
): AsyncFunction {
|
|
263
263
|
return if (P6::class == Promise::class) {
|
|
264
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, promise as P6) }
|
|
264
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, promise as P6) }
|
|
265
265
|
} else {
|
|
266
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }
|
|
266
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }
|
|
267
267
|
}.also {
|
|
268
268
|
asyncFunctions[name] = it
|
|
269
269
|
}
|
|
@@ -274,9 +274,9 @@ class ViewDefinitionBuilder<T : View>(
|
|
|
274
274
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
|
|
275
275
|
): AsyncFunction {
|
|
276
276
|
return if (P7::class == Promise::class) {
|
|
277
|
-
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, args[6] as P6, promise as P7) }
|
|
277
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, args[6] as P6, promise as P7) }
|
|
278
278
|
} else {
|
|
279
|
-
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }
|
|
279
|
+
AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>(), { typeOf<P1>() }.toAnyType<P1>(), { typeOf<P2>() }.toAnyType<P2>(), { typeOf<P3>() }.toAnyType<P3>(), { typeOf<P4>() }.toAnyType<P4>(), { typeOf<P5>() }.toAnyType<P5>(), { typeOf<P6>() }.toAnyType<P6>(), { typeOf<P7>() }.toAnyType<P7>())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }
|
|
280
280
|
}.also {
|
|
281
281
|
asyncFunctions[name] = it
|
|
282
282
|
}
|
|
@@ -62,7 +62,7 @@ struct CdpNetwork {
|
|
|
62
62
|
let mimeType: String
|
|
63
63
|
let encodedDataLength: Int64
|
|
64
64
|
|
|
65
|
-
init(_ response: HTTPURLResponse) {
|
|
65
|
+
init(_ response: HTTPURLResponse, encodedDataLength: Int64) {
|
|
66
66
|
self.url = response.url?.absoluteString ?? ""
|
|
67
67
|
self.status = response.statusCode
|
|
68
68
|
self.statusText = ""
|
|
@@ -73,7 +73,7 @@ struct CdpNetwork {
|
|
|
73
73
|
}
|
|
74
74
|
self.headers = headers
|
|
75
75
|
self.mimeType = response.value(forHTTPHeaderField: "Content-Type") ?? ""
|
|
76
|
-
self.encodedDataLength =
|
|
76
|
+
self.encodedDataLength = encodedDataLength
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -94,13 +94,13 @@ struct CdpNetwork {
|
|
|
94
94
|
var referrerPolicy = "no-referrer"
|
|
95
95
|
let type: ResourceType
|
|
96
96
|
|
|
97
|
-
init(now: TimeInterval, requestId: RequestId, request: URLRequest, redirectResponse: HTTPURLResponse?) {
|
|
97
|
+
init(now: TimeInterval, requestId: RequestId, request: URLRequest, encodedDataLength: Int64, redirectResponse: HTTPURLResponse?) {
|
|
98
98
|
self.requestId = requestId
|
|
99
99
|
self.request = Request(request)
|
|
100
100
|
self.timestamp = now
|
|
101
101
|
self.wallTime = now
|
|
102
102
|
if let redirectResponse = redirectResponse {
|
|
103
|
-
self.redirectResponse = Response(redirectResponse)
|
|
103
|
+
self.redirectResponse = Response(redirectResponse, encodedDataLength: encodedDataLength)
|
|
104
104
|
} else {
|
|
105
105
|
self.redirectResponse = nil
|
|
106
106
|
}
|
|
@@ -129,10 +129,10 @@ struct CdpNetwork {
|
|
|
129
129
|
let response: Response
|
|
130
130
|
var hasExtraInfo = false
|
|
131
131
|
|
|
132
|
-
init(now: TimeInterval, requestId: RequestId, request: URLRequest, response: HTTPURLResponse) {
|
|
132
|
+
init(now: TimeInterval, requestId: RequestId, request: URLRequest, response: HTTPURLResponse, encodedDataLength: Int64) {
|
|
133
133
|
self.requestId = requestId
|
|
134
134
|
self.timestamp = now
|
|
135
|
-
self.response = Response(response)
|
|
135
|
+
self.response = Response(response, encodedDataLength: encodedDataLength)
|
|
136
136
|
self.type = ResourceType.fromMimeType(self.response.mimeType)
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -142,10 +142,10 @@ struct CdpNetwork {
|
|
|
142
142
|
let timestamp: MonotonicTime
|
|
143
143
|
let encodedDataLength: Int64
|
|
144
144
|
|
|
145
|
-
init(now: TimeInterval, requestId: RequestId,
|
|
145
|
+
init(now: TimeInterval, requestId: RequestId, encodedDataLength: Int64) {
|
|
146
146
|
self.requestId = requestId
|
|
147
147
|
self.timestamp = now
|
|
148
|
-
self.encodedDataLength =
|
|
148
|
+
self.encodedDataLength = encodedDataLength
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -34,30 +34,42 @@ public final class ExpoRequestCdpInterceptor: NSObject, ExpoRequestInterceptorPr
|
|
|
34
34
|
|
|
35
35
|
// MARK: ExpoRequestInterceptorProtocolDelegate implementations
|
|
36
36
|
|
|
37
|
-
func willSendRequest(requestId: String, request: URLRequest, redirectResponse: HTTPURLResponse?) {
|
|
37
|
+
func willSendRequest(requestId: String, task: URLSessionTask, request: URLRequest, redirectResponse: HTTPURLResponse?) {
|
|
38
38
|
let now = Date().timeIntervalSince1970
|
|
39
39
|
|
|
40
|
-
let params = CdpNetwork.RequestWillBeSentParams(
|
|
40
|
+
let params = CdpNetwork.RequestWillBeSentParams(
|
|
41
|
+
now: now,
|
|
42
|
+
requestId: requestId,
|
|
43
|
+
request: request,
|
|
44
|
+
encodedDataLength: task.countOfBytesReceived,
|
|
45
|
+
redirectResponse: redirectResponse)
|
|
41
46
|
dispatchEvent(CdpNetwork.Event(method: "Network.requestWillBeSent", params: params))
|
|
42
47
|
|
|
43
48
|
let params2 = CdpNetwork.RequestWillBeSentExtraInfoParams(now: now, requestId: requestId, request: request)
|
|
44
49
|
dispatchEvent(CdpNetwork.Event(method: "Network.requestWillBeSentExtraInfo", params: params2))
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
func didReceiveResponse(requestId: String,
|
|
52
|
+
func didReceiveResponse(requestId: String, task: URLSessionTask, responseBody: Data, isText: Bool, responseBodyExceedsLimit: Bool) {
|
|
53
|
+
guard let request = task.currentRequest, let response = task.response as? HTTPURLResponse else {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
48
56
|
let now = Date().timeIntervalSince1970
|
|
49
57
|
|
|
50
|
-
let params = CdpNetwork.ResponseReceivedParams(
|
|
58
|
+
let params = CdpNetwork.ResponseReceivedParams(
|
|
59
|
+
now: now,
|
|
60
|
+
requestId: requestId,
|
|
61
|
+
request: request,
|
|
62
|
+
response: response,
|
|
63
|
+
encodedDataLength: task.countOfBytesReceived)
|
|
51
64
|
dispatchEvent(CdpNetwork.Event(method: "Network.responseReceived", params: params))
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
if !responseBodyExceedsLimit {
|
|
67
|
+
let params2 = CdpNetwork.ExpoReceivedResponseBodyParams(now: now, requestId: requestId, responseBody: responseBody, isText: isText)
|
|
68
|
+
dispatchEvent(CdpNetwork.Event(method: "Expo(Network.receivedResponseBody)", params: params2))
|
|
69
|
+
}
|
|
56
70
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let params = CdpNetwork.ExpoReceivedResponseBodyParams(now: now, requestId: requestId, responseBody: responseBody, isText: isText)
|
|
60
|
-
dispatchEvent(CdpNetwork.Event(method: "Expo(Network.receivedResponseBody)", params: params))
|
|
71
|
+
let params3 = CdpNetwork.LoadingFinishedParams(now: now, requestId: requestId, encodedDataLength: task.countOfBytesReceived)
|
|
72
|
+
dispatchEvent(CdpNetwork.Event(method: "Network.loadingFinished", params: params3))
|
|
61
73
|
}
|
|
62
74
|
}
|
|
63
75
|
|
|
@@ -16,8 +16,7 @@ public final class ExpoRequestInterceptorProtocol: URLProtocol, URLSessionDataDe
|
|
|
16
16
|
)
|
|
17
17
|
private var dataTask_: URLSessionDataTask?
|
|
18
18
|
private let responseBody = NSMutableData()
|
|
19
|
-
private var
|
|
20
|
-
private var responseContentLength: Int64 = 0
|
|
19
|
+
private var responseBodyExceedsLimit = false
|
|
21
20
|
|
|
22
21
|
static let MAX_BODY_SIZE = 1_048_576
|
|
23
22
|
|
|
@@ -55,12 +54,14 @@ public final class ExpoRequestInterceptorProtocol: URLProtocol, URLSessionDataDe
|
|
|
55
54
|
forKey: Self.REQUEST_ID,
|
|
56
55
|
in: mutableRequest
|
|
57
56
|
)
|
|
57
|
+
let dataTask = urlSession.dataTask(with: mutableRequest as URLRequest)
|
|
58
58
|
Self.delegate.willSendRequest(
|
|
59
59
|
requestId: requestId,
|
|
60
|
+
task: dataTask,
|
|
60
61
|
request: mutableRequest as URLRequest,
|
|
61
62
|
redirectResponse: nil
|
|
62
63
|
)
|
|
63
|
-
dataTask_ =
|
|
64
|
+
dataTask_ = dataTask
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
public override class func canonicalRequest(for request: URLRequest) -> URLRequest {
|
|
@@ -81,47 +82,25 @@ public final class ExpoRequestInterceptorProtocol: URLProtocol, URLSessionDataDe
|
|
|
81
82
|
client?.urlProtocol(self, didLoad: data)
|
|
82
83
|
if responseBody.length + data.count <= Self.MAX_BODY_SIZE {
|
|
83
84
|
responseBody.append(data)
|
|
85
|
+
} else {
|
|
86
|
+
responseBodyExceedsLimit = true
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
public func urlSession(
|
|
88
|
-
_: URLSession,
|
|
89
|
-
dataTask: URLSessionDataTask,
|
|
90
|
-
didReceive response: URLResponse,
|
|
91
|
-
completionHandler: @escaping (URLSession.ResponseDisposition) -> Void
|
|
92
|
-
) {
|
|
93
|
-
if let resp = response as? HTTPURLResponse,
|
|
94
|
-
let currentRequest = dataTask.currentRequest,
|
|
95
|
-
let requestId = URLProtocol.property(
|
|
96
|
-
forKey: Self.REQUEST_ID,
|
|
97
|
-
in: currentRequest
|
|
98
|
-
) as? String {
|
|
99
|
-
Self.delegate.didReceiveResponse(
|
|
100
|
-
requestId: requestId,
|
|
101
|
-
request: currentRequest,
|
|
102
|
-
response: resp
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
let contentType = resp.value(forHTTPHeaderField: "Content-Type")
|
|
106
|
-
responseIsText = (contentType?.starts(with: "text/") ?? false) || contentType == "application/json"
|
|
107
|
-
responseContentLength = resp.expectedContentLength
|
|
108
|
-
}
|
|
109
|
-
completionHandler(.allow)
|
|
110
|
-
client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .allowed)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
90
|
public func urlSession(_: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
|
|
114
91
|
if let error = error {
|
|
115
92
|
client?.urlProtocol(self, didFailWithError: error)
|
|
116
93
|
} else {
|
|
117
|
-
if
|
|
118
|
-
let
|
|
94
|
+
if let currentRequest = task.currentRequest,
|
|
95
|
+
let response = task.response as? HTTPURLResponse,
|
|
119
96
|
let requestId = URLProtocol.property(
|
|
120
97
|
forKey: Self.REQUEST_ID,
|
|
121
98
|
in: currentRequest
|
|
122
99
|
) as? String {
|
|
123
|
-
|
|
124
|
-
|
|
100
|
+
let contentType = response.value(forHTTPHeaderField: "Content-Type")
|
|
101
|
+
let isText = (contentType?.starts(with: "text/") ?? false) || contentType == "application/json"
|
|
102
|
+
Self.delegate.didReceiveResponse(
|
|
103
|
+
requestId: requestId, task: task, responseBody: responseBody as Data, isText: isText, responseBodyExceedsLimit: responseBodyExceedsLimit)
|
|
125
104
|
}
|
|
126
105
|
client?.urlProtocolDidFinishLoading(self)
|
|
127
106
|
}
|
|
@@ -129,7 +108,17 @@ public final class ExpoRequestInterceptorProtocol: URLProtocol, URLSessionDataDe
|
|
|
129
108
|
|
|
130
109
|
public func urlSession(
|
|
131
110
|
_: URLSession,
|
|
132
|
-
|
|
111
|
+
dataTask: URLSessionDataTask,
|
|
112
|
+
didReceive response: URLResponse,
|
|
113
|
+
completionHandler: @escaping (URLSession.ResponseDisposition) -> Void
|
|
114
|
+
) {
|
|
115
|
+
completionHandler(.allow)
|
|
116
|
+
client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .allowed)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public func urlSession(
|
|
120
|
+
_: URLSession,
|
|
121
|
+
task: URLSessionTask,
|
|
133
122
|
willPerformHTTPRedirection response: HTTPURLResponse,
|
|
134
123
|
newRequest request: URLRequest,
|
|
135
124
|
completionHandler: @escaping (URLRequest?) -> Void
|
|
@@ -137,6 +126,7 @@ public final class ExpoRequestInterceptorProtocol: URLProtocol, URLSessionDataDe
|
|
|
137
126
|
if let requestId = URLProtocol.property(forKey: Self.REQUEST_ID, in: request) as? String {
|
|
138
127
|
Self.delegate.willSendRequest(
|
|
139
128
|
requestId: requestId,
|
|
129
|
+
task: task,
|
|
140
130
|
request: request,
|
|
141
131
|
redirectResponse: response
|
|
142
132
|
)
|
|
@@ -173,11 +163,8 @@ public final class ExpoRequestInterceptorProtocol: URLProtocol, URLSessionDataDe
|
|
|
173
163
|
@objc(EXRequestInterceptorProtocolDelegate)
|
|
174
164
|
protocol ExpoRequestInterceptorProtocolDelegate {
|
|
175
165
|
@objc
|
|
176
|
-
func willSendRequest(requestId: String, request: URLRequest, redirectResponse: HTTPURLResponse?)
|
|
177
|
-
|
|
178
|
-
@objc
|
|
179
|
-
func didReceiveResponse(requestId: String, request: URLRequest, response: HTTPURLResponse)
|
|
166
|
+
func willSendRequest(requestId: String, task: URLSessionTask, request: URLRequest, redirectResponse: HTTPURLResponse?)
|
|
180
167
|
|
|
181
168
|
@objc
|
|
182
|
-
func
|
|
169
|
+
func didReceiveResponse(requestId: String, task: URLSessionTask, responseBody: Data, isText: Bool, responseBodyExceedsLimit: Bool)
|
|
183
170
|
}
|
|
@@ -77,22 +77,24 @@ final class ExpoRequestCdpInterceptorSpec: ExpoSpec {
|
|
|
77
77
|
expect(params["requestId"] as? String).to(equal(requestId))
|
|
78
78
|
expect(response["status"] as? Int).to(equal(200))
|
|
79
79
|
expect((response["headers"] as! [String: Any]).count).to(beGreaterThan(0))
|
|
80
|
+
expect(response["encodedDataLength"] as? Int64).to(beGreaterThan(0))
|
|
80
81
|
|
|
81
|
-
// Network.
|
|
82
|
+
// Expo(Network.receivedResponseBody)
|
|
82
83
|
json = self.parseJSON(data: self.mockDelegate.events[3])
|
|
83
84
|
method = json["method"] as! String
|
|
84
85
|
params = json["params"] as! [String: Any]
|
|
85
|
-
expect(method).to(equal("Network.
|
|
86
|
+
expect(method).to(equal("Expo(Network.receivedResponseBody)"))
|
|
86
87
|
expect(params["requestId"] as? String).to(equal(requestId))
|
|
88
|
+
expect(params["body"] as? String).notTo(beEmpty())
|
|
89
|
+
expect(params["base64Encoded"] as? Bool).to(beFalse())
|
|
87
90
|
|
|
88
|
-
//
|
|
91
|
+
// Network.loadingFinished
|
|
89
92
|
json = self.parseJSON(data: self.mockDelegate.events[4])
|
|
90
93
|
method = json["method"] as! String
|
|
91
94
|
params = json["params"] as! [String: Any]
|
|
92
|
-
expect(method).to(equal("
|
|
95
|
+
expect(method).to(equal("Network.loadingFinished"))
|
|
93
96
|
expect(params["requestId"] as? String).to(equal(requestId))
|
|
94
|
-
expect(params["
|
|
95
|
-
expect(params["base64Encoded"] as? Bool).to(beFalse())
|
|
97
|
+
expect(params["encodedDataLength"] as? Int64).to(beGreaterThan(0))
|
|
96
98
|
|
|
97
99
|
done()
|
|
98
100
|
}
|
|
@@ -145,10 +147,8 @@ final class ExpoRequestCdpInterceptorSpec: ExpoSpec {
|
|
|
145
147
|
expect(response["mimeType"] as? String).to(equal("image/png"))
|
|
146
148
|
expect((response["headers"] as! [String: Any]).count).to(beGreaterThan(0))
|
|
147
149
|
|
|
148
|
-
// Network.loadingFinished
|
|
149
|
-
|
|
150
150
|
// Expo(Network.receivedResponseBody)
|
|
151
|
-
json = self.parseJSON(data: self.mockDelegate.events[
|
|
151
|
+
json = self.parseJSON(data: self.mockDelegate.events[5])
|
|
152
152
|
method = json["method"] as! String
|
|
153
153
|
params = json["params"] as! [String: Any]
|
|
154
154
|
expect(method).to(equal("Expo(Network.receivedResponseBody)"))
|
|
@@ -156,13 +156,14 @@ final class ExpoRequestCdpInterceptorSpec: ExpoSpec {
|
|
|
156
156
|
expect(params["body"] as? String).notTo(beEmpty())
|
|
157
157
|
expect(params["base64Encoded"] as? Bool).to(beTrue())
|
|
158
158
|
|
|
159
|
+
// Network.loadingFinished
|
|
160
|
+
|
|
159
161
|
done()
|
|
160
162
|
}
|
|
161
163
|
}.resume()
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
|
|
166
167
|
it("respect image mimeType to CDP event") {
|
|
167
168
|
waitUntil(timeout: .seconds(2)) { done in
|
|
168
169
|
self.session.dataTask(with: URL(string: "https://avatars.githubusercontent.com/u/12504344")!) { (data, response, error) in
|
|
@@ -187,5 +188,29 @@ final class ExpoRequestCdpInterceptorSpec: ExpoSpec {
|
|
|
187
188
|
}.resume()
|
|
188
189
|
}
|
|
189
190
|
}
|
|
191
|
+
|
|
192
|
+
it("skip `receivedResponseBody` when response size exceeding 1MB limit") {
|
|
193
|
+
waitUntil(timeout: .seconds(5)) { done in
|
|
194
|
+
self.session.dataTask(with: URL(string: "https://raw.githubusercontent.com/expo/expo/main/apps/native-component-list/assets/videos/ace.mp4")!) { (data, response, error) in
|
|
195
|
+
DispatchQueue.main.async {
|
|
196
|
+
expect(self.mockDelegate.events.count).to(equal(4))
|
|
197
|
+
|
|
198
|
+
var json = self.parseJSON(data: self.mockDelegate.events[0])
|
|
199
|
+
expect(json["method"] as! String).to(equal("Network.requestWillBeSent"))
|
|
200
|
+
|
|
201
|
+
json = self.parseJSON(data: self.mockDelegate.events[1])
|
|
202
|
+
expect(json["method"] as! String).to(equal("Network.requestWillBeSentExtraInfo"))
|
|
203
|
+
|
|
204
|
+
json = self.parseJSON(data: self.mockDelegate.events[2])
|
|
205
|
+
expect(json["method"] as! String).to(equal("Network.responseReceived"))
|
|
206
|
+
|
|
207
|
+
json = self.parseJSON(data: self.mockDelegate.events[3])
|
|
208
|
+
expect(json["method"] as! String).to(equal("Network.loadingFinished"))
|
|
209
|
+
|
|
210
|
+
done()
|
|
211
|
+
}
|
|
212
|
+
}.resume()
|
|
213
|
+
}
|
|
214
|
+
}
|
|
190
215
|
}
|
|
191
216
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-modules-core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "The core of Expo Modules architecture",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@testing-library/react-hooks": "^7.0.1",
|
|
43
43
|
"expo-module-scripts": "^3.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "8fdc53c90c52242a80ea511ee3073d9ab950bc68"
|
|
46
46
|
}
|