react-native-nitro-modules 0.29.8 → 0.30.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.
@@ -40,6 +40,7 @@ Pod::Spec.new do |s|
40
40
  "cpp/entrypoint/InstallNitro.hpp",
41
41
  "cpp/registry/HybridObjectRegistry.hpp",
42
42
  "cpp/jsi/JSIConverter.hpp",
43
+ "cpp/jsi/JSIHelpers.hpp",
43
44
  "cpp/platform/NitroLogger.hpp",
44
45
  "cpp/threading/Dispatcher.hpp",
45
46
  "cpp/utils/JSCallback.hpp",
@@ -13,57 +13,65 @@ import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder
13
13
  @Keep
14
14
  @OptIn(FrameworkAPI::class)
15
15
  @Suppress("KotlinJniMissingFunction")
16
- class NitroModules internal constructor(val context: ReactApplicationContext) : NitroModulesSpec(context) {
17
- private val mHybridData: HybridData
16
+ class NitroModules internal constructor(
17
+ val context: ReactApplicationContext,
18
+ ) : NitroModulesSpec(context) {
19
+ private val mHybridData: HybridData
18
20
 
19
- init {
20
- mHybridData = initHybrid()
21
- applicationContext = context
22
- }
21
+ init {
22
+ mHybridData = initHybrid()
23
+ applicationContext = context
24
+ }
23
25
 
24
- override fun getName(): String {
25
- return NAME
26
- }
26
+ override fun getName(): String {
27
+ return NAME
28
+ }
27
29
 
28
- @ReactMethod(isBlockingSynchronousMethod = true)
29
- override fun install(): String? {
30
- try {
31
- // 1. Get jsi::Runtime pointer
32
- val jsContext = context.javaScriptContextHolder
33
- ?: return "ReactApplicationContext.javaScriptContextHolder is null!"
30
+ @ReactMethod(isBlockingSynchronousMethod = true)
31
+ override fun install(): String? {
32
+ try {
33
+ // 1. Get jsi::Runtime pointer
34
+ val jsContext =
35
+ context.javaScriptContextHolder
36
+ ?: return "ReactApplicationContext.javaScriptContextHolder is null!"
34
37
 
35
- // 2. Get CallInvokerHolder
36
- val callInvokerHolder = context.jsCallInvokerHolder as? CallInvokerHolderImpl
37
- ?: return "ReactApplicationContext.jsCallInvokerHolder is null!"
38
+ // 2. Get CallInvokerHolder
39
+ val callInvokerHolder =
40
+ context.jsCallInvokerHolder as? CallInvokerHolderImpl
41
+ ?: return "ReactApplicationContext.jsCallInvokerHolder is null!"
38
42
 
39
- // 3. Install Nitro
40
- install(jsContext.get(), callInvokerHolder)
43
+ // 3. Install Nitro
44
+ install(jsContext.get(), callInvokerHolder)
41
45
 
42
- return null
43
- } catch (e: Throwable) {
44
- // ?. Something went wrong! Maybe a JNI error?
45
- return e.message
46
- }
46
+ return null
47
+ } catch (e: Throwable) {
48
+ // ?. Something went wrong! Maybe a JNI error?
49
+ return e.message
47
50
  }
51
+ }
48
52
 
49
- private external fun initHybrid(): HybridData
50
- private external fun install(jsRuntimePointer: Long, callInvokerHolder: CallInvokerHolderImpl)
53
+ private external fun initHybrid(): HybridData
51
54
 
52
- companion object {
53
- /**
54
- * The TurboModule's name.
55
- */
56
- const val NAME = "NitroModules"
55
+ private external fun install(
56
+ jsRuntimePointer: Long,
57
+ callInvokerHolder: CallInvokerHolderImpl,
58
+ )
57
59
 
58
- /**
59
- * Get the current `ReactApplicationContext`, or `null` if none is available.
60
- */
61
- @JvmStatic
62
- var applicationContext: ReactApplicationContext? = null
60
+ companion object {
61
+ /**
62
+ * The TurboModule's name.
63
+ */
64
+ const val NAME = "NitroModules"
63
65
 
64
- init {
65
- // Make sure Nitro's C++ library is loaded
66
- JNIOnLoad.initializeNativeNitro()
67
- }
66
+ /**
67
+ * Get the current `ReactApplicationContext`, or `null` if none is available.
68
+ */
69
+ @JvmStatic
70
+ var applicationContext: ReactApplicationContext? = null
71
+
72
+ init {
73
+ // Make sure Nitro's C++ library is loaded
74
+ JNIOnLoad.initializeNativeNitro()
68
75
  }
69
- }
76
+ }
77
+ }
@@ -7,28 +7,32 @@ import com.facebook.react.module.model.ReactModuleInfo
7
7
  import com.facebook.react.module.model.ReactModuleInfoProvider
8
8
 
9
9
  class NitroModulesPackage : TurboReactPackage() {
10
- override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
11
- return if (name == NitroModules.NAME) {
12
- NitroModules(reactContext)
13
- } else {
14
- null
15
- }
10
+ override fun getModule(
11
+ name: String,
12
+ reactContext: ReactApplicationContext,
13
+ ): NativeModule? {
14
+ return if (name == NitroModules.NAME) {
15
+ NitroModules(reactContext)
16
+ } else {
17
+ null
16
18
  }
19
+ }
17
20
 
18
- override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
19
- return ReactModuleInfoProvider {
20
- val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
21
- val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
22
- moduleInfos[NitroModules.NAME] = ReactModuleInfo(
23
- NitroModules.NAME,
24
- NitroModules.NAME,
25
- canOverrideExistingModule = false,
26
- needsEagerInit = false,
27
- hasConstants = false,
28
- isCxxModule = false,
29
- isTurboModule = isTurboModule
30
- )
31
- moduleInfos
32
- }
21
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
22
+ return ReactModuleInfoProvider {
23
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
24
+ val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
25
+ moduleInfos[NitroModules.NAME] =
26
+ ReactModuleInfo(
27
+ NitroModules.NAME,
28
+ NitroModules.NAME,
29
+ canOverrideExistingModule = false,
30
+ needsEagerInit = false,
31
+ hasConstants = false,
32
+ isCxxModule = false,
33
+ isTurboModule = isTurboModule,
34
+ )
35
+ moduleInfos
33
36
  }
34
- }
37
+ }
38
+ }
@@ -30,52 +30,89 @@ class AnyMap {
30
30
  mHybridData = hybridData
31
31
  }
32
32
 
33
-
34
33
  @FastNative
35
34
  external fun contains(key: String): Boolean
35
+
36
36
  @FastNative
37
37
  external fun remove(key: String)
38
+
38
39
  @FastNative
39
40
  external fun clear()
41
+
40
42
  external fun getAllKeys(): Array<String>
41
43
 
42
44
  @FastNative
43
45
  external fun isNull(key: String): Boolean
46
+
44
47
  @FastNative
45
48
  external fun isDouble(key: String): Boolean
49
+
46
50
  @FastNative
47
51
  external fun isBoolean(key: String): Boolean
52
+
48
53
  @FastNative
49
54
  external fun isBigInt(key: String): Boolean
55
+
50
56
  @FastNative
51
57
  external fun isString(key: String): Boolean
58
+
52
59
  @FastNative
53
60
  external fun isArray(key: String): Boolean
61
+
54
62
  @FastNative
55
63
  external fun isObject(key: String): Boolean
56
64
 
57
65
  @FastNative
58
66
  external fun getDouble(key: String): Double
67
+
59
68
  @FastNative
60
69
  external fun getBoolean(key: String): Boolean
70
+
61
71
  @FastNative
62
72
  external fun getBigInt(key: String): Long
73
+
63
74
  external fun getString(key: String): String
75
+
64
76
  external fun getAnyArray(key: String): AnyArray
77
+
65
78
  external fun getAnyObject(key: String): AnyObject
66
79
 
67
80
  @FastNative
68
81
  external fun setNull(key: String)
82
+
69
83
  @FastNative
70
- external fun setDouble(key: String, value: Double)
84
+ external fun setDouble(
85
+ key: String,
86
+ value: Double,
87
+ )
88
+
71
89
  @FastNative
72
- external fun setBoolean(key: String, value: Boolean)
90
+ external fun setBoolean(
91
+ key: String,
92
+ value: Boolean,
93
+ )
94
+
73
95
  @FastNative
74
- external fun setBigInt(key: String, value: Long)
96
+ external fun setBigInt(
97
+ key: String,
98
+ value: Long,
99
+ )
100
+
75
101
  @FastNative
76
- external fun setString(key: String, value: String)
77
- external fun setAnyArray(key: String, value: AnyArray)
78
- external fun setAnyObject(key: String, value: AnyObject)
102
+ external fun setString(
103
+ key: String,
104
+ value: String,
105
+ )
106
+
107
+ external fun setAnyArray(
108
+ key: String,
109
+ value: AnyArray,
110
+ )
111
+
112
+ external fun setAnyObject(
113
+ key: String,
114
+ value: AnyObject,
115
+ )
79
116
 
80
117
  private external fun initHybrid(): HybridData
81
118
  }
@@ -22,143 +22,149 @@ typealias AnyObject = Map<String, AnyValue>
22
22
  @Keep
23
23
  @DoNotStrip
24
24
  class AnyValue {
25
- private val mHybridData: HybridData
26
-
27
- /**
28
- * Create a new [AnyValue] that holds `null`.
29
- */
30
- constructor() {
31
- mHybridData = initHybrid()
32
- }
33
-
34
- /**
35
- * Create a new [AnyValue] that holds the given [Double]
36
- */
37
- constructor(value: Double) {
38
- mHybridData = initHybrid(value)
39
- }
40
-
41
- /**
42
- * Create a new [AnyValue] that holds the given [Boolean]
43
- */
44
- constructor(value: Boolean) {
45
- mHybridData = initHybrid(value)
46
- }
47
-
48
- /**
49
- * Create a new [AnyValue] that holds the given [Long]
50
- */
51
- constructor(value: Long) {
52
- mHybridData = initHybrid(value)
53
- }
54
-
55
- /**
56
- * Create a new [AnyValue] that holds the given [String]
57
- */
58
- constructor(value: String) {
59
- mHybridData = initHybrid(value)
60
- }
61
-
62
- /**
63
- * Create a new [AnyValue] that holds the given [AnyArray]
64
- */
65
- constructor(value: AnyArray) {
66
- mHybridData = initHybrid(value)
67
- }
68
-
69
- /**
70
- * Create a new [AnyValue] that holds the given [AnyObject]
71
- */
72
- constructor(value: AnyObject) {
73
- mHybridData = initHybrid(value)
74
- }
75
-
76
- /**
77
- * Gets whether this [AnyValue] instance is holding a `null`.
78
- */
79
- @FastNative
80
- external fun isNull(): Boolean
81
-
82
- /**
83
- * Gets whether this [AnyValue] instance is holding a [Double] value.
84
- */
85
- @FastNative
86
- external fun isDouble(): Boolean
87
-
88
- /**
89
- * Gets whether this [AnyValue] instance is holding a [Boolean] value.
90
- */
91
- @FastNative
92
- external fun isBoolean(): Boolean
93
-
94
- /**
95
- * Gets whether this [AnyValue] instance is holding a [Long] value.
96
- */
97
- @FastNative
98
- external fun isBigInt(): Boolean
99
-
100
- /**
101
- * Gets whether this [AnyValue] instance is holding a [String] value.
102
- */
103
- @FastNative
104
- external fun isString(): Boolean
105
-
106
- /**
107
- * Gets whether this [AnyValue] instance is holding an [AnyArray] value.
108
- */
109
- @FastNative
110
- external fun isAnyArray(): Boolean
111
-
112
- /**
113
- * Gets whether this [AnyValue] instance is holding an [AnyObject] value.
114
- */
115
- @FastNative
116
- external fun isAnyObject(): Boolean
117
-
118
- /**
119
- * Get the [Double] value this [AnyValue] is holding.
120
- * @throws Error if this [AnyValue] is not holding a [Double] (see [isDouble]`()`)
121
- */
122
- @FastNative
123
- external fun asDouble(): Double
124
-
125
- /**
126
- * Get the [Boolean] value this [AnyValue] is holding.
127
- * @throws Error if this [AnyValue] is not holding a [Boolean] (see [isBoolean]`()`)
128
- */
129
- @FastNative
130
- external fun asBoolean(): Boolean
131
-
132
- /**
133
- * Get the [Long] value this [AnyValue] is holding.
134
- * @throws Error if this [AnyValue] is not holding a [Long] (see [isLong]`()`)
135
- */
136
- @FastNative
137
- external fun asBigInt(): Long
138
-
139
- /**
140
- * Get the [String] value this [AnyValue] is holding.
141
- * @throws Error if this [AnyValue] is not holding a [String] (see [isString]`()`)
142
- */
143
- external fun asString(): String
144
-
145
- /**
146
- * Get the [AnyArray] value this [AnyValue] is holding.
147
- * @throws Error if this [AnyValue] is not holding an [AnyArray] (see [isAnyArray]`()`)
148
- */
149
- external fun asAnyArray(): AnyArray
150
-
151
- /**
152
- * Get the [AnyObject] value this [AnyValue] is holding.
153
- * @throws Error if this [AnyValue] is not holding an [AnyObject] (see [isAnyObject]`()`)
154
- */
155
- external fun asAnyObject(): AnyObject
156
-
157
- private external fun initHybrid(): HybridData
158
- private external fun initHybrid(value: Double): HybridData
159
- private external fun initHybrid(value: Boolean): HybridData
160
- private external fun initHybrid(value: Long): HybridData
161
- private external fun initHybrid(value: String): HybridData
162
- private external fun initHybrid(value: AnyArray): HybridData
163
- private external fun initHybrid(value: AnyObject): HybridData
25
+ private val mHybridData: HybridData
26
+
27
+ /**
28
+ * Create a new [AnyValue] that holds `null`.
29
+ */
30
+ constructor() {
31
+ mHybridData = initHybrid()
32
+ }
33
+
34
+ /**
35
+ * Create a new [AnyValue] that holds the given [Double]
36
+ */
37
+ constructor(value: Double) {
38
+ mHybridData = initHybrid(value)
39
+ }
40
+
41
+ /**
42
+ * Create a new [AnyValue] that holds the given [Boolean]
43
+ */
44
+ constructor(value: Boolean) {
45
+ mHybridData = initHybrid(value)
46
+ }
47
+
48
+ /**
49
+ * Create a new [AnyValue] that holds the given [Long]
50
+ */
51
+ constructor(value: Long) {
52
+ mHybridData = initHybrid(value)
53
+ }
54
+
55
+ /**
56
+ * Create a new [AnyValue] that holds the given [String]
57
+ */
58
+ constructor(value: String) {
59
+ mHybridData = initHybrid(value)
60
+ }
61
+
62
+ /**
63
+ * Create a new [AnyValue] that holds the given [AnyArray]
64
+ */
65
+ constructor(value: AnyArray) {
66
+ mHybridData = initHybrid(value)
67
+ }
68
+
69
+ /**
70
+ * Create a new [AnyValue] that holds the given [AnyObject]
71
+ */
72
+ constructor(value: AnyObject) {
73
+ mHybridData = initHybrid(value)
74
+ }
75
+
76
+ /**
77
+ * Gets whether this [AnyValue] instance is holding a `null`.
78
+ */
79
+ @FastNative
80
+ external fun isNull(): Boolean
81
+
82
+ /**
83
+ * Gets whether this [AnyValue] instance is holding a [Double] value.
84
+ */
85
+ @FastNative
86
+ external fun isDouble(): Boolean
87
+
88
+ /**
89
+ * Gets whether this [AnyValue] instance is holding a [Boolean] value.
90
+ */
91
+ @FastNative
92
+ external fun isBoolean(): Boolean
93
+
94
+ /**
95
+ * Gets whether this [AnyValue] instance is holding a [Long] value.
96
+ */
97
+ @FastNative
98
+ external fun isBigInt(): Boolean
99
+
100
+ /**
101
+ * Gets whether this [AnyValue] instance is holding a [String] value.
102
+ */
103
+ @FastNative
104
+ external fun isString(): Boolean
105
+
106
+ /**
107
+ * Gets whether this [AnyValue] instance is holding an [AnyArray] value.
108
+ */
109
+ @FastNative
110
+ external fun isAnyArray(): Boolean
111
+
112
+ /**
113
+ * Gets whether this [AnyValue] instance is holding an [AnyObject] value.
114
+ */
115
+ @FastNative
116
+ external fun isAnyObject(): Boolean
117
+
118
+ /**
119
+ * Get the [Double] value this [AnyValue] is holding.
120
+ * @throws Error if this [AnyValue] is not holding a [Double] (see [isDouble]`()`)
121
+ */
122
+ @FastNative
123
+ external fun asDouble(): Double
124
+
125
+ /**
126
+ * Get the [Boolean] value this [AnyValue] is holding.
127
+ * @throws Error if this [AnyValue] is not holding a [Boolean] (see [isBoolean]`()`)
128
+ */
129
+ @FastNative
130
+ external fun asBoolean(): Boolean
131
+
132
+ /**
133
+ * Get the [Long] value this [AnyValue] is holding.
134
+ * @throws Error if this [AnyValue] is not holding a [Long] (see [isLong]`()`)
135
+ */
136
+ @FastNative
137
+ external fun asBigInt(): Long
138
+
139
+ /**
140
+ * Get the [String] value this [AnyValue] is holding.
141
+ * @throws Error if this [AnyValue] is not holding a [String] (see [isString]`()`)
142
+ */
143
+ external fun asString(): String
144
+
145
+ /**
146
+ * Get the [AnyArray] value this [AnyValue] is holding.
147
+ * @throws Error if this [AnyValue] is not holding an [AnyArray] (see [isAnyArray]`()`)
148
+ */
149
+ external fun asAnyArray(): AnyArray
150
+
151
+ /**
152
+ * Get the [AnyObject] value this [AnyValue] is holding.
153
+ * @throws Error if this [AnyValue] is not holding an [AnyObject] (see [isAnyObject]`()`)
154
+ */
155
+ external fun asAnyObject(): AnyObject
156
+
157
+ private external fun initHybrid(): HybridData
158
+
159
+ private external fun initHybrid(value: Double): HybridData
160
+
161
+ private external fun initHybrid(value: Boolean): HybridData
162
+
163
+ private external fun initHybrid(value: Long): HybridData
164
+
165
+ private external fun initHybrid(value: String): HybridData
166
+
167
+ private external fun initHybrid(value: AnyArray): HybridData
168
+
169
+ private external fun initHybrid(value: AnyObject): HybridData
164
170
  }