react-native-worklets 0.7.2 → 0.8.0-bundle-mode-preview-1
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/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +32 -28
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +13 -5
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +7 -5
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +5 -4
- package/Common/cpp/worklets/Resources/SynchronizableUnpacker.cpp +5 -5
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +42 -19
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +2 -0
- package/Common/cpp/worklets/Tools/Defs.h +2 -2
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +34 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +24 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +11 -6
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +82 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +12 -0
- package/RNWorklets.podspec +15 -14
- package/android/CMakeLists.txt +8 -2
- package/android/build.gradle +92 -56
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +67 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.h +48 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +52 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +43 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +115 -19
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +11 -13
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +6 -0
- package/android/src/main/java/com/swmansion/worklets/ScriptBufferWrapper.java +88 -0
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +23 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +30 -0
- package/android/src/{legacyBundling → networking}/com/swmansion/worklets/WorkletsModule.java +52 -2
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +268 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +1084 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +37 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +9 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +98 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +57 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +82 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +177 -0
- package/android/src/{experimentalBundling → no-networking}/com/swmansion/worklets/WorkletsModule.java +10 -15
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +22 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +706 -0
- package/apple/worklets/apple/WorkletsModule.mm +56 -17
- package/bundleMode/index.js +2 -6
- package/compatibility.json +4 -1
- package/lib/module/WorkletsModule/NativeWorklets.native.js +8 -2
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
- package/lib/module/bundleMode/metroOverrides.native.js +115 -0
- package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
- package/lib/module/bundleMode/network.native.js +41 -0
- package/lib/module/bundleMode/network.native.js.map +1 -0
- package/lib/module/debug/jsVersion.js +1 -1
- package/lib/module/debug/jsVersion.js.map +1 -1
- package/lib/module/featureFlags/staticFlags.json +2 -0
- package/lib/module/featureFlags/types.js +3 -1
- package/lib/module/featureFlags/types.js.map +1 -1
- package/lib/module/index.js +4 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/initializers/initializers.native.js +24 -50
- package/lib/module/initializers/initializers.native.js.map +1 -1
- package/lib/module/initializers/workletRuntimeEntry.native.js +3 -3
- package/lib/module/initializers/workletRuntimeEntry.native.js.map +1 -1
- package/lib/module/memory/bundleUnpacker.native.js +2 -2
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -1
- package/lib/module/memory/serializable.native.js +3 -3
- package/lib/module/memory/serializable.native.js.map +1 -1
- package/lib/module/memory/synchronizableUnpacker.native.js +3 -3
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -1
- package/lib/module/platformChecker.js +2 -2
- package/lib/module/platformChecker.js.map +1 -1
- package/lib/module/runtimeKind.js +51 -0
- package/lib/module/runtimeKind.js.map +1 -1
- package/lib/module/runtimes.js +3 -0
- package/lib/module/runtimes.js.map +1 -1
- package/lib/module/runtimes.native.js +34 -3
- package/lib/module/runtimes.native.js.map +1 -1
- package/lib/module/threads.native.js +2 -2
- package/lib/module/threads.native.js.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +2 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts +28 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts.map +1 -0
- package/lib/typescript/bundleMode/network.native.d.ts +7 -0
- package/lib/typescript/bundleMode/network.native.d.ts.map +1 -0
- package/lib/typescript/debug/jsVersion.d.ts +1 -1
- package/lib/typescript/debug/jsVersion.d.ts.map +1 -1
- package/lib/typescript/featureFlags/types.d.ts +3 -1
- package/lib/typescript/featureFlags/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/initializers/initializers.native.d.ts +1 -0
- package/lib/typescript/initializers/initializers.native.d.ts.map +1 -1
- package/lib/typescript/initializers/workletRuntimeEntry.native.d.ts +1 -1
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/platformChecker.d.ts.map +1 -1
- package/lib/typescript/runtimeKind.d.ts +31 -0
- package/lib/typescript/runtimeKind.d.ts.map +1 -1
- package/lib/typescript/runtimes.d.ts +1 -0
- package/lib/typescript/runtimes.d.ts.map +1 -1
- package/lib/typescript/runtimes.native.d.ts +20 -2
- package/lib/typescript/runtimes.native.d.ts.map +1 -1
- package/lib/typescript/threads.native.d.ts +1 -1
- package/package.json +8 -6
- package/plugin/index.d.ts +109 -0
- package/plugin/index.js +59 -9
- package/scripts/worklets_utils.rb +21 -5
- package/src/WorkletsModule/NativeWorklets.native.ts +14 -4
- package/src/WorkletsModule/workletsModuleProxy.ts +6 -3
- package/src/bundleMode/metroOverrides.native.ts +151 -0
- package/src/bundleMode/network.native.ts +59 -0
- package/src/debug/jsVersion.ts +1 -1
- package/src/featureFlags/staticFlags.json +2 -0
- package/src/featureFlags/types.ts +3 -1
- package/src/index.ts +10 -1
- package/src/initializers/initializers.native.ts +29 -70
- package/src/initializers/workletRuntimeEntry.native.ts +3 -3
- package/src/memory/bundleUnpacker.native.ts +2 -4
- package/src/memory/serializable.native.ts +3 -3
- package/src/memory/synchronizableUnpacker.native.ts +6 -12
- package/src/platformChecker.ts +3 -2
- package/src/privateGlobals.d.ts +7 -2
- package/src/runtimeKind.ts +47 -0
- package/src/runtimes.native.ts +43 -2
- package/src/runtimes.ts +10 -0
- package/src/threads.native.ts +2 -2
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on NetworkEventUtil.kt from React Native
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@file:Suppress("DEPRECATION_ERROR") // Conflicting okhttp versions
|
|
6
|
+
|
|
7
|
+
package com.swmansion.worklets
|
|
8
|
+
|
|
9
|
+
import android.os.Bundle
|
|
10
|
+
import android.util.Base64
|
|
11
|
+
import com.facebook.react.bridge.Arguments
|
|
12
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
13
|
+
import com.facebook.react.bridge.WritableMap
|
|
14
|
+
import com.facebook.react.bridge.buildReadableArray
|
|
15
|
+
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
|
|
16
|
+
import java.net.SocketTimeoutException
|
|
17
|
+
import okhttp3.Headers
|
|
18
|
+
import okhttp3.Protocol
|
|
19
|
+
import okhttp3.Request
|
|
20
|
+
import okhttp3.Response
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Utility class for reporting network lifecycle events to JavaScript and InspectorNetworkReporter.
|
|
24
|
+
*/
|
|
25
|
+
internal object WorkletsNetworkEventUtil {
|
|
26
|
+
@JvmStatic
|
|
27
|
+
fun onCreateRequest(devToolsRequestId: String, request: Request) {
|
|
28
|
+
if (ReactNativeFeatureFlags.enableNetworkEventReporting()) {
|
|
29
|
+
val headersMap = okHttpHeadersToMap(request.headers())
|
|
30
|
+
// InspectorNetworkReporter.reportRequestStart(
|
|
31
|
+
// devToolsRequestId,
|
|
32
|
+
// request.url().toString(),
|
|
33
|
+
// request.method(),
|
|
34
|
+
// headersMap,
|
|
35
|
+
// (request.body() as? ProgressRequestBody)?.getBodyPreview()
|
|
36
|
+
// ?: request.body()?.toString().orEmpty(),
|
|
37
|
+
// request.body()?.contentLength() ?: 0,
|
|
38
|
+
// )
|
|
39
|
+
// InspectorNetworkReporter.reportConnectionTiming(devToolsRequestId, headersMap)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@JvmStatic
|
|
44
|
+
fun onDataSend(
|
|
45
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
46
|
+
requestId: Int,
|
|
47
|
+
progress: Long,
|
|
48
|
+
total: Long,
|
|
49
|
+
) {
|
|
50
|
+
runtimeWrapper.emitDeviceEvent(
|
|
51
|
+
"didSendNetworkData",
|
|
52
|
+
buildReadableArray {
|
|
53
|
+
add(requestId)
|
|
54
|
+
add(progress.toInt())
|
|
55
|
+
add(total.toInt())
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@JvmStatic
|
|
61
|
+
fun onIncrementalDataReceived(
|
|
62
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
63
|
+
requestId: Int,
|
|
64
|
+
devToolsRequestId: String,
|
|
65
|
+
data: String?,
|
|
66
|
+
progress: Long,
|
|
67
|
+
total: Long,
|
|
68
|
+
) {
|
|
69
|
+
// if (ReactNativeFeatureFlags.enableNetworkEventReporting() && data != null) {
|
|
70
|
+
// InspectorNetworkReporter.reportDataReceived(devToolsRequestId, data)
|
|
71
|
+
// InspectorNetworkReporter.maybeStoreResponseBodyIncremental(devToolsRequestId, data)
|
|
72
|
+
// }
|
|
73
|
+
runtimeWrapper.emitDeviceEvent(
|
|
74
|
+
"didReceiveNetworkIncrementalData",
|
|
75
|
+
buildReadableArray {
|
|
76
|
+
add(requestId)
|
|
77
|
+
add(data)
|
|
78
|
+
add(progress.toInt())
|
|
79
|
+
add(total.toInt())
|
|
80
|
+
},
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@JvmStatic
|
|
85
|
+
fun onDataReceivedProgress(
|
|
86
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
87
|
+
requestId: Int,
|
|
88
|
+
progress: Long,
|
|
89
|
+
total: Long,
|
|
90
|
+
) {
|
|
91
|
+
runtimeWrapper.emitDeviceEvent(
|
|
92
|
+
"didReceiveNetworkDataProgress",
|
|
93
|
+
buildReadableArray {
|
|
94
|
+
add(requestId)
|
|
95
|
+
add(progress.toInt())
|
|
96
|
+
add(total.toInt())
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@JvmStatic
|
|
102
|
+
fun onDataReceived(
|
|
103
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
104
|
+
requestId: Int,
|
|
105
|
+
devToolsRequestId: String,
|
|
106
|
+
data: String?,
|
|
107
|
+
responseType: String,
|
|
108
|
+
) {
|
|
109
|
+
// if (ReactNativeFeatureFlags.enableNetworkEventReporting()) {
|
|
110
|
+
// InspectorNetworkReporter.maybeStoreResponseBody(
|
|
111
|
+
// devToolsRequestId,
|
|
112
|
+
// data.orEmpty(),
|
|
113
|
+
// responseType == "base64",
|
|
114
|
+
// )
|
|
115
|
+
// }
|
|
116
|
+
runtimeWrapper.emitDeviceEvent(
|
|
117
|
+
"didReceiveNetworkData",
|
|
118
|
+
buildReadableArray {
|
|
119
|
+
add(requestId)
|
|
120
|
+
add(data)
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@JvmStatic
|
|
126
|
+
fun onDataReceived(
|
|
127
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
128
|
+
requestId: Int,
|
|
129
|
+
devToolsRequestId: String,
|
|
130
|
+
data: WritableMap,
|
|
131
|
+
rawData: ByteArray,
|
|
132
|
+
) {
|
|
133
|
+
// if (ReactNativeFeatureFlags.enableNetworkEventReporting()) {
|
|
134
|
+
// InspectorNetworkReporter.maybeStoreResponseBody(
|
|
135
|
+
// devToolsRequestId,
|
|
136
|
+
// Base64.encodeToString(rawData, Base64.NO_WRAP),
|
|
137
|
+
// true,
|
|
138
|
+
// )
|
|
139
|
+
// }
|
|
140
|
+
runtimeWrapper.emitDeviceEvent(
|
|
141
|
+
"didReceiveNetworkData",
|
|
142
|
+
Arguments.createArray().apply {
|
|
143
|
+
pushInt(requestId)
|
|
144
|
+
pushMap(data)
|
|
145
|
+
},
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@JvmStatic
|
|
150
|
+
fun onRequestError(
|
|
151
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
152
|
+
requestId: Int,
|
|
153
|
+
devToolsRequestId: String,
|
|
154
|
+
error: String?,
|
|
155
|
+
e: Throwable?,
|
|
156
|
+
) {
|
|
157
|
+
runtimeWrapper.emitDeviceEvent(
|
|
158
|
+
"didCompleteNetworkResponse",
|
|
159
|
+
buildReadableArray {
|
|
160
|
+
add(requestId)
|
|
161
|
+
add(error)
|
|
162
|
+
if (e?.javaClass == SocketTimeoutException::class.java) {
|
|
163
|
+
add(true) // last argument is a time out boolean
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@JvmStatic
|
|
170
|
+
fun onRequestSuccess(
|
|
171
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
172
|
+
requestId: Int,
|
|
173
|
+
devToolsRequestId: String,
|
|
174
|
+
encodedDataLength: Long,
|
|
175
|
+
) {
|
|
176
|
+
runtimeWrapper.emitDeviceEvent(
|
|
177
|
+
"didCompleteNetworkResponse",
|
|
178
|
+
buildReadableArray {
|
|
179
|
+
add(requestId)
|
|
180
|
+
addNull()
|
|
181
|
+
},
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@JvmStatic
|
|
186
|
+
fun onResponseReceived(
|
|
187
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
188
|
+
requestId: Int,
|
|
189
|
+
devToolsRequestId: String,
|
|
190
|
+
requestUrl: String?,
|
|
191
|
+
response: Response,
|
|
192
|
+
) {
|
|
193
|
+
val headersMap = okHttpHeadersToMap(response.headers())
|
|
194
|
+
val headersBundle = Bundle()
|
|
195
|
+
for ((headerName, headerValue) in headersMap) {
|
|
196
|
+
headersBundle.putString(headerName, headerValue)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// if (ReactNativeFeatureFlags.enableNetworkEventReporting()) {
|
|
200
|
+
// InspectorNetworkReporter.reportResponseStart(
|
|
201
|
+
// devToolsRequestId,
|
|
202
|
+
// requestUrl.orEmpty(),
|
|
203
|
+
// response.code(),
|
|
204
|
+
// headersMap,
|
|
205
|
+
// response.body()?.contentLength() ?: 0,
|
|
206
|
+
// )
|
|
207
|
+
// }
|
|
208
|
+
runtimeWrapper.emitDeviceEvent(
|
|
209
|
+
"didReceiveNetworkResponse",
|
|
210
|
+
Arguments.createArray().apply {
|
|
211
|
+
pushInt(requestId)
|
|
212
|
+
pushInt(response.code())
|
|
213
|
+
pushMap(Arguments.fromBundle(headersBundle))
|
|
214
|
+
pushString(requestUrl)
|
|
215
|
+
},
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@Deprecated("Compatibility overload")
|
|
220
|
+
@JvmStatic
|
|
221
|
+
fun onResponseReceived(
|
|
222
|
+
runtimeWrapper: WorkletRuntimeWrapper,
|
|
223
|
+
requestId: Int,
|
|
224
|
+
devToolsRequestId: String,
|
|
225
|
+
statusCode: Int,
|
|
226
|
+
headers: WritableMap?,
|
|
227
|
+
url: String?,
|
|
228
|
+
) {
|
|
229
|
+
val headersBuilder = Headers.Builder()
|
|
230
|
+
headers?.let { map ->
|
|
231
|
+
val iterator = map.keySetIterator()
|
|
232
|
+
while (iterator.hasNextKey()) {
|
|
233
|
+
val key = iterator.nextKey()
|
|
234
|
+
val value = map.getString(key)
|
|
235
|
+
if (value != null) {
|
|
236
|
+
headersBuilder.add(key, value)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
onResponseReceived(
|
|
241
|
+
runtimeWrapper,
|
|
242
|
+
requestId,
|
|
243
|
+
devToolsRequestId,
|
|
244
|
+
url,
|
|
245
|
+
Response.Builder()
|
|
246
|
+
.protocol(Protocol.HTTP_1_1)
|
|
247
|
+
.request(Request.Builder().url(url.orEmpty()).build())
|
|
248
|
+
.headers(headersBuilder.build())
|
|
249
|
+
.code(statusCode)
|
|
250
|
+
.message("")
|
|
251
|
+
.build(),
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private fun okHttpHeadersToMap(headers: Headers): Map<String, String> {
|
|
256
|
+
val responseHeaders = mutableMapOf<String, String>()
|
|
257
|
+
for (i in 0 until headers.size()) {
|
|
258
|
+
val headerName = headers.name(i)
|
|
259
|
+
// multiple values for the same header
|
|
260
|
+
if (responseHeaders.containsKey(headerName)) {
|
|
261
|
+
responseHeaders[headerName] = "${responseHeaders[headerName]}, ${headers.value(i)}"
|
|
262
|
+
} else {
|
|
263
|
+
responseHeaders[headerName] = headers.value(i)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return responseHeaders
|
|
267
|
+
}
|
|
268
|
+
}
|