Browse Source

Fixed crash when unregistering EventBus subsribers

closes #291
Guy Carmeli 8 years ago
parent
commit
653b0716ff

+ 4
- 1
android/app/src/main/java/com/reactnativenavigation/events/EventBus.java View File

@@ -3,6 +3,7 @@ package com.reactnativenavigation.events;
3 3
 import java.lang.ref.WeakReference;
4 4
 import java.util.ArrayList;
5 5
 import java.util.List;
6
+import java.util.ListIterator;
6 7
 
7 8
 public enum EventBus {
8 9
     instance;
@@ -15,7 +16,9 @@ public enum EventBus {
15 16
     }
16 17
 
17 18
     public void unregister(Subscriber subscriber) {
18
-        for (WeakReference<Subscriber> ref : subscribers) {
19
+        ListIterator<WeakReference<Subscriber>> iterator = subscribers.listIterator();
20
+        while (iterator.hasNext()) {
21
+            WeakReference<Subscriber> ref = iterator.next();
19 22
             Subscriber registered = ref.get();
20 23
             if (registered != null && registered == subscriber) {
21 24
                 subscribers.remove(ref);