brick-module 0.1.17 → 0.1.19

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.
@@ -228,42 +228,14 @@ ext.applyBrickModules = { settings, args ->
228
228
  cmake_minimum_required(VERSION 3.13)
229
229
  set(CMAKE_VERBOSE_MAKEFILE on)
230
230
 
231
- # Header for BrickModuleSpec. When included by RN autolinking (no BRICKMODULESPEC_DUMMY_IMPL),
232
- # include RN headers and provide an inline nullptr-returning implementation. When building the
233
- # dummy static library (with BRICKMODULESPEC_DUMMY_IMPL), avoid depending on RN headers.
234
- file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/BrickModuleSpec.h [[
235
- /** Auto-generated dummy header for BrickModuleSpec */
236
- #pragma once
237
- #include <memory>
238
- #include <string>
239
- namespace facebook { namespace react {
240
-
241
- #ifndef BRICKMODULESPEC_DUMMY_IMPL
242
- #include <ReactCommon/JavaTurboModule.h>
243
- inline std::shared_ptr<TurboModule> BrickModuleSpec_ModuleProvider(
244
- const std::string & /*moduleName*/, const JavaTurboModule::InitParams & /*params*/) {
245
- return nullptr;
246
- }
247
- #else
248
- class TurboModule; // forward declaration
249
- class JavaTurboModule; // forward declaration
250
- #endif
251
-
252
- }} // namespace facebook::react
253
- ]])
254
-
255
- # Create a trivial compilation unit for the static library
256
- file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp [[
257
- // Dummy TU for react_codegen_BrickModuleSpec
258
- int brick_codegen_BrickModuleSpec_dummy = 0;
259
- ]])
231
+ # Create a dummy source file
232
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "// Dummy file for BrickModuleSpec\n")
260
233
 
261
234
  # Create an empty static library to satisfy React Native's build system
262
235
  add_library(react_codegen_BrickModuleSpec STATIC ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
263
236
 
264
237
  # Set necessary properties
265
238
  target_include_directories(react_codegen_BrickModuleSpec PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
266
- target_compile_definitions(react_codegen_BrickModuleSpec PRIVATE BRICKMODULESPEC_DUMMY_IMPL=1)
267
239
  '''
268
240
 
269
241
  def prepareTask = subproj.tasks.findByName('prepareBrickModuleAutolinkCMake') ?: subproj.tasks.create('prepareBrickModuleAutolinkCMake') {
@@ -33,9 +33,21 @@ function get(moduleName) {
33
33
  get: (_target, property) => {
34
34
  if (typeof property !== "string") return;
35
35
  if (property === "addEventListener") return (eventName, listener) => {
36
- const subscription = getEventEmitter().addListener(`${moduleName}_${eventName}`, listener);
36
+ const emitter = getEventEmitter();
37
+ try {
38
+ const native = getNativeModule();
39
+ const moduleAddName = `${moduleName}_onEventListenerAdded`;
40
+ if (typeof native[moduleAddName] === "function") native[moduleAddName](eventName);
41
+ } catch {}
42
+ const subscription = emitter.addListener(`${moduleName}_${eventName}`, listener);
37
43
  return () => {
38
- subscription.remove();
44
+ const native = getNativeModule();
45
+ const moduleRemoveName = `${moduleName}_onEventListenerRemoved`;
46
+ try {
47
+ if (typeof native[moduleRemoveName] === "function") native[moduleRemoveName](eventName);
48
+ } catch {} finally {
49
+ subscription.remove();
50
+ }
39
51
  };
40
52
  };
41
53
  const allConstants = nativeModuleInstance?.getConstants?.() ?? {};
@@ -20,7 +20,7 @@ open class BrickModuleBase: NSObject {
20
20
 
21
21
  /// Sends an event with the given name and data
22
22
  /// Automatically prefixes with module name and uses the registry's event emitter
23
- public func sendEvent(_ eventName: String, data: [String: Any]?) {
23
+ public func sendEvent(_ eventName: String, data: Any?) {
24
24
  // Format event name with module prefix
25
25
  let fullEventName = "\(moduleName)_\(eventName)"
26
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brick-module",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Better React Native native module development",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -62,7 +62,7 @@
62
62
  "brick-codegen": "./bin/brick-codegen.js"
63
63
  },
64
64
  "dependencies": {
65
- "brick-codegen": "0.1.17"
65
+ "brick-codegen": "0.1.19"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "react": ">=18.2.0",
@@ -94,13 +94,35 @@ function get<T extends BrickModuleInterface>(
94
94
  if (property === "addEventListener") {
95
95
  return (eventName: string, listener: (event: unknown) => void) => {
96
96
  const emitter = getEventEmitter();
97
+ // Inform native module about listener addition (module-specific)
98
+ try {
99
+ const native = getNativeModule();
100
+ const moduleAddName = `${moduleName}_onEventListenerAdded`;
101
+ if (typeof native[moduleAddName] === "function") {
102
+ native[moduleAddName](eventName);
103
+ }
104
+ } catch {
105
+ // ignore
106
+ }
107
+
97
108
  const subscription = emitter.addListener(
98
109
  `${moduleName}_${eventName}`,
99
110
  listener
100
111
  );
101
112
 
102
113
  return () => {
103
- subscription.remove();
114
+ const native = getNativeModule();
115
+ const moduleRemoveName = `${moduleName}_onEventListenerRemoved`;
116
+ try {
117
+ // Prefer module-specific native removal for precise cleanup
118
+ if (typeof native[moduleRemoveName] === "function") {
119
+ native[moduleRemoveName](eventName);
120
+ }
121
+ } catch {
122
+ // ignore
123
+ } finally {
124
+ subscription.remove();
125
+ }
104
126
  };
105
127
  };
106
128
  }