@octopus-community/react-native 1.0.4 → 1.0.5

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.
@@ -2,16 +2,16 @@ import React
2
2
  import Octopus
3
3
 
4
4
  class OctopusEventManager {
5
- private weak var eventEmitter: RCTEventEmitter?
5
+ private weak var bridge: RCTBridge?
6
6
  private var hasListeners = false
7
7
 
8
- init(eventEmitter: RCTEventEmitter) {
9
- self.eventEmitter = eventEmitter
8
+ init(bridge: RCTBridge?) {
9
+ self.bridge = bridge
10
10
  }
11
11
 
12
12
  func emitLoginRequired() {
13
13
  if hasListeners {
14
- eventEmitter?.sendEvent(withName: "loginRequired", body: nil)
14
+ bridge?.eventDispatcher().sendAppEvent(withName: "loginRequired", body: nil)
15
15
  }
16
16
  }
17
17
 
@@ -19,14 +19,14 @@ class OctopusEventManager {
19
19
  if hasListeners {
20
20
  let fieldToEdit = ProfileFieldMapper.toReactNativeString(profileField)
21
21
  let eventBody = ["fieldToEdit": fieldToEdit]
22
- eventEmitter?.sendEvent(withName: "editUser", body: eventBody)
22
+ bridge?.eventDispatcher().sendAppEvent(withName: "editUser", body: eventBody)
23
23
  }
24
24
  }
25
25
 
26
26
  func emitUserTokenRequest(requestId: String) {
27
27
  if hasListeners {
28
28
  let eventBody = ["requestId": requestId]
29
- eventEmitter?.sendEvent(withName: "userTokenRequest", body: eventBody)
29
+ bridge?.eventDispatcher().sendAppEvent(withName: "userTokenRequest", body: eventBody)
30
30
  }
31
31
  }
32
32
 
@@ -37,8 +37,4 @@ class OctopusEventManager {
37
37
  func stopObserving() {
38
38
  hasListeners = false
39
39
  }
40
-
41
- func supportedEvents() -> [String] {
42
- return ["loginRequired", "editUser", "userTokenRequest"]
43
- }
44
40
  }
@@ -1,3 +1,2 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
  #import <React/RCTViewManager.h>
3
- #import <React/RCTEventEmitter.h>
@@ -1,7 +1,6 @@
1
1
  #import <React/RCTBridgeModule.h>
2
- #import <React/RCTEventEmitter.h>
3
2
 
4
- @interface RCT_EXTERN_MODULE(OctopusReactNativeSdk, RCTEventEmitter)
3
+ @interface RCT_EXTERN_MODULE(OctopusReactNativeSdk, NSObject)
5
4
 
6
5
  RCT_EXTERN_METHOD(initialize:(NSDictionary *)options
7
6
  withResolver:(RCTPromiseResolveBlock)resolve
@@ -37,6 +36,10 @@ RCT_EXTERN_METHOD(updateTheme:(NSDictionary *)themeOptions
37
36
  withResolver:(RCTPromiseResolveBlock)resolve
38
37
  withRejecter:(RCTPromiseRejectBlock)reject)
39
38
 
39
+ RCT_EXTERN_METHOD(addListener:(NSString *)eventName)
40
+
41
+ RCT_EXTERN_METHOD(removeListeners:(NSInteger)count)
42
+
40
43
  + (BOOL)requiresMainQueueSetup
41
44
  {
42
45
  return NO;
@@ -2,20 +2,33 @@ import Octopus
2
2
  import OctopusUI
3
3
  import SwiftUI
4
4
  import UIKit
5
+ import React
5
6
 
6
7
  @objc(OctopusReactNativeSdk)
7
- class OctopusReactNativeSdk: RCTEventEmitter {
8
+ class OctopusReactNativeSdk: NSObject, RCTBridgeModule {
8
9
 
9
10
  // MARK: - Properties
10
11
 
11
12
  private var octopusSDK: OctopusSDK?
12
13
  private lazy var uiManager = OctopusUIManager()
13
- private lazy var eventManager = OctopusEventManager(eventEmitter: self)
14
+ private lazy var eventManager = OctopusEventManager(bridge: bridge)
14
15
  private let sdkInitializer = OctopusSDKInitializer()
15
16
  private var ssoAuthenticator: OctopusSSOAuthenticator?
16
17
  private var theme: OctopusTheme?
17
18
  private var logoSource: [String: Any]?
18
19
  private var fontConfiguration: [String: Any]?
20
+
21
+ // MARK: - RCTBridgeModule
22
+
23
+ @objc var bridge: RCTBridge!
24
+
25
+ @objc static func moduleName() -> String! {
26
+ return "OctopusReactNativeSdk"
27
+ }
28
+
29
+ @objc static func requiresMainQueueSetup() -> Bool {
30
+ return false
31
+ }
19
32
 
20
33
  // MARK: - Initialization
21
34
 
@@ -151,22 +164,19 @@ class OctopusReactNativeSdk: RCTEventEmitter {
151
164
  octopusSDK = nil
152
165
  }
153
166
 
154
- @objc override func invalidate() {
167
+ @objc func invalidate() {
155
168
  cleanup()
156
- super.invalidate()
157
169
  }
158
-
159
- // MARK: - RCTEventEmitter overrides
160
-
161
- @objc override func supportedEvents() -> [String]! {
162
- return eventManager.supportedEvents()
163
- }
164
-
165
- @objc override func startObserving() {
170
+
171
+ // MARK: - Event Listener Support for NativeEventEmitter
172
+
173
+ @objc func addListener(_ eventName: String) {
174
+ // Start observing when listeners are added
166
175
  eventManager.startObserving()
167
176
  }
168
-
169
- @objc override func stopObserving() {
177
+
178
+ @objc func removeListeners(_ count: Int) {
179
+ // Stop observing when listeners are removed
170
180
  eventManager.stopObserving()
171
181
  }
172
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octopus-community/react-native",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "React Native module for the Octopus Community SDK",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",
@@ -67,7 +67,7 @@
67
67
  "@evilmartians/lefthook": "^1.5.0",
68
68
  "@react-native/eslint-config": "^0.78.0",
69
69
  "@types/jest": "^29.5.5",
70
- "@types/react": "^19.0.0",
70
+ "@types/react": "^19.1.0",
71
71
  "commitlint": "^19.6.1",
72
72
  "del-cli": "^5.1.0",
73
73
  "eslint": "^9.22.0",
@@ -75,8 +75,8 @@
75
75
  "eslint-plugin-prettier": "^5.2.3",
76
76
  "jest": "^29.7.0",
77
77
  "prettier": "^3.0.3",
78
- "react": "19.0.0",
79
- "react-native": "0.78.2",
78
+ "react": "19.1.0",
79
+ "react-native": "^0.81.4",
80
80
  "react-native-builder-bob": "^0.40.12",
81
81
  "turbo": "^1.10.7",
82
82
  "typedoc": "^0.28.7",