react-native-flic2 2.0.0-beta.8 → 2.0.0-beta.9

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.
@@ -86,6 +86,31 @@ class Flic2Module(reactContext: ReactApplicationContext) :
86
86
 
87
87
  override fun invalidate() {
88
88
  super.invalidate()
89
+
90
+ // Remove all button listeners before cleanup to prevent callbacks after teardown
91
+ try {
92
+ val manager = flic2Service?.getManager()
93
+ if (manager != null) {
94
+ buttonListeners.forEach { (uuid, listener) ->
95
+ try {
96
+ // Find the button and remove the listener
97
+ val button = manager.buttons.find { it.uuid == uuid }
98
+ if (button != null) {
99
+ button.removeListener(listener)
100
+ Log.d(TAG, "Removed listener for button during invalidate: $uuid")
101
+ }
102
+ } catch (e: Exception) {
103
+ Log.w(TAG, "Failed to remove listener for button during invalidate: $uuid", e)
104
+ }
105
+ }
106
+ }
107
+ } catch (e: Exception) {
108
+ Log.w(TAG, "Error during listener cleanup in invalidate", e)
109
+ }
110
+
111
+ // Clear listeners map
112
+ buttonListeners.clear()
113
+
89
114
  moduleScope.cancel()
90
115
  if (serviceBound) {
91
116
  reactApplicationContext.unbindService(serviceConnection)
@@ -246,7 +271,18 @@ class Flic2Module(reactContext: ReactApplicationContext) :
246
271
  // Disconnect before forgetting like iOS
247
272
  button.disconnectOrAbortPendingConnection()
248
273
 
249
- // Remove listener
274
+ // Explicitly remove listener from button before forgetting (matches old implementation)
275
+ val listener = buttonListeners[uuid]
276
+ if (listener != null) {
277
+ try {
278
+ button.removeListener(listener)
279
+ Log.d(TAG, "Removed listener for button: $uuid")
280
+ } catch (e: Exception) {
281
+ Log.w(TAG, "Failed to remove listener for button: $uuid", e)
282
+ }
283
+ }
284
+
285
+ // Remove listener from map
250
286
  buttonListeners.remove(uuid)
251
287
 
252
288
  // Forget button
@@ -387,8 +423,24 @@ class Flic2Module(reactContext: ReactApplicationContext) :
387
423
  val buttons = manager.buttons.toList()
388
424
 
389
425
  buttons.forEach { button ->
426
+ // Explicitly remove listener from button before forgetting (matches old implementation)
427
+ val listener = buttonListeners[button.uuid]
428
+ if (listener != null) {
429
+ try {
430
+ button.removeListener(listener)
431
+ Log.d(TAG, "Removed listener for button: ${button.uuid}")
432
+ } catch (e: Exception) {
433
+ Log.w(TAG, "Failed to remove listener for button: ${button.uuid}", e)
434
+ }
435
+ }
436
+
437
+ // Remove listener from map
390
438
  buttonListeners.remove(button.uuid)
439
+
440
+ // Disconnect before forgetting
391
441
  button.disconnectOrAbortPendingConnection()
442
+
443
+ // Forget button
392
444
  manager.forgetButton(button)
393
445
  }
394
446
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-flic2",
3
- "version": "2.0.0-beta.8",
3
+ "version": "2.0.0-beta.9",
4
4
  "description": "React Native Flic plugin made with the Flic2 SDK (unofficial)",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",