brick-module 0.1.6 → 0.1.8
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/BrickModule.podspec +6 -8
- package/android/brick_modules.gradle +31 -112
- package/android/build.gradle +0 -1
- package/android/src/main/java/com/brickmodule/BrickModulePackage.kt +2 -3
- package/android/src/main/java/com/brickmodule/BrickModuleRegistry.kt +2 -2
- package/dist/BrickModule.js +5 -1
- package/dist/index.js +3 -3
- package/ios/BrickModule/{Internal/BrickCoreModule.swift → BrickCoreModule.swift} +30 -9
- package/ios/BrickModule/BrickModuleRegistrable.swift +26 -0
- package/ios/BrickModule/BrickModuleRegistrableViewControllerType.swift +5 -0
- package/ios/BrickModule/{Internal/BrickModuleRegistry.swift → BrickModuleRegistry.swift} +32 -41
- package/package.json +16 -5
- package/podfile_helper.rb +22 -239
- package/src/index.ts +1 -1
- package/android/build/generated/source/codegen/jni/CMakeLists.txt +0 -14
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -7
- package/android/gradlew +0 -252
- package/android/gradlew.bat +0 -94
- package/ios/BrickModule/Public/BrickModule-Swift.h +0 -341
package/BrickModule.podspec
CHANGED
|
@@ -25,6 +25,9 @@ Pod::Spec.new do |s|
|
|
|
25
25
|
base_config = {
|
|
26
26
|
"DEFINES_MODULE" => "YES",
|
|
27
27
|
"SWIFT_VERSION" => "5.0",
|
|
28
|
+
"SWIFT_COMPILATION_MODE" => "wholemodule",
|
|
29
|
+
"SWIFT_INSTALL_OBJC_HEADER" => "YES",
|
|
30
|
+
"SWIFT_OBJC_INTERFACE_HEADER_NAME" => "BrickModule-Swift.h",
|
|
28
31
|
"OTHER_SWIFT_FLAGS" => "-enable-experimental-feature AccessLevelOnImport"
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -36,22 +39,17 @@ Pod::Spec.new do |s|
|
|
|
36
39
|
else
|
|
37
40
|
s.dependency "React-Core"
|
|
38
41
|
|
|
39
|
-
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
40
|
-
if ENV["RCT_NEW_ARCH_ENABLED"] == "1" then
|
|
41
42
|
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
42
43
|
s.pod_target_xcconfig = base_config.merge({
|
|
43
44
|
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
44
45
|
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
45
46
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
46
47
|
})
|
|
47
|
-
|
|
48
|
+
|
|
48
49
|
s.dependency "React-Codegen"
|
|
49
50
|
s.dependency "RCT-Folly"
|
|
50
51
|
s.dependency "RCTRequired"
|
|
51
52
|
s.dependency "RCTTypeSafety"
|
|
52
53
|
s.dependency "ReactCommon/turbomodule/core"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -43,86 +43,29 @@ ext.readPackageJson = { File packageJsonFile ->
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
// Walk up the directory tree looking for brick.json
|
|
48
|
-
if (!startDir) {
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
def current = new File(startDir).canonicalFile
|
|
54
|
-
def root = new File('/').canonicalFile
|
|
55
|
-
|
|
56
|
-
while (current != root && current != null) {
|
|
57
|
-
def brickJsonFile = new File(current, 'brick.json')
|
|
58
|
-
if (brickJsonFile.exists()) {
|
|
59
|
-
return brickJsonFile
|
|
60
|
-
}
|
|
61
|
-
def parent = current.parentFile
|
|
62
|
-
if (parent == current || parent == null) break // Reached filesystem root
|
|
63
|
-
current = parent
|
|
64
|
-
}
|
|
65
|
-
} catch (Exception e) {
|
|
66
|
-
// Failed to process directory, return null
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return null
|
|
70
|
-
}
|
|
46
|
+
// Removed discovery helpers; explicit appPath is required
|
|
71
47
|
|
|
72
|
-
ext.
|
|
73
|
-
//
|
|
74
|
-
if (!projectRootPath || !configDir) {
|
|
75
|
-
return null
|
|
76
|
-
}
|
|
77
|
-
|
|
48
|
+
ext.getBrickAndroidPath = { projectRoot ->
|
|
49
|
+
// Read brick.json from explicit project root
|
|
78
50
|
try {
|
|
79
|
-
def
|
|
80
|
-
if (
|
|
81
|
-
return projectRootFile.exists() ? projectRootFile : null
|
|
82
|
-
} else {
|
|
83
|
-
// Relative to brick.json location
|
|
84
|
-
def resolvedFile = new File(configDir, projectRootPath).canonicalFile
|
|
85
|
-
return resolvedFile.exists() ? resolvedFile : null
|
|
86
|
-
}
|
|
87
|
-
} catch (Exception e) {
|
|
88
|
-
return null
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
ext.getBrickAndroidPath = { searchRoot ->
|
|
93
|
-
// Walk up directory tree to find brick.json
|
|
94
|
-
def brickConfigFile = findBrickJson(searchRoot)
|
|
95
|
-
|
|
96
|
-
if (brickConfigFile && brickConfigFile.exists()) {
|
|
97
|
-
try {
|
|
51
|
+
def brickConfigFile = new File(projectRoot, 'brick.json')
|
|
52
|
+
if (brickConfigFile.exists()) {
|
|
98
53
|
def config = new JsonSlurper().parse(brickConfigFile)
|
|
99
|
-
|
|
100
|
-
// Get the effective project root
|
|
101
|
-
def effectiveRoot = brickConfigFile.parentFile
|
|
102
|
-
if (config.projectRoot) {
|
|
103
|
-
def resolvedRoot = resolveProjectRoot(config.projectRoot, brickConfigFile.parentFile)
|
|
104
|
-
if (resolvedRoot) {
|
|
105
|
-
effectiveRoot = resolvedRoot
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
54
|
def androidPath = config?.output?.android
|
|
110
55
|
if (androidPath && !androidPath.isEmpty()) {
|
|
111
|
-
// Handle absolute paths (though not recommended)
|
|
112
56
|
if (new File(androidPath).isAbsolute()) {
|
|
113
57
|
println("[Brick] Warning: Using absolute path for Android output is not recommended: ${androidPath}")
|
|
114
58
|
return androidPath
|
|
115
59
|
}
|
|
116
|
-
|
|
117
|
-
return new File(effectiveRoot, androidPath).canonicalPath
|
|
60
|
+
return new File(projectRoot, androidPath).canonicalPath
|
|
118
61
|
}
|
|
119
|
-
} catch (Exception e) {
|
|
120
|
-
println("[Brick] Warning: Failed to parse brick.json: ${e.message}")
|
|
121
62
|
}
|
|
63
|
+
} catch (Exception e) {
|
|
64
|
+
println("[Brick] Warning: Failed to read brick.json from ${projectRoot}: ${e.message}")
|
|
122
65
|
}
|
|
123
66
|
|
|
124
|
-
// Default:
|
|
125
|
-
return new File(
|
|
67
|
+
// Default: android/.brick in project root
|
|
68
|
+
return new File(projectRoot, 'android/.brick').canonicalPath
|
|
126
69
|
}
|
|
127
70
|
|
|
128
71
|
ext.getAllDependencies = { packageJson ->
|
|
@@ -136,44 +79,6 @@ ext.isBrickModule = { packageJson ->
|
|
|
136
79
|
return packageJson?.brickModule != null
|
|
137
80
|
}
|
|
138
81
|
|
|
139
|
-
ext.findProjectRoot = { androidDir ->
|
|
140
|
-
// 1. Walk up directory tree to find brick.json
|
|
141
|
-
def brickConfigFile = findBrickJson(androidDir)
|
|
142
|
-
if (brickConfigFile) {
|
|
143
|
-
brickLog("Found brick.json at: ${brickConfigFile.canonicalPath}")
|
|
144
|
-
try {
|
|
145
|
-
def config = new JsonSlurper().parse(brickConfigFile)
|
|
146
|
-
if (config.projectRoot) {
|
|
147
|
-
def projectRoot = resolveProjectRoot(config.projectRoot, brickConfigFile.parentFile)
|
|
148
|
-
if (projectRoot) {
|
|
149
|
-
brickLog("Using projectRoot from brick.json: ${projectRoot.canonicalPath}")
|
|
150
|
-
return projectRoot
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
// If brick.json exists but has no projectRoot, use its directory as project root
|
|
154
|
-
return brickConfigFile.parentFile
|
|
155
|
-
} catch (Exception e) {
|
|
156
|
-
println("[Brick] Warning: Failed to parse brick.json: ${e.message}")
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 2. Walk up to find package.json with node_modules
|
|
161
|
-
def current = androidDir
|
|
162
|
-
while (current != null && current != new File('/')) {
|
|
163
|
-
if (new File(current, 'package.json').exists() && new File(current, 'node_modules').exists()) {
|
|
164
|
-
brickLog("Found project root via package.json: ${current.canonicalPath}")
|
|
165
|
-
return current
|
|
166
|
-
}
|
|
167
|
-
def parent = current.parentFile
|
|
168
|
-
if (parent == current) break
|
|
169
|
-
current = parent
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// If no project root found, use default fallback
|
|
173
|
-
brickLog("Warning: Failed to find project root via brick.json or package.json. Using default: ${androidDir.parentFile.canonicalPath}")
|
|
174
|
-
return androidDir.parentFile
|
|
175
|
-
}
|
|
176
|
-
|
|
177
82
|
ext.runBrickCodegen = { workingDir ->
|
|
178
83
|
def brickModuleDir = resolveModule(workingDir, "brick-module")
|
|
179
84
|
if (brickModuleDir == null) {
|
|
@@ -188,7 +93,8 @@ ext.runBrickCodegen = { workingDir ->
|
|
|
188
93
|
}
|
|
189
94
|
|
|
190
95
|
try {
|
|
191
|
-
def
|
|
96
|
+
def wdPath = (workingDir instanceof File) ? workingDir.absolutePath : workingDir
|
|
97
|
+
def proc = ['node', codegenPath.absolutePath, '--platform', 'android', '--projectRoot', wdPath].execute(null, workingDir)
|
|
192
98
|
proc.waitFor()
|
|
193
99
|
return proc.exitValue() == 0
|
|
194
100
|
} catch (Exception e) {
|
|
@@ -201,13 +107,26 @@ ext.runBrickCodegen = { workingDir ->
|
|
|
201
107
|
// Main Configuration
|
|
202
108
|
// =============================================================================
|
|
203
109
|
|
|
204
|
-
ext.applyBrickModules = { settings ->
|
|
205
|
-
def
|
|
110
|
+
ext.applyBrickModules = { settings, args = [:] ->
|
|
111
|
+
def appPath = (args instanceof Map) ? args.appPath : args
|
|
112
|
+
if (!appPath) {
|
|
113
|
+
throw new GradleException("Brick: appPath is required. Call applyBrickModules(settings, [appPath: '/absolute/path/to/app'])")
|
|
114
|
+
}
|
|
115
|
+
// Support relative appPath (relative to settings.rootDir)
|
|
116
|
+
def appPathFile = new File(appPath.toString())
|
|
117
|
+
def projectRoot = (appPathFile.isAbsolute() ? appPathFile : new File(settings.rootDir, appPathFile.path)).canonicalFile
|
|
118
|
+
|
|
119
|
+
// Validate package.json exists in appPath
|
|
120
|
+
def packageJsonFile = new File(projectRoot, 'package.json')
|
|
121
|
+
if (!packageJsonFile.exists()) {
|
|
122
|
+
throw new GradleException("Brick: package.json not found at ${projectRoot}. Please pass a valid appPath.")
|
|
123
|
+
}
|
|
124
|
+
|
|
206
125
|
def foundModules = []
|
|
207
126
|
def brickModulesData = [:]
|
|
208
127
|
|
|
209
128
|
// Read app's package.json
|
|
210
|
-
def appPackageJson = readPackageJson(
|
|
129
|
+
def appPackageJson = readPackageJson(packageJsonFile)
|
|
211
130
|
if (appPackageJson == null) {
|
|
212
131
|
throw new GradleException("Could not find or parse package.json at ${projectRoot}")
|
|
213
132
|
}
|
|
@@ -265,7 +184,7 @@ ext.applyBrickModules = { settings ->
|
|
|
265
184
|
}
|
|
266
185
|
|
|
267
186
|
// Check if codegen is needed (use configured path)
|
|
268
|
-
def androidBrickPath = getBrickAndroidPath(
|
|
187
|
+
def androidBrickPath = getBrickAndroidPath(projectRoot)
|
|
269
188
|
def brickDir = new File(androidBrickPath)
|
|
270
189
|
def needsCodegen = !brickDir.exists() || !new File(brickDir, "src/main/kotlin/BrickModule.kt").exists()
|
|
271
190
|
|
|
@@ -308,7 +227,7 @@ def configureAppProject(gradle) {
|
|
|
308
227
|
def configureBrickModules(project) {
|
|
309
228
|
def rootProject = project.rootProject
|
|
310
229
|
def brickModulesData = rootProject.ext.brickModulesData
|
|
311
|
-
def projectRoot =
|
|
230
|
+
def projectRoot = rootProject.ext.brickProjectRoot
|
|
312
231
|
|
|
313
232
|
// Add source directory for generated code
|
|
314
233
|
project.android.sourceSets.main.java.srcDir "${project.buildDir}/generated/source/brick-provider"
|
|
@@ -340,7 +259,7 @@ def configureBrickModules(project) {
|
|
|
340
259
|
def codegenPath = new File(brickModuleDir, "bin/brick-codegen.js")
|
|
341
260
|
|
|
342
261
|
if (codegenPath.exists()) {
|
|
343
|
-
def codegenProc = ['node', codegenPath.absolutePath, '--platform', 'android'].execute(null, workingDir)
|
|
262
|
+
def codegenProc = ['node', codegenPath.absolutePath, '--platform', 'android', '--projectRoot', workingDir.absolutePath].execute(null, workingDir)
|
|
344
263
|
codegenProc.waitFor()
|
|
345
264
|
}
|
|
346
265
|
}
|
package/android/build.gradle
CHANGED
|
@@ -65,7 +65,6 @@ android {
|
|
|
65
65
|
defaultConfig {
|
|
66
66
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
67
67
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
68
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
69
68
|
consumerProguardFiles 'proguard-rules.pro'
|
|
70
69
|
buildConfigField "long", "BUILD_TIMESTAMP", "${System.currentTimeMillis()}L"
|
|
71
70
|
}
|
|
@@ -39,8 +39,7 @@ class BrickModulePackage : TurboReactPackage() {
|
|
|
39
39
|
val currentClassLoader = Thread.currentThread().contextClassLoader
|
|
40
40
|
val generatedClass =
|
|
41
41
|
Class.forName("com.brickmodule.BrickModule", true, currentClassLoader)
|
|
42
|
-
val constructor =
|
|
43
|
-
generatedClass.getConstructor(ReactContext::class.java)
|
|
42
|
+
val constructor = generatedClass.getConstructor(ReactContext::class.java)
|
|
44
43
|
val instance = constructor.newInstance(reactContext) as NativeModule
|
|
45
44
|
println(
|
|
46
45
|
"✅ BrickModule successfully created with thread classloader: ${instance.javaClass.name}"
|
|
@@ -68,7 +67,7 @@ class BrickModulePackage : TurboReactPackage() {
|
|
|
68
67
|
println("🔍 BrickModulePackage.getReactModuleInfoProvider called")
|
|
69
68
|
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
70
69
|
// Force TurboModule to true since we're using NativeBrickModuleSpec
|
|
71
|
-
val isTurboModule: Boolean =
|
|
70
|
+
val isTurboModule: Boolean = true
|
|
72
71
|
moduleInfos["BrickModule"] =
|
|
73
72
|
ReactModuleInfo(
|
|
74
73
|
"BrickModule",
|
|
@@ -14,7 +14,7 @@ class BrickModuleRegistry {
|
|
|
14
14
|
private var isRegistered: Boolean = false
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Registers an array of Brick modules Each module must implement their respective
|
|
17
|
+
* Registers an array of Brick modules Each module must implement their respective Spec
|
|
18
18
|
* interface
|
|
19
19
|
*
|
|
20
20
|
* @param modules List of module instances to register
|
|
@@ -50,7 +50,7 @@ class BrickModuleRegistry {
|
|
|
50
50
|
// Register or update the module
|
|
51
51
|
val isUpdate = modules.containsKey(moduleName)
|
|
52
52
|
modules[moduleName] = module
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
if (isUpdate) {
|
|
55
55
|
println("🔄 BrickModuleRegistry: Module '$moduleName' updated (replaced existing)")
|
|
56
56
|
} else {
|
package/dist/BrickModule.js
CHANGED
|
@@ -82,6 +82,10 @@ const BrickModule = {
|
|
|
82
82
|
getRegisteredModules,
|
|
83
83
|
clearCache
|
|
84
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Default export for convenience
|
|
87
|
+
*/
|
|
88
|
+
var BrickModule_default = BrickModule;
|
|
85
89
|
|
|
86
90
|
//#endregion
|
|
87
|
-
export {
|
|
91
|
+
export { BrickModule_default as default };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BrickModule_default from "./BrickModule.js";
|
|
2
2
|
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
/**
|
|
5
5
|
* Error types for Brick modules
|
|
6
6
|
*/
|
|
7
7
|
var BrickModuleError = class extends Error {
|
|
8
|
-
constructor(message, code = "
|
|
8
|
+
constructor(message, code = "BRICK_ERROR", moduleName, methodName) {
|
|
9
9
|
super(message);
|
|
10
10
|
this.code = code;
|
|
11
11
|
this.moduleName = moduleName;
|
|
@@ -15,4 +15,4 @@ var BrickModuleError = class extends Error {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
|
-
export { BrickModule, BrickModuleError };
|
|
18
|
+
export { BrickModule_default as BrickModule, BrickModuleError };
|
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import React
|
|
2
3
|
|
|
3
|
-
@objc public protocol BrickModuleRegistableViewControllerType {
|
|
4
|
-
@objc var moduleRegistry: BrickModuleRegistry? { get }
|
|
5
|
-
}
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Base class for all Brick modules
|
|
6
|
+
* Provides common functionality including event emission
|
|
9
7
|
*/
|
|
10
|
-
|
|
8
|
+
open class BrickModuleBase: NSObject {
|
|
11
9
|
/// The name of the module (required for registration)
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
public let moduleName: String
|
|
11
|
+
|
|
12
|
+
public weak var eventEmitter: RCTEventEmitter?
|
|
13
|
+
public weak var bridgeProxy: RCTBridgeProxy?
|
|
14
|
+
|
|
15
|
+
/// Initialize with module name
|
|
16
|
+
public init(moduleName: String) {
|
|
17
|
+
self.moduleName = moduleName
|
|
18
|
+
super.init()
|
|
19
|
+
}
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
/// Sends an event with the given name and data
|
|
22
|
+
/// Automatically prefixes with module name and uses the registry's event emitter
|
|
23
|
+
public func sendEvent(_ eventName: String, data: [String: Any]?) {
|
|
24
|
+
// Format event name with module prefix
|
|
25
|
+
let fullEventName = "\(moduleName)_\(eventName)"
|
|
26
|
+
|
|
27
|
+
// Get the shared event emitter instance and send event
|
|
28
|
+
if let eventEmitter = self.eventEmitter {
|
|
29
|
+
eventEmitter.sendEvent(withName: fullEventName, body: data)
|
|
30
|
+
} else {
|
|
31
|
+
let error = NSError(domain: "BrickModule", code: 500, userInfo: [
|
|
32
|
+
NSLocalizedDescriptionKey: "Event emitter not available, cannot send event: \(fullEventName)"
|
|
33
|
+
])
|
|
34
|
+
print("Error: \(error.localizedDescription)")
|
|
35
|
+
}
|
|
36
|
+
}
|
|
16
37
|
}
|
|
17
38
|
|
|
18
39
|
/**
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BrickModuleRegistrable.swift
|
|
3
|
+
// BrickModule
|
|
4
|
+
//
|
|
5
|
+
// Protocol for BrickModule registration - Swift-style naming convention
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import UIKit
|
|
9
|
+
import React
|
|
10
|
+
|
|
11
|
+
/// Protocol for BrickModule registration and management
|
|
12
|
+
/// This matches Android's BrickModuleRegistrar interface with Swift naming conventions
|
|
13
|
+
public protocol BrickModuleRegistrable {
|
|
14
|
+
|
|
15
|
+
// MARK: - Module Registry Management
|
|
16
|
+
|
|
17
|
+
/// Module registry - property instead of getter method
|
|
18
|
+
/// This registry manages all registered BrickModules
|
|
19
|
+
var moduleRegistry: BrickModuleRegistry { get }
|
|
20
|
+
|
|
21
|
+
/// Register modules when bridge is ready - using 'on' parameter label
|
|
22
|
+
/// Called after didInitializeBridge to register BrickModules
|
|
23
|
+
func registerModules()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import React
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Central registry for all Brick modules
|
|
6
7
|
* Manages module lifecycle and provides simple module storage
|
|
7
8
|
*/
|
|
8
9
|
@objc public class BrickModuleRegistry: NSObject {
|
|
9
10
|
|
|
10
|
-
private var modules: [String:
|
|
11
|
+
private var modules: [String: BrickModuleBase] = [:]
|
|
11
12
|
private var isRegistered: Bool = false
|
|
12
|
-
|
|
13
|
+
private weak var eventEmitter: RCTEventEmitter?
|
|
14
|
+
private weak var bridgeProxy: RCTBridgeProxy?;
|
|
13
15
|
|
|
14
16
|
public override init() {
|
|
15
17
|
super.init()
|
|
@@ -19,13 +21,12 @@ import React
|
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Registers an array of Brick modules (Swift API)
|
|
22
|
-
* Each module must implement BrickModuleBase and its respective
|
|
24
|
+
* Each module must implement BrickModuleBase and its respective Spec protocol
|
|
23
25
|
* This should be called once during app initialization
|
|
24
26
|
*/
|
|
25
27
|
public func register(_ modules: [BrickModuleBase]) {
|
|
26
|
-
|
|
27
|
-
print("
|
|
28
|
-
return
|
|
28
|
+
if isRegistered {
|
|
29
|
+
print("♻️ BrickModuleRegistry: Re-registering modules. Existing modules may be overwritten.")
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
for module in modules {
|
|
@@ -34,10 +35,6 @@ import React
|
|
|
34
35
|
|
|
35
36
|
isRegistered = true
|
|
36
37
|
print("✅ BrickModuleRegistry: Successfully registered \(self.modules.count) modules")
|
|
37
|
-
|
|
38
|
-
if ProcessInfo.processInfo.environment["GRANITE_DEBUG"] == "1" {
|
|
39
|
-
debugPrintRegisteredModules()
|
|
40
|
-
}
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
/**
|
|
@@ -49,7 +46,7 @@ import React
|
|
|
49
46
|
public func registerModules(_ modules: NSArray) {
|
|
50
47
|
let brickModules = modules.compactMap { $0 as? BrickModuleBase }
|
|
51
48
|
register(brickModules)
|
|
52
|
-
|
|
49
|
+
}
|
|
53
50
|
|
|
54
51
|
private func registerSingleModule(_ module: BrickModuleBase) {
|
|
55
52
|
let moduleName = module.moduleName
|
|
@@ -60,14 +57,10 @@ import React
|
|
|
60
57
|
return
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
// Check for module name conflicts
|
|
64
|
-
if modules.keys.contains(moduleName) {
|
|
65
|
-
print("⚠️ BrickModuleRegistry: Module '\(moduleName)' is already registered. Skipping.")
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
60
|
// Register the module
|
|
70
61
|
modules[moduleName] = module
|
|
62
|
+
modules[moduleName]?.eventEmitter = self.eventEmitter;
|
|
63
|
+
modules[moduleName]?.bridgeProxy = self.bridgeProxy;
|
|
71
64
|
print("📦 BrickModuleRegistry: Registered module '\(moduleName)'")
|
|
72
65
|
}
|
|
73
66
|
|
|
@@ -81,6 +74,14 @@ import React
|
|
|
81
74
|
return modules[moduleName]
|
|
82
75
|
}
|
|
83
76
|
|
|
77
|
+
|
|
78
|
+
public func setBridge(_ bridge: Any) {
|
|
79
|
+
self.bridgeProxy = bridge as? RCTBridgeProxy;
|
|
80
|
+
for module in modules {
|
|
81
|
+
module.value.bridgeProxy = self.bridgeProxy;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
84
85
|
/**
|
|
85
86
|
* Returns list of registered module names
|
|
86
87
|
*/
|
|
@@ -92,11 +93,13 @@ import React
|
|
|
92
93
|
|
|
93
94
|
/**
|
|
94
95
|
* Sets the React Native event emitter instance for event emission
|
|
95
|
-
* This should be called during app initialization
|
|
96
|
+
* This should be called during app initialization frBrickModuleom the main BrickModule
|
|
96
97
|
*/
|
|
97
|
-
|
|
98
|
-
self.eventEmitter = eventEmitter
|
|
99
|
-
|
|
98
|
+
public func setEventEmitter(_ eventEmitter: Any) {
|
|
99
|
+
self.eventEmitter = eventEmitter as? RCTEventEmitter
|
|
100
|
+
for module in modules {
|
|
101
|
+
module.value.eventEmitter = self.eventEmitter
|
|
102
|
+
}
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
/**
|
|
@@ -106,36 +109,24 @@ import React
|
|
|
106
109
|
@objc public func getEventEmitter() -> RCTEventEmitter? {
|
|
107
110
|
return eventEmitter
|
|
108
111
|
}
|
|
109
|
-
|
|
110
|
-
// MARK: - Debug & Development
|
|
111
|
-
|
|
112
|
-
private func debugPrintRegisteredModules() {
|
|
113
|
-
print("🔍 BrickModuleRegistry Debug Info:")
|
|
114
|
-
print(" Total Modules: \(modules.count)")
|
|
115
112
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Unregisters all modules and clears their registry references
|
|
115
|
+
*/
|
|
116
|
+
@objc public func unregister() {
|
|
117
|
+
modules.removeAll()
|
|
118
|
+
isRegistered = false
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
/**
|
|
123
122
|
* Clears all registered modules (for testing purposes only)
|
|
124
123
|
*/
|
|
125
124
|
@objc public func clearRegistry() {
|
|
126
|
-
|
|
127
|
-
ProcessInfo.processInfo.environment["GRANITE_ALLOW_CLEAR"] == "1" else {
|
|
128
|
-
print("⚠️ BrickModuleRegistry: clearRegistry() is only allowed in test environment")
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
modules.removeAll()
|
|
133
|
-
isRegistered = false
|
|
134
|
-
|
|
135
|
-
print("🧹 BrickModuleRegistry: Registry cleared")
|
|
125
|
+
unregister()
|
|
136
126
|
}
|
|
137
127
|
}
|
|
138
128
|
|
|
139
129
|
public class ModuleRegistry {
|
|
140
130
|
|
|
141
131
|
}
|
|
132
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brick-module",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Better React Native native module development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,8 +16,19 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist/",
|
|
19
|
-
"ios
|
|
20
|
-
"android
|
|
19
|
+
"ios",
|
|
20
|
+
"android",
|
|
21
|
+
"react-native.config.js",
|
|
22
|
+
"!ios/build",
|
|
23
|
+
"!android/build",
|
|
24
|
+
"!android/gradle",
|
|
25
|
+
"!android/gradlew",
|
|
26
|
+
"!android/gradlew.bat",
|
|
27
|
+
"!android/local.properties",
|
|
28
|
+
"!**/__tests__",
|
|
29
|
+
"!**/__fixtures__",
|
|
30
|
+
"!**/__mocks__",
|
|
31
|
+
"!**/.*",
|
|
21
32
|
"src/",
|
|
22
33
|
"bin/",
|
|
23
34
|
"BrickModule.podspec",
|
|
@@ -51,7 +62,7 @@
|
|
|
51
62
|
"brick-codegen": "./bin/brick-codegen.js"
|
|
52
63
|
},
|
|
53
64
|
"dependencies": {
|
|
54
|
-
"brick-codegen": "0.1.
|
|
65
|
+
"brick-codegen": "0.1.8"
|
|
55
66
|
},
|
|
56
67
|
"peerDependencies": {
|
|
57
68
|
"react": ">=18.2.0",
|
|
@@ -60,7 +71,7 @@
|
|
|
60
71
|
"devDependencies": {
|
|
61
72
|
"@types/react": "^18.2.0",
|
|
62
73
|
"@types/react-native": "^0.72.0",
|
|
63
|
-
"tsdown": "^0.14.
|
|
74
|
+
"tsdown": "^0.14.2",
|
|
64
75
|
"typescript": "^5.9.2"
|
|
65
76
|
},
|
|
66
77
|
"codegenConfig": {
|