expo-modules-core 3.0.11 → 3.0.13
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 +13 -0
- package/android/build.gradle +2 -2
- package/android/src/main/cpp/JavaCallback.h +1 -1
- package/android/src/main/cpp/MethodMetadata.cpp +1 -1
- package/android/src/main/java/expo/modules/kotlin/AppContext.kt +10 -3
- package/android/src/main/java/expo/modules/kotlin/{modules/ModuleUtils.kt → EnumExtensions.kt} +6 -7
- package/android/src/main/java/expo/modules/kotlin/KClassExtensions.kt +10 -0
- package/android/src/main/java/expo/modules/kotlin/ReadableTypeExtensions.kt +8 -9
- package/android/src/main/java/expo/modules/kotlin/defaultmodules/JSLoggerModule.kt +92 -0
- package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +2 -2
- package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +3 -2
- package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +5 -5
- package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObjectTypeConverter.kt +1 -2
- package/android/src/main/java/expo/modules/kotlin/types/EnumTypeConverter.kt +7 -6
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/sweet/{NativeErrorManager.d.ts → NativeJSLogger.d.ts} +1 -1
- package/build/sweet/NativeJSLogger.d.ts.map +1 -0
- package/build/sweet/setUpJsLogger.fx.d.ts +2 -0
- package/build/sweet/setUpJsLogger.fx.d.ts.map +1 -0
- package/build/sweet/setUpJsLogger.fx.web.d.ts +2 -0
- package/build/sweet/setUpJsLogger.fx.web.d.ts.map +1 -0
- package/ios/Core/AppContext.swift +11 -0
- package/ios/Core/Modules/JSLoggerModule.swift +65 -0
- package/ios/JSI/EXJSIConversions.mm +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/sweet/NativeJSLogger.ts +3 -0
- package/src/sweet/setUpJsLogger.fx.ts +56 -0
- package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +0 -34
- package/build/sweet/NativeErrorManager.d.ts.map +0 -1
- package/build/sweet/setUpErrorManager.fx.d.ts +0 -2
- package/build/sweet/setUpErrorManager.fx.d.ts.map +0 -1
- package/build/sweet/setUpErrorManager.fx.web.d.ts +0 -2
- package/build/sweet/setUpErrorManager.fx.web.d.ts.map +0 -1
- package/src/sweet/NativeErrorManager.ts +0 -3
- package/src/sweet/setUpErrorManager.fx.ts +0 -23
- /package/src/sweet/{setUpErrorManager.fx.web.ts → setUpJsLogger.fx.web.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -10,11 +10,24 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 3.0.13 — 2025-09-04
|
|
14
|
+
|
|
15
|
+
### 💡 Others
|
|
16
|
+
|
|
17
|
+
- [Android] Remove some usage of `kotlin.reflect.full.*`. ([#39385](https://github.com/expo/expo/pull/39385) by [@lukmccall](https://github.com/lukmccall))
|
|
18
|
+
|
|
19
|
+
## 3.0.12 — 2025-09-03
|
|
20
|
+
|
|
21
|
+
### 💡 Others
|
|
22
|
+
|
|
23
|
+
- Use new LongLivedObject.h and CallbackWrapper.h headers namespace ([#39344](https://github.com/expo/expo/pull/39344) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
24
|
+
|
|
13
25
|
## 3.0.11 — 2025-09-02
|
|
14
26
|
|
|
15
27
|
### 🎉 New features
|
|
16
28
|
|
|
17
29
|
- Add `disableForceFlatten` prop to control flattening of display contents views. ([#39262](https://github.com/expo/expo/pull/39262) by [@nishan](https://github.com/intergalacticspacehighway))
|
|
30
|
+
- Add logging from native to JS, compliant with the Logger interface, via `appContext.jsLogger`. ([#39159](https://github.com/expo/expo/pull/39159) by [@behenate](https://github.com/behenate))
|
|
18
31
|
|
|
19
32
|
### 🐛 Bug fixes
|
|
20
33
|
|
package/android/build.gradle
CHANGED
|
@@ -25,7 +25,7 @@ if (shouldIncludeCompose) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
group = 'host.exp.exponent'
|
|
28
|
-
version = '3.0.
|
|
28
|
+
version = '3.0.13'
|
|
29
29
|
|
|
30
30
|
def isExpoModulesCoreTests = {
|
|
31
31
|
Gradle gradle = getGradle()
|
|
@@ -75,7 +75,7 @@ android {
|
|
|
75
75
|
defaultConfig {
|
|
76
76
|
consumerProguardFiles 'proguard-rules.pro'
|
|
77
77
|
versionCode 1
|
|
78
|
-
versionName "3.0.
|
|
78
|
+
versionName "3.0.13"
|
|
79
79
|
buildConfigField "String", "EXPO_MODULES_CORE_VERSION", "\"${versionName}\""
|
|
80
80
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled.toString()
|
|
81
81
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
#include <react/jni/WritableNativeMap.h>
|
|
15
15
|
#include <fbjni/detail/CoreClasses.h>
|
|
16
16
|
#include <ReactCommon/CallInvoker.h>
|
|
17
|
-
#include <
|
|
17
|
+
#include <react/bridging/LongLivedObject.h>
|
|
18
18
|
|
|
19
19
|
namespace jni = facebook::jni;
|
|
20
20
|
namespace react = facebook::react;
|
|
@@ -29,6 +29,7 @@ import expo.modules.kotlin.activityresult.DefaultAppContextActivityResultCaller
|
|
|
29
29
|
import expo.modules.kotlin.defaultmodules.AppDirectoriesModule
|
|
30
30
|
import expo.modules.kotlin.defaultmodules.ErrorManagerModule
|
|
31
31
|
import expo.modules.kotlin.defaultmodules.FilePermissionModule
|
|
32
|
+
import expo.modules.kotlin.defaultmodules.JSLoggerModule
|
|
32
33
|
import expo.modules.kotlin.defaultmodules.NativeModulesProxyModule
|
|
33
34
|
import expo.modules.kotlin.events.EventEmitter
|
|
34
35
|
import expo.modules.kotlin.events.EventName
|
|
@@ -109,8 +110,8 @@ class AppContext(
|
|
|
109
110
|
// Registering modules has to happen at the very end of `AppContext` creation. Some modules need to access
|
|
110
111
|
// `AppContext` during their initialisation, so we need to ensure all `AppContext`'s
|
|
111
112
|
// properties are initialized first. Not having that would trigger NPE.
|
|
112
|
-
registry.register(ErrorManagerModule())
|
|
113
113
|
registry.register(NativeModulesProxyModule())
|
|
114
|
+
registry.register(JSLoggerModule())
|
|
114
115
|
|
|
115
116
|
// Registering modules that were previously provided by legacy FileSystem module.
|
|
116
117
|
legacyModuleRegistry.registerInternalModule(FilePermissionModule())
|
|
@@ -248,8 +249,14 @@ class AppContext(
|
|
|
248
249
|
return KEventEmitterWrapper(legacyEventEmitter, hostingRuntimeContext.reactContextHolder)
|
|
249
250
|
}
|
|
250
251
|
|
|
251
|
-
|
|
252
|
-
|
|
252
|
+
@Deprecated("Use AppContext.jsLogger instead")
|
|
253
|
+
val errorManager: ErrorManagerModule? by lazy {
|
|
254
|
+
hostingRuntimeContext.registry.getModule()
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
val jsLogger by lazy {
|
|
258
|
+
hostingRuntimeContext.registry.getModule<JSLoggerModule>()?.logger
|
|
259
|
+
}
|
|
253
260
|
|
|
254
261
|
internal fun onDestroy() = trace("AppContext.onDestroy") {
|
|
255
262
|
hostingRuntimeContext.reactContext?.removeLifecycleEventListener(reactLifecycleDelegate)
|
package/android/src/main/java/expo/modules/kotlin/{modules/ModuleUtils.kt → EnumExtensions.kt}
RENAMED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
package expo.modules.kotlin
|
|
1
|
+
package expo.modules.kotlin
|
|
2
2
|
|
|
3
3
|
import expo.modules.kotlin.types.Enumerable
|
|
4
4
|
import kotlin.reflect.KProperty1
|
|
5
5
|
import kotlin.reflect.full.declaredMemberProperties
|
|
6
|
-
import kotlin.reflect.full.primaryConstructor
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
val enumClass =
|
|
10
|
-
val primaryConstructor = enumClass.
|
|
7
|
+
fun <T> T.convertToString(): String where T : Enum<T>, T : Enumerable {
|
|
8
|
+
val enumClass = this::class
|
|
9
|
+
val primaryConstructor = enumClass.fastPrimaryConstructor
|
|
11
10
|
if (primaryConstructor?.parameters?.size == 1) {
|
|
12
11
|
val parameterName = primaryConstructor.parameters.first().name
|
|
13
12
|
val parameterProperty = enumClass
|
|
@@ -18,8 +17,8 @@ internal fun <T> convertEnumToString(enumValue: T): String where T : Enumerable,
|
|
|
18
17
|
require(parameterProperty.returnType.classifier == String::class) { "The enum parameter has to be a string." }
|
|
19
18
|
|
|
20
19
|
@Suppress("UNCHECKED_CAST")
|
|
21
|
-
return (parameterProperty as KProperty1<T, String>).get(
|
|
20
|
+
return (parameterProperty as KProperty1<T, String>).get(this)
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
return
|
|
23
|
+
return this.name
|
|
25
24
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
package expo.modules.kotlin
|
|
2
|
+
|
|
3
|
+
import kotlin.reflect.KClass
|
|
4
|
+
import kotlin.reflect.KFunction
|
|
5
|
+
import kotlin.reflect.full.primaryConstructor
|
|
6
|
+
|
|
7
|
+
val <T : Any> KClass<T>.fastPrimaryConstructor: KFunction<T>?
|
|
8
|
+
// If class only has one constructor, use it as a primary constructor.
|
|
9
|
+
// Otherwise, try to find the primary constructor using kotlin reflection.
|
|
10
|
+
get() = constructors.singleOrNull() ?: primaryConstructor
|
|
@@ -3,16 +3,15 @@ package expo.modules.kotlin
|
|
|
3
3
|
import com.facebook.react.bridge.ReadableArray
|
|
4
4
|
import com.facebook.react.bridge.ReadableMap
|
|
5
5
|
import com.facebook.react.bridge.ReadableType
|
|
6
|
-
import kotlin.reflect.
|
|
7
|
-
import kotlin.reflect.full.createType
|
|
6
|
+
import kotlin.reflect.KClass
|
|
8
7
|
|
|
9
|
-
fun ReadableType.
|
|
8
|
+
fun ReadableType.toKClass(): KClass<*> {
|
|
10
9
|
return when (this) {
|
|
11
|
-
ReadableType.Null -> Any::class
|
|
12
|
-
ReadableType.Boolean -> Boolean::class
|
|
13
|
-
ReadableType.Number -> Number::class
|
|
14
|
-
ReadableType.String -> String::class
|
|
15
|
-
ReadableType.Map -> ReadableMap::class
|
|
16
|
-
ReadableType.Array -> ReadableArray::class
|
|
10
|
+
ReadableType.Null -> Any::class
|
|
11
|
+
ReadableType.Boolean -> Boolean::class
|
|
12
|
+
ReadableType.Number -> Number::class
|
|
13
|
+
ReadableType.String -> String::class
|
|
14
|
+
ReadableType.Map -> ReadableMap::class
|
|
15
|
+
ReadableType.Array -> ReadableArray::class
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
package expo.modules.kotlin.defaultmodules
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle
|
|
4
|
+
import expo.modules.core.logging.LogHandler
|
|
5
|
+
import expo.modules.core.logging.LogType
|
|
6
|
+
import expo.modules.core.logging.Logger
|
|
7
|
+
import expo.modules.kotlin.exception.CodedException
|
|
8
|
+
import expo.modules.kotlin.modules.Module
|
|
9
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
10
|
+
import java.lang.ref.WeakReference
|
|
11
|
+
|
|
12
|
+
private const val moduleName = "ExpoModulesCoreJSLogger"
|
|
13
|
+
private const val onNewError = "$moduleName.onNewError"
|
|
14
|
+
private const val onNewWarning = "$moduleName.onNewWarning"
|
|
15
|
+
private const val onNewDebug = "$moduleName.onNewDebug"
|
|
16
|
+
private const val onNewInfo = "$moduleName.onNewInfo"
|
|
17
|
+
private const val onNewTrace = "$moduleName.onNewTrace"
|
|
18
|
+
|
|
19
|
+
@Deprecated("Use JSLoggerModule instead")
|
|
20
|
+
typealias ErrorManagerModule = JSLoggerModule
|
|
21
|
+
|
|
22
|
+
class JSLoggerModule : Module() {
|
|
23
|
+
private class JSLogHandler(module: JSLoggerModule) : LogHandler() {
|
|
24
|
+
private val moduleReference = WeakReference(module)
|
|
25
|
+
|
|
26
|
+
override fun log(type: LogType, message: String, cause: Throwable?) {
|
|
27
|
+
val finalMessage = if (cause != null) {
|
|
28
|
+
"$message. ${cause.message}"
|
|
29
|
+
} else {
|
|
30
|
+
message
|
|
31
|
+
}
|
|
32
|
+
moduleReference.get()?.reportToLogBox(type, finalMessage)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var logger: Logger? = null
|
|
37
|
+
private set
|
|
38
|
+
|
|
39
|
+
override fun definition() = ModuleDefinition {
|
|
40
|
+
Name(moduleName)
|
|
41
|
+
|
|
42
|
+
Events(onNewError, onNewWarning, onNewDebug, onNewInfo, onNewTrace)
|
|
43
|
+
|
|
44
|
+
OnCreate {
|
|
45
|
+
val logHandler = JSLogHandler(this@JSLoggerModule)
|
|
46
|
+
logger = Logger(listOf(logHandler))
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Deprecated("Use appContext.jsLogger.warn(...) instead")
|
|
51
|
+
fun reportWarningToLogBox(warning: String) {
|
|
52
|
+
sendEvent(
|
|
53
|
+
onNewWarning,
|
|
54
|
+
createMessageBundle(warning)
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Deprecated("Use appContext.jsLogger.error(...) instead")
|
|
59
|
+
fun reportExceptionToLogBox(codedException: CodedException) {
|
|
60
|
+
sendEvent(
|
|
61
|
+
onNewError,
|
|
62
|
+
createMessageBundle(codedException.message ?: codedException.toString())
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private fun createMessageBundle(message: String): Bundle {
|
|
67
|
+
return Bundle().apply {
|
|
68
|
+
putString("message", message)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private fun reportToLogBox(type: LogType, message: String) {
|
|
73
|
+
sendEvent(
|
|
74
|
+
type.eventName,
|
|
75
|
+
Bundle().apply {
|
|
76
|
+
putString("message", message)
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private val LogType.eventName: String
|
|
83
|
+
get() = when (this) {
|
|
84
|
+
LogType.Trace -> onNewTrace
|
|
85
|
+
LogType.Timer -> onNewDebug
|
|
86
|
+
LogType.Stacktrace -> onNewTrace
|
|
87
|
+
LogType.Debug -> onNewDebug
|
|
88
|
+
LogType.Info -> onNewInfo
|
|
89
|
+
LogType.Warn -> onNewWarning
|
|
90
|
+
LogType.Error -> onNewError
|
|
91
|
+
LogType.Fatal -> onNewError
|
|
92
|
+
}
|
|
@@ -71,8 +71,8 @@ inline fun <reified T : CodedException> errorCodeOf(): String =
|
|
|
71
71
|
CodedException.inferCode(T::class.java)
|
|
72
72
|
|
|
73
73
|
internal class IncompatibleArgTypeException(
|
|
74
|
-
argumentType:
|
|
75
|
-
desiredType:
|
|
74
|
+
argumentType: KClass<*>,
|
|
75
|
+
desiredType: KClass<*>,
|
|
76
76
|
cause: Throwable? = null
|
|
77
77
|
) : CodedException(
|
|
78
78
|
message = "Argument type '$argumentType' is not compatible with expected type '$desiredType'.",
|
|
@@ -3,6 +3,7 @@ package expo.modules.kotlin.modules
|
|
|
3
3
|
import android.os.Bundle
|
|
4
4
|
import expo.modules.kotlin.AppContext
|
|
5
5
|
import expo.modules.kotlin.RuntimeContext
|
|
6
|
+
import expo.modules.kotlin.convertToString
|
|
6
7
|
import expo.modules.kotlin.providers.AppContextProvider
|
|
7
8
|
import expo.modules.kotlin.tracing.trace
|
|
8
9
|
import expo.modules.kotlin.types.Enumerable
|
|
@@ -44,11 +45,11 @@ abstract class Module : AppContextProvider {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
fun <T> sendEvent(enum: T, body: Bundle? = Bundle.EMPTY) where T : Enumerable, T : Enum<T> {
|
|
47
|
-
moduleEventEmitter?.emit(
|
|
48
|
+
moduleEventEmitter?.emit(enum.convertToString(), body)
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
fun <T> sendEvent(enum: T, body: Map<String, Any?>? = null) where T : Enumerable, T : Enum<T> {
|
|
51
|
-
moduleEventEmitter?.emit(
|
|
52
|
+
moduleEventEmitter?.emit(enum.convertToString(), body)
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
open fun converters(): TypeConverterProvider? = null
|
|
@@ -7,7 +7,9 @@ import expo.modules.kotlin.Promise
|
|
|
7
7
|
import expo.modules.kotlin.component6
|
|
8
8
|
import expo.modules.kotlin.component7
|
|
9
9
|
import expo.modules.kotlin.component8
|
|
10
|
+
import expo.modules.kotlin.convertToString
|
|
10
11
|
import expo.modules.kotlin.events.EventsDefinition
|
|
12
|
+
import expo.modules.kotlin.fastPrimaryConstructor
|
|
11
13
|
import expo.modules.kotlin.functions.AsyncFunctionComponent
|
|
12
14
|
import expo.modules.kotlin.functions.AsyncFunctionBuilder
|
|
13
15
|
import expo.modules.kotlin.functions.AsyncFunctionWithPromiseComponent
|
|
@@ -18,14 +20,12 @@ import expo.modules.kotlin.jni.JavaScriptModuleObject
|
|
|
18
20
|
import expo.modules.kotlin.jni.decorators.JSDecoratorsBridgingObject
|
|
19
21
|
import expo.modules.kotlin.modules.Module
|
|
20
22
|
import expo.modules.kotlin.modules.ModuleDefinitionBuilder
|
|
21
|
-
import expo.modules.kotlin.modules.convertEnumToString
|
|
22
23
|
import expo.modules.kotlin.types.Enumerable
|
|
23
24
|
import expo.modules.kotlin.types.TypeConverterProvider
|
|
24
25
|
import expo.modules.kotlin.types.enforceType
|
|
25
26
|
import expo.modules.kotlin.types.toArgsArray
|
|
26
27
|
import expo.modules.kotlin.types.toReturnType
|
|
27
28
|
import kotlin.reflect.full.declaredMemberProperties
|
|
28
|
-
import kotlin.reflect.full.primaryConstructor
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Base class for other definitions representing an object, such as `ModuleDefinition`.
|
|
@@ -449,7 +449,7 @@ open class ObjectDefinitionBuilder(
|
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
inline fun <reified T> Events() where T : Enumerable, T : Enum<T> {
|
|
452
|
-
val primaryConstructor = T::class.
|
|
452
|
+
val primaryConstructor = T::class.fastPrimaryConstructor
|
|
453
453
|
val events = if (primaryConstructor?.parameters?.size == 1) {
|
|
454
454
|
val parameterName = primaryConstructor.parameters.first().name
|
|
455
455
|
|
|
@@ -487,7 +487,7 @@ open class ObjectDefinitionBuilder(
|
|
|
487
487
|
* Creates module's lifecycle listener that is called right after the first event listener is added for given event.
|
|
488
488
|
*/
|
|
489
489
|
fun <T> OnStartObserving(enum: T, body: () -> Unit) where T : Enumerable, T : Enum<T> {
|
|
490
|
-
OnStartObserving(
|
|
490
|
+
OnStartObserving(enum.convertToString(), body)
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
/**
|
|
@@ -520,7 +520,7 @@ open class ObjectDefinitionBuilder(
|
|
|
520
520
|
* Creates module's lifecycle listener that is called right after all event listeners are removed for given event.
|
|
521
521
|
*/
|
|
522
522
|
fun <T> OnStopObserving(enum: T, body: () -> Unit) where T : Enumerable, T : Enum<T> {
|
|
523
|
-
OnStopObserving(
|
|
523
|
+
OnStopObserving(enum.convertToString(), body)
|
|
524
524
|
}
|
|
525
525
|
|
|
526
526
|
/**
|
package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObjectTypeConverter.kt
CHANGED
|
@@ -10,7 +10,6 @@ import expo.modules.kotlin.types.NonNullableTypeConverter
|
|
|
10
10
|
import kotlin.reflect.KClass
|
|
11
11
|
import kotlin.reflect.KType
|
|
12
12
|
import kotlin.reflect.KTypeProjection
|
|
13
|
-
import kotlin.reflect.full.isSuperclassOf
|
|
14
13
|
|
|
15
14
|
class SharedObjectTypeConverter<T : SharedObject>(
|
|
16
15
|
val type: KType
|
|
@@ -74,7 +73,7 @@ class SharedRefTypeConverter<T : SharedRef<*>>(
|
|
|
74
73
|
val ref = sharedRef.ref ?: return sharedRef
|
|
75
74
|
val sharedRefClass = sharedRefType?.classifier as? KClass<*>
|
|
76
75
|
?: return sharedRef
|
|
77
|
-
if (sharedRefClass.
|
|
76
|
+
if (ref::class.java.isAssignableFrom(sharedRefClass.javaObjectType) || ref::class.java.isAssignableFrom(sharedRefClass.java)) {
|
|
78
77
|
return sharedRef
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -5,12 +5,11 @@ import expo.modules.kotlin.AppContext
|
|
|
5
5
|
import expo.modules.kotlin.exception.DynamicCastException
|
|
6
6
|
import expo.modules.kotlin.exception.EnumNoSuchValueException
|
|
7
7
|
import expo.modules.kotlin.exception.IncompatibleArgTypeException
|
|
8
|
+
import expo.modules.kotlin.fastPrimaryConstructor
|
|
8
9
|
import expo.modules.kotlin.jni.ExpectedType
|
|
9
10
|
import expo.modules.kotlin.logger
|
|
10
|
-
import expo.modules.kotlin.
|
|
11
|
+
import expo.modules.kotlin.toKClass
|
|
11
12
|
import kotlin.reflect.KClass
|
|
12
|
-
import kotlin.reflect.full.createType
|
|
13
|
-
import kotlin.reflect.full.primaryConstructor
|
|
14
13
|
|
|
15
14
|
class EnumTypeConverter(
|
|
16
15
|
private val enumClass: KClass<Enum<*>>
|
|
@@ -23,7 +22,9 @@ class EnumTypeConverter(
|
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
private val primaryConstructor = requireNotNull(
|
|
25
|
+
private val primaryConstructor = requireNotNull(
|
|
26
|
+
enumClass.fastPrimaryConstructor
|
|
27
|
+
) {
|
|
27
28
|
"Cannot convert js value to enum without the primary constructor"
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -48,7 +49,7 @@ class EnumTypeConverter(
|
|
|
48
49
|
)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
throw IncompatibleArgTypeException(value.type.
|
|
52
|
+
throw IncompatibleArgTypeException(value.type.toKClass(), enumClass)
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
override fun convertFromAny(value: Any, context: AppContext?, forceConversion: Boolean): Enum<*> {
|
|
@@ -62,7 +63,7 @@ class EnumTypeConverter(
|
|
|
62
63
|
)
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
throw IncompatibleArgTypeException(value::class
|
|
66
|
+
throw IncompatibleArgTypeException(value::class, enumClass)
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
/**
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAC;AAClC,OAAO,YAAY,CAAC;AAEpB,mBAAmB,0BAA0B,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEzC,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAElC,cAAc,QAAQ,CAAC;AAEvB,cAAc,kCAAkC,CAAC;AACjD,cAAc,UAAU,CAAC;AAGzB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeJSLogger.d.ts","sourceRoot":"","sources":["../../src/sweet/NativeJSLogger.ts"],"names":[],"mappings":";AAEA,wBAAsE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setUpJsLogger.fx.d.ts","sourceRoot":"","sources":["../../src/sweet/setUpJsLogger.fx.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setUpJsLogger.fx.web.d.ts","sourceRoot":"","sources":["../../src/sweet/setUpJsLogger.fx.web.ts"],"names":[],"mappings":""}
|
|
@@ -17,6 +17,15 @@ public final class AppContext: NSObject {
|
|
|
17
17
|
*/
|
|
18
18
|
public let config: AppContextConfig
|
|
19
19
|
|
|
20
|
+
public lazy var jsLogger: Logger = {
|
|
21
|
+
let loggerModule = self.moduleRegistry.get(moduleWithName: JSLoggerModule.name) as? JSLoggerModule
|
|
22
|
+
guard let logger = loggerModule?.logger else {
|
|
23
|
+
log.error("Failed to get the JSLoggerModule logger. Falling back to OS logger.")
|
|
24
|
+
return log
|
|
25
|
+
}
|
|
26
|
+
return logger
|
|
27
|
+
}()
|
|
28
|
+
|
|
20
29
|
/**
|
|
21
30
|
The module registry for the app context.
|
|
22
31
|
*/
|
|
@@ -126,6 +135,8 @@ public final class AppContext: NSObject {
|
|
|
126
135
|
self.config = config ?? AppContextConfig(documentDirectory: nil, cacheDirectory: nil, appGroups: appCodeSignEntitlements.appGroups)
|
|
127
136
|
|
|
128
137
|
super.init()
|
|
138
|
+
|
|
139
|
+
self.moduleRegistry.register(module: JSLoggerModule(appContext: self))
|
|
129
140
|
listenToClientAppNotifications()
|
|
130
141
|
}
|
|
131
142
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
private let onNewError = "\(JSLoggerModule.name).onNewError"
|
|
2
|
+
private let onNewWarning = "\(JSLoggerModule.name).onNewWarning"
|
|
3
|
+
private let onNewDebug = "\(JSLoggerModule.name).onNewDebug"
|
|
4
|
+
private let onNewInfo = "\(JSLoggerModule.name).onNewInfo"
|
|
5
|
+
private let onNewTrace = "\(JSLoggerModule.name).onNewTrace"
|
|
6
|
+
|
|
7
|
+
public final class JSLoggerModule: Module {
|
|
8
|
+
public static let name = "ExpoModulesCoreJSLogger"
|
|
9
|
+
|
|
10
|
+
// We could have made the JSLoggerModule implement the LogHandler interface, but the Logger
|
|
11
|
+
// holds a strong reference to the LogHandlers, which would lead to a reference cycle.
|
|
12
|
+
private class JSLogHandler: LogHandler {
|
|
13
|
+
weak var module: JSLoggerModule?
|
|
14
|
+
|
|
15
|
+
init(module: JSLoggerModule) {
|
|
16
|
+
self.module = module
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func log(type: LogType, _ message: String) {
|
|
20
|
+
module?.reportToLogBox(type: type, message)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public var logger: Logger?
|
|
25
|
+
|
|
26
|
+
public func definition() -> ModuleDefinition {
|
|
27
|
+
Name(Self.name)
|
|
28
|
+
|
|
29
|
+
Events(onNewError, onNewWarning, onNewDebug, onNewInfo, onNewTrace)
|
|
30
|
+
|
|
31
|
+
OnCreate {
|
|
32
|
+
let logHandler = JSLogHandler(module: self)
|
|
33
|
+
self.logger = Logger(logHandlers: [logHandler])
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private func reportToLogBox(type: LogType, _ message: String) {
|
|
38
|
+
self.sendEvent(type.eventName, [
|
|
39
|
+
"message": message
|
|
40
|
+
])
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private extension LogType {
|
|
45
|
+
var eventName: String {
|
|
46
|
+
switch self {
|
|
47
|
+
case .trace:
|
|
48
|
+
onNewTrace
|
|
49
|
+
case .timer:
|
|
50
|
+
onNewDebug
|
|
51
|
+
case .stacktrace:
|
|
52
|
+
onNewTrace
|
|
53
|
+
case .debug:
|
|
54
|
+
onNewDebug
|
|
55
|
+
case .info:
|
|
56
|
+
onNewInfo
|
|
57
|
+
case .warn:
|
|
58
|
+
onNewWarning
|
|
59
|
+
case .error:
|
|
60
|
+
onNewError
|
|
61
|
+
case .fatal:
|
|
62
|
+
onNewError
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
-
#import <
|
|
3
|
+
#import <react/bridging/CallbackWrapper.h>
|
|
4
4
|
#import <ExpoModulesCore/EXJavaScriptValue.h>
|
|
5
5
|
#import <ExpoModulesCore/EXJavaScriptObject.h>
|
|
6
6
|
#import <ExpoModulesCore/EXJavaScriptWeakObject.h>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-modules-core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13",
|
|
4
4
|
"description": "The core of Expo Modules architecture",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"@testing-library/react-native": "^13.2.0",
|
|
66
66
|
"expo-module-scripts": "^5.0.6"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "8cafaff8076e443e6c80e8013ec809f4f290f24d"
|
|
69
69
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import NativeJSLogger from './NativeJSLogger';
|
|
2
|
+
import Platform from '../Platform';
|
|
3
|
+
import { CodedError } from '../errors/CodedError';
|
|
4
|
+
|
|
5
|
+
type LogListener = {
|
|
6
|
+
action: (...data: any[]) => void;
|
|
7
|
+
eventName: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
if (__DEV__ && (Platform.OS === 'android' || Platform.OS === 'ios') && NativeJSLogger) {
|
|
11
|
+
const onNewException: LogListener = {
|
|
12
|
+
eventName: 'ExpoModulesCoreJSLogger.onNewError',
|
|
13
|
+
action: console.error,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const onNewWarning: LogListener = {
|
|
17
|
+
eventName: 'ExpoModulesCoreJSLogger.onNewWarning',
|
|
18
|
+
action: console.warn,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const onNewDebug: LogListener = {
|
|
22
|
+
eventName: 'ExpoModulesCoreJSLogger.onNewDebug',
|
|
23
|
+
action: console.debug,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const onNewInfo: LogListener = {
|
|
27
|
+
eventName: 'ExpoModulesCoreJSLogger.onNewInfo',
|
|
28
|
+
action: console.info,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const onNewTrace: LogListener = {
|
|
32
|
+
eventName: 'ExpoModulesCoreJSLogger.onNewTrace',
|
|
33
|
+
action: console.trace,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const listeners: LogListener[] = [
|
|
37
|
+
onNewException,
|
|
38
|
+
onNewWarning,
|
|
39
|
+
onNewDebug,
|
|
40
|
+
onNewInfo,
|
|
41
|
+
onNewTrace,
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
for (const listener of listeners) {
|
|
45
|
+
NativeJSLogger.addListener(listener.eventName, ({ message }: { message: string }) => {
|
|
46
|
+
listener.action(message);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare namespace globalThis {
|
|
52
|
+
let ExpoModulesCore_CodedError: undefined | typeof CodedError;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// We have to export `CodedError` via global object to use in later in the C++ code.
|
|
56
|
+
globalThis.ExpoModulesCore_CodedError = CodedError;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
package expo.modules.kotlin.defaultmodules
|
|
2
|
-
|
|
3
|
-
import android.os.Bundle
|
|
4
|
-
import expo.modules.kotlin.exception.CodedException
|
|
5
|
-
import expo.modules.kotlin.modules.Module
|
|
6
|
-
import expo.modules.kotlin.modules.ModuleDefinition
|
|
7
|
-
|
|
8
|
-
private const val onNewException = "ExpoModulesCoreErrorManager.onNewException"
|
|
9
|
-
private const val onNewWarning = "ExpoModulesCoreErrorManager.onNewWarning"
|
|
10
|
-
|
|
11
|
-
class ErrorManagerModule : Module() {
|
|
12
|
-
override fun definition() = ModuleDefinition {
|
|
13
|
-
Name("ExpoModulesCoreErrorManager")
|
|
14
|
-
Events(onNewException, onNewWarning)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
fun reportExceptionToLogBox(codedException: CodedException) {
|
|
18
|
-
sendEvent(
|
|
19
|
-
onNewException,
|
|
20
|
-
Bundle().apply {
|
|
21
|
-
putString("message", codedException.message ?: codedException.toString())
|
|
22
|
-
}
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
fun reportWarningToLogBox(warning: String) {
|
|
27
|
-
sendEvent(
|
|
28
|
-
onNewWarning,
|
|
29
|
-
Bundle().apply {
|
|
30
|
-
putString("message", warning)
|
|
31
|
-
}
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativeErrorManager.d.ts","sourceRoot":"","sources":["../../src/sweet/NativeErrorManager.ts"],"names":[],"mappings":";AAEA,wBAA0E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setUpErrorManager.fx.d.ts","sourceRoot":"","sources":["../../src/sweet/setUpErrorManager.fx.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setUpErrorManager.fx.web.d.ts","sourceRoot":"","sources":["../../src/sweet/setUpErrorManager.fx.web.ts"],"names":[],"mappings":""}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import NativeErrorManager from './NativeErrorManager';
|
|
2
|
-
import Platform from '../Platform';
|
|
3
|
-
import { CodedError } from '../errors/CodedError';
|
|
4
|
-
|
|
5
|
-
if (__DEV__ && Platform.OS === 'android' && NativeErrorManager) {
|
|
6
|
-
const onNewException = 'ExpoModulesCoreErrorManager.onNewException';
|
|
7
|
-
const onNewWarning = 'ExpoModulesCoreErrorManager.onNewWarning';
|
|
8
|
-
|
|
9
|
-
NativeErrorManager.addListener(onNewException, ({ message }: { message: string }) => {
|
|
10
|
-
console.error(message);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
NativeErrorManager.addListener(onNewWarning, ({ message }: { message: string }) => {
|
|
14
|
-
console.warn(message);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare namespace globalThis {
|
|
19
|
-
let ExpoModulesCore_CodedError: undefined | typeof CodedError;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// We have to export `CodedError` via global object to use in later in the C++ code.
|
|
23
|
-
globalThis.ExpoModulesCore_CodedError = CodedError;
|
|
File without changes
|