@altcraft/react-native-sdk 0.0.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +21 -120
  2. package/autolink.js +36 -0
  3. package/lib/commonjs/altcraft_sdk.js +297 -0
  4. package/lib/commonjs/altcraft_sdk.js.map +1 -0
  5. package/lib/commonjs/index.js +192 -0
  6. package/lib/commonjs/index.js.map +1 -0
  7. package/lib/commonjs/package.json +1 -0
  8. package/lib/module/altcraft_sdk.js +292 -0
  9. package/lib/module/altcraft_sdk.js.map +1 -0
  10. package/lib/module/index.js +13 -427
  11. package/lib/module/index.js.map +1 -1
  12. package/lib/typescript/commonjs/package.json +1 -0
  13. package/lib/typescript/commonjs/src/altcraft_sdk.d.ts +143 -0
  14. package/lib/typescript/commonjs/src/altcraft_sdk.d.ts.map +1 -0
  15. package/lib/typescript/commonjs/src/index.d.ts +24 -0
  16. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  17. package/lib/typescript/module/src/altcraft_sdk.d.ts +143 -0
  18. package/lib/typescript/module/src/altcraft_sdk.d.ts.map +1 -0
  19. package/lib/typescript/module/src/index.d.ts +24 -0
  20. package/lib/typescript/module/src/index.d.ts.map +1 -0
  21. package/package.json +49 -95
  22. package/scripts/postinstall.cjs +195 -0
  23. package/src/altcraft_sdk.ts +337 -0
  24. package/src/index.ts +91 -0
  25. package/Sdk.podspec +0 -48
  26. package/android/build.gradle +0 -77
  27. package/android/gradle.properties +0 -5
  28. package/android/src/main/AndroidManifest.xml +0 -2
  29. package/android/src/main/java/com/altcraft/sdk/SdkEventEmitter.kt +0 -55
  30. package/android/src/main/java/com/altcraft/sdk/SdkModule.kt +0 -993
  31. package/android/src/main/java/com/altcraft/sdk/SdkPackage.kt +0 -41
  32. package/android/src/main/java/com/altcraft/sdk/utilities/Converter.kt +0 -326
  33. package/android/src/main/java/com/altcraft/sdk/utilities/Extension.kt +0 -72
  34. package/ios/Converter.swift +0 -640
  35. package/ios/Sdk.h +0 -20
  36. package/ios/Sdk.mm +0 -979
  37. package/ios/SdkModule.swift +0 -778
  38. package/lib/module/NativeSdk.js +0 -48
  39. package/lib/module/NativeSdk.js.map +0 -1
  40. package/lib/module/Utilities.js +0 -178
  41. package/lib/module/Utilities.js.map +0 -1
  42. package/lib/typescript/src/NativeSdk.d.ts +0 -215
  43. package/lib/typescript/src/NativeSdk.d.ts.map +0 -1
  44. package/lib/typescript/src/Utilities.d.ts +0 -47
  45. package/lib/typescript/src/Utilities.d.ts.map +0 -1
  46. package/lib/typescript/src/index.d.ts +0 -252
  47. package/lib/typescript/src/index.d.ts.map +0 -1
  48. package/react-native.config.js +0 -10
  49. package/src/NativeSdk.ts +0 -313
  50. package/src/Utilities.ts +0 -180
  51. package/src/index.tsx +0 -570
  52. /package/lib/typescript/{package.json → module/package.json} +0 -0
@@ -0,0 +1,337 @@
1
+ import { AltcraftCore } from '@altcraft/core';
2
+ import type {
3
+ AltcraftConfig,
4
+ CategoryData,
5
+ ResponseWithHttpCode,
6
+ } from '@altcraft/core';
7
+ import { AltcraftInApp } from '@altcraft/inapp';
8
+ import type {
9
+ InAppAnimationConfig,
10
+ InAppAnimationEasing,
11
+ InAppAnimationSpec,
12
+ InAppSubscribeOptions,
13
+ JsonContentApi,
14
+ JsonContentHandler,
15
+ } from '@altcraft/inapp';
16
+ import { AltcraftProfile } from '@altcraft/profile';
17
+ import type { UpdateProfileOptions } from '@altcraft/profile';
18
+ import { AltcraftPush } from '@altcraft/push';
19
+ import type {
20
+ PushEventOptions,
21
+ PushSubscribeOptions,
22
+ TokenData,
23
+ } from '@altcraft/push';
24
+ import { AltcraftTarget } from '@altcraft/target';
25
+ import type { MobileEventOptions, Subscription, UTM } from '@altcraft/target';
26
+ import type { SdkEvent } from '@altcraft/core';
27
+
28
+ /**
29
+ * Main entry point for the Altcraft SDK.
30
+ *
31
+ * All SDK operations are accessed through this class's static methods.
32
+ * The package is a pure-JS facade: initialization is delegated to
33
+ * `AltcraftCore.initialize`, and all other operations are delegated to the
34
+ * module packages ({@link AltcraftCore}, {@link AltcraftPush},
35
+ * {@link AltcraftInApp}, {@link AltcraftTarget}, {@link AltcraftProfile}).
36
+ * There is no umbrella native module; module options are applied through
37
+ * `AltcraftConfigBuilder` extensions.
38
+ *
39
+ * ```ts
40
+ * import { AltcraftSDK } from 'altcraft';
41
+ *
42
+ * // Initialize
43
+ * await AltcraftSDK.initialize({
44
+ * apiUrl: 'https://your-api.altcraft.com',
45
+ * appInfo: { appID: 'firebase-app-id', appIID: 'firebase-instance-id', appVer: '1.0.0' },
46
+ * });
47
+ *
48
+ * // Subscribe to push
49
+ * AltcraftSDK.pushSubscribe({ sync: true });
50
+ *
51
+ * // Listen to SDK events
52
+ * AltcraftSDK.subscribeToEvents((event) => {
53
+ * console.log(`${event.function}: ${event.message}`);
54
+ * });
55
+ * ```
56
+ *
57
+ * Module-specific options are added through `AltcraftConfigBuilder` extensions
58
+ * and applied by `AltcraftCore.initialize`:
59
+ *
60
+ * ```ts
61
+ * import { AltcraftConfigBuilder, AltcraftCore } from '@altcraft/core';
62
+ * import '@altcraft/inapp';
63
+ * import '@altcraft/push';
64
+ *
65
+ * await AltcraftCore.initialize(
66
+ * new AltcraftConfigBuilder({ apiUrl: 'https://your-api.altcraft.com' })
67
+ * .pushConfig({ providerPriority: ['android-firebase'] })
68
+ * .inAppConfig({ maxPlacements: 50 })
69
+ * .build()
70
+ * );
71
+ * ```
72
+ */
73
+ export class AltcraftSDK {
74
+ /** Provides access to In-App placements with JSON content. */
75
+ static readonly jsonContent: JsonContentApi = AltcraftInApp.jsonContent;
76
+
77
+ // ---- Initialization ----
78
+
79
+ /**
80
+ * Initializes the Altcraft SDK with the given configuration.
81
+ *
82
+ * Delegates to `AltcraftCore.initialize`. For module-specific options use
83
+ * `AltcraftConfigBuilder` and the module extensions (`pushConfig`,
84
+ * `inAppConfig`).
85
+ */
86
+ static initialize(config: AltcraftConfig): Promise<void> {
87
+ return AltcraftCore.initialize(config);
88
+ }
89
+
90
+ // ---- Push Subscription ----
91
+
92
+ /** Subscribes to push notifications. */
93
+ static pushSubscribe(options: PushSubscribeOptions = {}): Promise<void> {
94
+ return AltcraftPush.pushSubscribe(options);
95
+ }
96
+
97
+ /** Suspends push subscription. */
98
+ static pushSuspend(options: PushSubscribeOptions = {}): Promise<void> {
99
+ return AltcraftPush.pushSuspend(options);
100
+ }
101
+
102
+ /** Unsubscribes from push notifications. */
103
+ static pushUnSubscribe(options: PushSubscribeOptions = {}): Promise<void> {
104
+ return AltcraftPush.pushUnSubscribe(options);
105
+ }
106
+
107
+ /** UnSuspends a previously suspended push subscription. */
108
+ static unSuspendPushSubscription(): Promise<ResponseWithHttpCode | null> {
109
+ return AltcraftPush.unSuspendPushSubscription();
110
+ }
111
+
112
+ // ---- In-App Subscription ----
113
+
114
+ /** Subscribes to In-App notifications. */
115
+ static inAppSubscribe(options: InAppSubscribeOptions = {}): Promise<void> {
116
+ return AltcraftInApp.inAppSubscribe(options);
117
+ }
118
+
119
+ /** Unsubscribes from In-App notifications. */
120
+ static inAppUnsubscribe(options: InAppSubscribeOptions = {}): Promise<void> {
121
+ return AltcraftInApp.inAppUnsubscribe(options);
122
+ }
123
+
124
+ // ---- Subscription Status ----
125
+
126
+ /** Gets the status of the latest subscription. */
127
+ static getStatusOfLatestSubscription(): Promise<ResponseWithHttpCode | null> {
128
+ return AltcraftPush.getStatusOfLatestSubscription();
129
+ }
130
+
131
+ /** Gets the status of the current subscription. */
132
+ static getStatusForCurrentSubscription(): Promise<ResponseWithHttpCode | null> {
133
+ return AltcraftPush.getStatusForCurrentSubscription();
134
+ }
135
+
136
+ /** Gets the status of the latest subscription for a specific provider. */
137
+ static getStatusOfLatestSubscriptionForProvider(
138
+ provider: string | null = null
139
+ ): Promise<ResponseWithHttpCode | null> {
140
+ return AltcraftPush.getStatusOfLatestSubscriptionForProvider(provider);
141
+ }
142
+
143
+ // ---- SDK Events ----
144
+
145
+ /** Subscribes to SDK events stream. */
146
+ static subscribeToEvents(handler: (event: SdkEvent) => void): void {
147
+ AltcraftCore.subscribeToEvents(handler);
148
+ }
149
+
150
+ /** Unsubscribes from SDK events. */
151
+ static unsubscribeFromEvents(handler: (event: SdkEvent) => void): void {
152
+ AltcraftCore.unsubscribeFromEvents(handler);
153
+ }
154
+
155
+ // ---- Mobile Events ----
156
+
157
+ /** Sends a mobile event to the Altcraft platform. */
158
+ static sendTarget(options: MobileEventOptions): void {
159
+ AltcraftTarget.sendTarget(options);
160
+ }
161
+
162
+ // ---- Push Tokens ----
163
+
164
+ /** Gets the current push token data. */
165
+ static getPushToken(): Promise<TokenData | null> {
166
+ return AltcraftPush.getPushToken();
167
+ }
168
+
169
+ /** Sets or clears a push token for the given provider. */
170
+ static setPushToken(provider: string, token: string | null): void {
171
+ AltcraftPush.setPushToken(provider, token);
172
+ }
173
+
174
+ // ---- State ----
175
+
176
+ /** Clears all SDK state. */
177
+ static clear(): Promise<void> {
178
+ return AltcraftCore.clear();
179
+ }
180
+
181
+ // ---- Push Handling (Android) ----
182
+
183
+ /** Forwards a push payload to the SDK (Android). */
184
+ static takePush(message: Record<string, string>): void {
185
+ AltcraftPush.takePush(message);
186
+ }
187
+
188
+ // ---- Permissions (Android) ----
189
+
190
+ /** Requests notification permission (Android). Returns true if granted. */
191
+ static requestNotificationPermission(): Promise<boolean> {
192
+ return AltcraftPush.requestNotificationPermission();
193
+ }
194
+
195
+ // ---- Push Events (Android) ----
196
+
197
+ /** Reports push delivery (Android). */
198
+ static deliveryEvent(options: PushEventOptions = {}): void {
199
+ AltcraftPush.deliveryEvent(options);
200
+ }
201
+
202
+ /** Reports push open (Android). */
203
+ static openEvent(options: PushEventOptions = {}): void {
204
+ AltcraftPush.openEvent(options);
205
+ }
206
+
207
+ // ---- UserDefaults (iOS) ----
208
+
209
+ /**
210
+ * Stores a string value in native storage (UserDefaults on iOS,
211
+ * SharedPreferences on Android).
212
+ *
213
+ * On iOS, `suiteName` selects the App Group UserDefaults suite.
214
+ * On Android, `suiteName` is ignored.
215
+ */
216
+ static setUserDefaultsValue(
217
+ suiteName: string | null,
218
+ key: string,
219
+ value: string | null
220
+ ): void {
221
+ AltcraftCore.setUserDefaultsValue(suiteName, key, value);
222
+ }
223
+
224
+ // ---- Profile ----
225
+
226
+ /** Updates profile fields on the server. */
227
+ static updateProfileFields(options: UpdateProfileOptions = {}): void {
228
+ AltcraftProfile.updateProfileFields(options);
229
+ }
230
+
231
+ // ---- Token Management ----
232
+
233
+ /** Forces a token refresh. */
234
+ static forcedTokenUpdate(): Promise<void> {
235
+ return AltcraftPush.forcedTokenUpdate();
236
+ }
237
+
238
+ /** Deletes a device token for the given provider. */
239
+ static deleteDeviceToken(provider: string): Promise<void> {
240
+ return AltcraftPush.deleteDeviceToken(provider);
241
+ }
242
+
243
+ /** Changes the push provider priority list. */
244
+ static changePushProviderPriorityList(priorityList: string[]): Promise<void> {
245
+ return AltcraftPush.changePushProviderPriorityList(priorityList);
246
+ }
247
+
248
+ // ---- Push Identification ----
249
+
250
+ /** Checks if a push message is from Altcraft. */
251
+ static isAltcraftPush(message: Record<string, string>): boolean {
252
+ return AltcraftPush.isAltcraftPush(message);
253
+ }
254
+
255
+ // ---- Session (Android) ----
256
+
257
+ /** Unlocks initial operations in the current session (Android). */
258
+ static unlockInitialOperationsInThisSession(): void {
259
+ AltcraftCore.unlockInitialOperationsInThisSession();
260
+ }
261
+
262
+ // ---- App Group (iOS) ----
263
+
264
+ /** Sets the App Group for UserDefaults (iOS). */
265
+ static setAppGroup(groupName: string | null): void {
266
+ AltcraftCore.setAppGroup(groupName);
267
+ }
268
+
269
+ // ---- Authentication ----
270
+
271
+ /** Registers a JWT provider that the native SDK calls when it needs a token. */
272
+ static setJwtProvider(provider: () => Promise<string | null>): void {
273
+ AltcraftCore.setJwtProvider(provider);
274
+ }
275
+
276
+ /** Starts SDK authentication. */
277
+ static authenticate(): void {
278
+ AltcraftCore.authenticate();
279
+ }
280
+
281
+ /** Logs the user out. */
282
+ static logOut(): void {
283
+ AltcraftCore.logOut();
284
+ }
285
+
286
+ /** Returns whether the user is authenticated. */
287
+ static isAuthenticated(): Promise<boolean> {
288
+ return AltcraftCore.isAuthenticated();
289
+ }
290
+
291
+ // ---- InApp ----
292
+
293
+ /** Sets the current screen for In-App placement matching. */
294
+ static setScreen(screen: string): void {
295
+ AltcraftInApp.setScreen(screen);
296
+ }
297
+
298
+ /** Fires an In-App trigger by name. */
299
+ static trigger(name: string): void {
300
+ AltcraftInApp.trigger(name);
301
+ }
302
+
303
+ /** Requests In-App placements. */
304
+ static getPlacements(): void {
305
+ AltcraftInApp.getPlacements();
306
+ }
307
+
308
+ /** Sets or clears the In-App show animation configuration. */
309
+ static setAnimation(config: InAppAnimationConfig | null): void {
310
+ AltcraftInApp.setAnimation(config);
311
+ }
312
+
313
+ /** Disables the In-App show animation. */
314
+ static clearAnimation(): void {
315
+ AltcraftInApp.clearAnimation();
316
+ }
317
+ }
318
+
319
+ export type {
320
+ AltcraftConfig,
321
+ CategoryData,
322
+ InAppAnimationConfig,
323
+ InAppAnimationEasing,
324
+ InAppAnimationSpec,
325
+ InAppSubscribeOptions,
326
+ JsonContentApi,
327
+ JsonContentHandler,
328
+ MobileEventOptions,
329
+ PushEventOptions,
330
+ PushSubscribeOptions,
331
+ ResponseWithHttpCode,
332
+ SdkEvent,
333
+ Subscription,
334
+ TokenData,
335
+ UpdateProfileOptions,
336
+ UTM,
337
+ };
package/src/index.ts ADDED
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Altcraft SDK for React Native.
3
+ *
4
+ * Umbrella package for the Altcraft push notification platform. Provides the
5
+ * full `AltcraftSDK` API as a pure-JS facade over the connected modules
6
+ * (initialization is delegated to `@altcraft/core`).
7
+ *
8
+ * For modular usage, depend on the individual module packages instead:
9
+ * `@altcraft/core`, `@altcraft/push`, `@altcraft/inapp`, `@altcraft/target`,
10
+ * `@altcraft/profile`.
11
+ */
12
+ export { AltcraftSDK } from './altcraft_sdk';
13
+
14
+ export {
15
+ AltcraftCore,
16
+ AltcraftCorePlatform,
17
+ TurboModuleAltcraftCore,
18
+ AltcraftChannels,
19
+ actionField,
20
+ ActionFieldBuilder,
21
+ Utilities,
22
+ AltcraftException,
23
+ coreModuleEvents,
24
+ } from '@altcraft/core';
25
+ export type { CoreModuleEvents } from '@altcraft/core';
26
+
27
+ export {
28
+ AltcraftPush,
29
+ AltcraftPushPlatform,
30
+ TurboModuleAltcraftPush,
31
+ pushModuleEvents,
32
+ } from '@altcraft/push';
33
+ export type {
34
+ PushSubscribeOptions,
35
+ PushEventOptions,
36
+ PushModuleEvents,
37
+ TokenData,
38
+ } from '@altcraft/push';
39
+
40
+ export {
41
+ AltcraftInApp,
42
+ AltcraftInAppPlatform,
43
+ TurboModuleAltcraftInApp,
44
+ inAppModuleEvents,
45
+ } from '@altcraft/inapp';
46
+ export type {
47
+ InAppAnimationConfig,
48
+ InAppAnimationEasing,
49
+ InAppAnimationSpec,
50
+ InAppSubscribeOptions,
51
+ InAppModuleEvents,
52
+ JsonContentApi,
53
+ JsonContentHandler,
54
+ } from '@altcraft/inapp';
55
+
56
+ export {
57
+ AltcraftTarget,
58
+ AltcraftTargetPlatform,
59
+ TurboModuleAltcraftTarget,
60
+ targetModuleEvents,
61
+ emailSubscription,
62
+ smsSubscription,
63
+ pushSubscription,
64
+ ccDataSubscription,
65
+ } from '@altcraft/target';
66
+ export type {
67
+ MobileEventOptions,
68
+ TargetModuleEvents,
69
+ Subscription,
70
+ EmailSubscription,
71
+ SmsSubscription,
72
+ PushSubscription,
73
+ CcDataSubscription,
74
+ UTM,
75
+ } from '@altcraft/target';
76
+
77
+ export {
78
+ AltcraftProfile,
79
+ AltcraftProfilePlatform,
80
+ TurboModuleAltcraftProfile,
81
+ profileModuleEvents,
82
+ } from '@altcraft/profile';
83
+ export type { UpdateProfileOptions, ProfileModuleEvents } from '@altcraft/profile';
84
+
85
+ export type {
86
+ AltcraftConfig,
87
+ AppInfo,
88
+ CategoryData,
89
+ ResponseWithHttpCode,
90
+ SdkEvent,
91
+ } from '@altcraft/core';
package/Sdk.podspec DELETED
@@ -1,48 +0,0 @@
1
- require "json"
2
-
3
- package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
-
5
- Pod::Spec.new do |s|
6
- s.name = "Sdk"
7
- s.version = package["version"]
8
- s.summary = package["description"]
9
- s.homepage = package["homepage"]
10
- s.license = package["license"]
11
- s.authors = package["author"]
12
-
13
- s.platform = :ios, min_ios_version_supported
14
-
15
- s.source = {
16
- :git => "https://github.com/altcraft/react-native-sdk.git",
17
- :tag => s.version.to_s
18
- }
19
-
20
- # --- Sources ---
21
- s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
22
- s.public_header_files = "ios/**/*.h"
23
-
24
- # --- Swift / Module settings (critical for <Sdk/Sdk-Swift.h>) ---
25
- s.swift_version = "6.0"
26
- s.pod_target_xcconfig = {
27
- "DEFINES_MODULE" => "YES",
28
- "CLANG_ENABLE_MODULES" => "YES",
29
- "SWIFT_INSTALL_OBJC_HEADER" => "YES"
30
- }
31
-
32
- # --- Native dependency ---
33
- s.dependency "Altcraft", "1.0.3"
34
-
35
- # --- React Native module deps ---
36
- install_modules_dependencies(s)
37
-
38
- if ENV["RCT_NEW_ARCH_ENABLED"] == "1"
39
- s.dependency "React-Codegen"
40
- s.dependency "RCT-Folly"
41
- s.dependency "RCTRequired"
42
- s.dependency "RCTTypeSafety"
43
- s.dependency "ReactCommon/turbomodule/core"
44
- s.dependency "React-RCTFabric"
45
- s.dependency "React-NativeModulesApple"
46
- end
47
- end
48
-
@@ -1,77 +0,0 @@
1
- buildscript {
2
- ext.getExtOrDefault = {name ->
3
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Sdk_' + name]
4
- }
5
-
6
- repositories {
7
- google()
8
- mavenCentral()
9
- }
10
-
11
- dependencies {
12
- classpath "com.android.tools.build:gradle:8.7.2"
13
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
14
- }
15
- }
16
-
17
- apply plugin: "com.android.library"
18
- apply plugin: "kotlin-android"
19
-
20
- apply plugin: "com.facebook.react"
21
-
22
- def getExtOrIntegerDefault(name) {
23
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Sdk_" + name]).toInteger()
24
- }
25
-
26
- android {
27
- namespace "com.sdk"
28
-
29
- compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
30
-
31
- defaultConfig {
32
- minSdkVersion getExtOrIntegerDefault("minSdkVersion")
33
- targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
34
- }
35
-
36
- buildFeatures {
37
- buildConfig true
38
- }
39
-
40
- buildTypes {
41
- release {
42
- minifyEnabled false
43
- }
44
- }
45
-
46
- lintOptions {
47
- disable "GradleCompatible"
48
- }
49
-
50
- compileOptions {
51
- sourceCompatibility JavaVersion.VERSION_1_8
52
- targetCompatibility JavaVersion.VERSION_1_8
53
- }
54
-
55
- sourceSets {
56
- main {
57
- java.srcDirs += [
58
- "generated/java",
59
- "generated/jni"
60
- ]
61
- }
62
- }
63
- }
64
-
65
- repositories {
66
- mavenCentral()
67
- google()
68
- }
69
-
70
- def kotlin_version = getExtOrDefault("kotlinVersion")
71
-
72
- dependencies {
73
- api "com.altcraft:android-sdk:1.0.6"
74
- implementation "com.facebook.react:react-android"
75
- implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
76
- implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3"
77
- }
@@ -1,5 +0,0 @@
1
- Sdk_kotlinVersion=2.0.21
2
- Sdk_minSdkVersion=24
3
- Sdk_targetSdkVersion=34
4
- Sdk_compileSdkVersion=35
5
- Sdk_ndkVersion=27.1.12297006
@@ -1,2 +0,0 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
@@ -1,55 +0,0 @@
1
- package com.altcraft.sdk
2
-
3
- import android.util.Log
4
- import com.facebook.react.bridge.ReactApplicationContext
5
- import com.facebook.react.bridge.ReactContextBaseJavaModule
6
- import com.facebook.react.bridge.ReactMethod
7
- import com.facebook.react.module.annotations.ReactModule
8
- import com.facebook.react.modules.core.DeviceEventManagerModule
9
-
10
- /**
11
- * Event emitter module for NativeEventEmitter on the JS side.
12
- * SdkModule calls [emit] to forward SDK events to JS.
13
- */
14
- @ReactModule(name = SdkEventEmitter.NAME)
15
- class SdkEventEmitter(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
16
-
17
- companion object {
18
- const val NAME = "SDKEventEmitter"
19
-
20
- @JvmStatic
21
- fun emit(eventName: String, event: Any?) {
22
- try {
23
- instance?.reactApplicationContext?.getJSModule(
24
- DeviceEventManagerModule.RCTDeviceEventEmitter::class.java
25
- )?.emit(eventName, event)
26
- } catch (e: Exception) {
27
- Log.e("altcraft_lib_android_bridge", "SdkEventEmitter.emit failed: ${e.message}")
28
- }
29
- }
30
-
31
- @JvmStatic
32
- private var instance: SdkEventEmitter? = null
33
- }
34
-
35
- override fun getName(): String = NAME
36
-
37
- init {
38
- instance = this
39
- }
40
-
41
- @ReactMethod
42
- fun addListener(eventName: String) {
43
- // No-op — required by NativeEventEmitter
44
- }
45
-
46
- @ReactMethod
47
- fun removeListeners(count: Double) {
48
- // No-op — required by NativeEventEmitter
49
- }
50
-
51
- override fun onCatalystInstanceDestroy() {
52
- super.onCatalystInstanceDestroy()
53
- instance = null
54
- }
55
- }