@octopus-community/react-native 1.0.3 → 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
|
|
5
|
+
private weak var bridge: RCTBridge?
|
|
6
6
|
private var hasListeners = false
|
|
7
7
|
|
|
8
|
-
init(
|
|
9
|
-
self.
|
|
8
|
+
init(bridge: RCTBridge?) {
|
|
9
|
+
self.bridge = bridge
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
func emitLoginRequired() {
|
|
13
13
|
if hasListeners {
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,7 +1,6 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
|
-
#import <React/RCTEventEmitter.h>
|
|
3
2
|
|
|
4
|
-
@interface RCT_EXTERN_MODULE(OctopusReactNativeSdk,
|
|
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:
|
|
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(
|
|
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
|
|
167
|
+
@objc func invalidate() {
|
|
155
168
|
cleanup()
|
|
156
|
-
super.invalidate()
|
|
157
169
|
}
|
|
158
|
-
|
|
159
|
-
// MARK: -
|
|
160
|
-
|
|
161
|
-
@objc
|
|
162
|
-
|
|
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
|
|
177
|
+
|
|
178
|
+
@objc func removeListeners(_ count: Int) {
|
|
179
|
+
// Stop observing when listeners are removed
|
|
170
180
|
eventManager.stopObserving()
|
|
171
181
|
}
|
|
172
182
|
}
|
|
@@ -89,18 +89,43 @@ class OctopusUIManager {
|
|
|
89
89
|
}.resume()
|
|
90
90
|
} else {
|
|
91
91
|
// Local file path (from Image.resolveAssetSource)
|
|
92
|
-
if let image =
|
|
92
|
+
if let image = loadImageFromLocalPath(uri) {
|
|
93
93
|
completion(image)
|
|
94
94
|
} else {
|
|
95
|
-
|
|
96
|
-
let filename = (uri as NSString).lastPathComponent
|
|
97
|
-
let nameWithoutExtension = (filename as NSString).deletingPathExtension
|
|
98
|
-
let image = UIImage(named: nameWithoutExtension)
|
|
99
|
-
completion(image)
|
|
95
|
+
completion(nil)
|
|
100
96
|
}
|
|
101
97
|
}
|
|
102
98
|
}
|
|
103
99
|
|
|
100
|
+
private func loadImageFromLocalPath(_ path: String) -> UIImage? {
|
|
101
|
+
// Handle absolute file URLs (file://) first
|
|
102
|
+
if path.hasPrefix("file://"), let url = URL(string: path),
|
|
103
|
+
let image = UIImage(contentsOfFile: url.path) {
|
|
104
|
+
return image
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Try raw absolute path next
|
|
108
|
+
if path.hasPrefix("/"), FileManager.default.fileExists(atPath: path),
|
|
109
|
+
let image = UIImage(contentsOfFile: path) {
|
|
110
|
+
return image
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// For React Native bundled assets the path is relative (e.g. assets/assets/logo.png)
|
|
114
|
+
let nsPath = path as NSString
|
|
115
|
+
let directory = nsPath.deletingLastPathComponent
|
|
116
|
+
let filename = nsPath.lastPathComponent
|
|
117
|
+
let nameWithoutExtension = (filename as NSString).deletingPathExtension
|
|
118
|
+
let fileExtension = (filename as NSString).pathExtension
|
|
119
|
+
|
|
120
|
+
if let bundlePath = Bundle.main.path(forResource: nameWithoutExtension, ofType: fileExtension.isEmpty ? nil : fileExtension, inDirectory: directory.isEmpty ? nil : directory) ,
|
|
121
|
+
let image = UIImage(contentsOfFile: bundlePath) {
|
|
122
|
+
return image
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Final fallback: let UIKit try to resolve it by name (works for assets catalog entries)
|
|
126
|
+
return UIImage(named: nameWithoutExtension)
|
|
127
|
+
}
|
|
128
|
+
|
|
104
129
|
func closeUI() throws {
|
|
105
130
|
guard let presentedVC = presentedViewController else {
|
|
106
131
|
throw NSError(domain: "CLOSE_UI_ERROR", code: 0, userInfo: [NSLocalizedDescriptionKey: "No UI is currently presented"])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octopus-community/react-native",
|
|
3
|
-
"version": "1.0.
|
|
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.
|
|
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.
|
|
79
|
-
"react-native": "0.
|
|
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",
|