Browse Source

Emit modalDismissed event when modals are dismissed on Android

Guy Carmeli 6 years ago
parent
commit
9543b539d5

+ 9
- 4
lib/android/app/src/main/java/com/reactnativenavigation/react/EventEmitter.java View File

14
 	private static final String ComponentDidAppear      = "RNN.ComponentDidAppear";
14
 	private static final String ComponentDidAppear      = "RNN.ComponentDidAppear";
15
 	private static final String ComponentDidDisappear   = "RNN.ComponentDidDisappear";
15
 	private static final String ComponentDidDisappear   = "RNN.ComponentDidDisappear";
16
 	private static final String NavigationButtonPressed = "RNN.NavigationButtonPressed";
16
 	private static final String NavigationButtonPressed = "RNN.NavigationButtonPressed";
17
-	private static final String SearchBarUpdated        = "RNN.SearchBarUpdated";
18
-	private static final String SearchBarCancelPressed  = "RNN.SearchBarCancelPressed";
17
+    private static final String ModalDismissed          = "RNN.ModalDismissed";
19
 
18
 
20
 	private final RCTDeviceEventEmitter emitter;
19
 	private final RCTDeviceEventEmitter emitter;
21
 
20
 
22
-	EventEmitter(ReactContext reactContext) {
21
+	public EventEmitter(ReactContext reactContext) {
23
 		this.emitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
22
 		this.emitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
24
 	}
23
 	}
25
 
24
 
55
 		emit(BottomTabSelected, event);
54
 		emit(BottomTabSelected, event);
56
 	}
55
 	}
57
 
56
 
58
-	public void emitCommandCompletedEvent(String commandId, long completionTime) {
57
+	public void emitCommandCompleted(String commandId, long completionTime) {
59
 		WritableMap event = Arguments.createMap();
58
 		WritableMap event = Arguments.createMap();
60
 		event.putString("commandId", commandId);
59
 		event.putString("commandId", commandId);
61
 		event.putDouble("completionTime", completionTime);
60
 		event.putDouble("completionTime", completionTime);
62
 		emit(CommandCompleted, event);
61
 		emit(CommandCompleted, event);
63
 	}
62
 	}
64
 
63
 
64
+    public void emitModalDismissed(String id) {
65
+        WritableMap event = Arguments.createMap();
66
+        event.putString("componentId", id);
67
+        emit(ModalDismissed, event);
68
+    }
69
+
65
 	private void emit(String eventName) {
70
 	private void emit(String eventName) {
66
 		emit(eventName, Arguments.createMap());
71
 		emit(eventName, Arguments.createMap());
67
 	}
72
 	}

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java View File

61
 	public void setRoot(String commandId, ReadableMap rawLayoutTree, Promise promise) {
61
 	public void setRoot(String commandId, ReadableMap rawLayoutTree, Promise promise) {
62
 		final LayoutNode layoutTree = LayoutNodeParser.parse(JSONParser.parse(rawLayoutTree).optJSONObject("root"));
62
 		final LayoutNode layoutTree = LayoutNodeParser.parse(JSONParser.parse(rawLayoutTree).optJSONObject("root"));
63
 		handle(() -> {
63
 		handle(() -> {
64
+            navigator().setEventEmitter(eventEmitter);
64
             final ViewController viewController = newLayoutFactory().create(layoutTree);
65
             final ViewController viewController = newLayoutFactory().create(layoutTree);
65
             navigator().setRoot(viewController, new NativeCommandListener(commandId, promise, eventEmitter, now));
66
             navigator().setRoot(viewController, new NativeCommandListener(commandId, promise, eventEmitter, now));
66
         });
67
         });

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/utils/NativeCommandListener.java View File

21
     @Override
21
     @Override
22
     public void onSuccess(String childId) {
22
     public void onSuccess(String childId) {
23
         if (promise != null) promise.resolve(childId);
23
         if (promise != null) promise.resolve(childId);
24
-        eventEmitter.emitCommandCompletedEvent(commandId, now.now());
24
+        eventEmitter.emitCommandCompleted(commandId, now.now());
25
     }
25
     }
26
 
26
 
27
     @Override
27
     @Override

+ 5
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java View File

12
 import com.reactnativenavigation.parse.Options;
12
 import com.reactnativenavigation.parse.Options;
13
 import com.reactnativenavigation.presentation.OptionsPresenter;
13
 import com.reactnativenavigation.presentation.OptionsPresenter;
14
 import com.reactnativenavigation.presentation.OverlayManager;
14
 import com.reactnativenavigation.presentation.OverlayManager;
15
+import com.reactnativenavigation.react.EventEmitter;
15
 import com.reactnativenavigation.utils.CommandListener;
16
 import com.reactnativenavigation.utils.CommandListener;
16
 import com.reactnativenavigation.utils.CommandListenerAdapter;
17
 import com.reactnativenavigation.utils.CommandListenerAdapter;
17
 import com.reactnativenavigation.utils.CompatUtils;
18
 import com.reactnativenavigation.utils.CompatUtils;
214
                          fromId +
215
                          fromId +
215
                          " was not found.");
216
                          " was not found.");
216
     }
217
     }
218
+
219
+    public void setEventEmitter(EventEmitter eventEmitter) {
220
+        modalStack.setEventEmitter(eventEmitter);
221
+    }
217
 }
222
 }

+ 7
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenter.java View File

8
 import com.reactnativenavigation.anim.ModalAnimator;
8
 import com.reactnativenavigation.anim.ModalAnimator;
9
 import com.reactnativenavigation.parse.ModalPresentationStyle;
9
 import com.reactnativenavigation.parse.ModalPresentationStyle;
10
 import com.reactnativenavigation.parse.Options;
10
 import com.reactnativenavigation.parse.Options;
11
+import com.reactnativenavigation.react.EventEmitter;
11
 import com.reactnativenavigation.utils.CommandListener;
12
 import com.reactnativenavigation.utils.CommandListener;
12
 import com.reactnativenavigation.viewcontrollers.ViewController;
13
 import com.reactnativenavigation.viewcontrollers.ViewController;
13
 
14
 
16
     private ViewGroup content;
17
     private ViewGroup content;
17
     private ModalAnimator animator;
18
     private ModalAnimator animator;
18
     private Options defaultOptions = new Options();
19
     private Options defaultOptions = new Options();
20
+    private EventEmitter eventEmitter;
19
 
21
 
20
     ModalPresenter(ModalAnimator animator) {
22
     ModalPresenter(ModalAnimator animator) {
21
         this.animator = animator;
23
         this.animator = animator;
84
 
86
 
85
     private void onDismissEnd(ViewController toDismiss, CommandListener listener) {
87
     private void onDismissEnd(ViewController toDismiss, CommandListener listener) {
86
         toDismiss.destroy();
88
         toDismiss.destroy();
89
+        eventEmitter.emitModalDismissed(toDismiss.getId());
87
         listener.onSuccess(toDismiss.getId());
90
         listener.onSuccess(toDismiss.getId());
88
     }
91
     }
92
+
93
+    public void setEventEmitter(EventEmitter eventEmitter) {
94
+        this.eventEmitter = eventEmitter;
95
+    }
89
 }
96
 }

+ 5
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/ModalStack.java View File

6
 
6
 
7
 import com.reactnativenavigation.anim.ModalAnimator;
7
 import com.reactnativenavigation.anim.ModalAnimator;
8
 import com.reactnativenavigation.parse.Options;
8
 import com.reactnativenavigation.parse.Options;
9
+import com.reactnativenavigation.react.EventEmitter;
9
 import com.reactnativenavigation.utils.CommandListener;
10
 import com.reactnativenavigation.utils.CommandListener;
10
 import com.reactnativenavigation.viewcontrollers.ViewController;
11
 import com.reactnativenavigation.viewcontrollers.ViewController;
11
 
12
 
125
         }
126
         }
126
         return null;
127
         return null;
127
     }
128
     }
129
+
130
+    public void setEventEmitter(EventEmitter eventEmitter) {
131
+        presenter.setEventEmitter(eventEmitter);
132
+    }
128
 }
133
 }

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/utils/NativeCommandListenerTest.java View File

39
     @Test
39
     @Test
40
     public void onSuccess_emitsNavigationEvent() {
40
     public void onSuccess_emitsNavigationEvent() {
41
         uut.onSuccess(CHILD_ID);
41
         uut.onSuccess(CHILD_ID);
42
-        verify(eventEmitter, times(1)).emitCommandCompletedEvent(COMMAND_ID, NOW);
42
+        verify(eventEmitter, times(1)).emitCommandCompleted(COMMAND_ID, NOW);
43
     }
43
     }
44
 
44
 
45
     @Test
45
     @Test

+ 1
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

67
         activityController = newActivityController(TestActivity.class);
67
         activityController = newActivityController(TestActivity.class);
68
         activity = activityController.create().get();
68
         activity = activityController.create().get();
69
         modalStack = spy(new ModalStack(activity));
69
         modalStack = spy(new ModalStack(activity));
70
+        modalStack.setEventEmitter(Mockito.mock(EventEmitter.class));
70
         uut = new Navigator(activity, childRegistry, modalStack, overlayManager);
71
         uut = new Navigator(activity, childRegistry, modalStack, overlayManager);
71
         activity.setNavigator(uut);
72
         activity.setNavigator(uut);
72
 
73
 

+ 3
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenterTest.java View File

10
 import com.reactnativenavigation.parse.ModalPresentationStyle;
10
 import com.reactnativenavigation.parse.ModalPresentationStyle;
11
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.Options;
12
 import com.reactnativenavigation.parse.params.Bool;
12
 import com.reactnativenavigation.parse.params.Bool;
13
+import com.reactnativenavigation.react.EventEmitter;
13
 import com.reactnativenavigation.utils.CommandListener;
14
 import com.reactnativenavigation.utils.CommandListener;
14
 import com.reactnativenavigation.utils.CommandListenerAdapter;
15
 import com.reactnativenavigation.utils.CommandListenerAdapter;
15
 import com.reactnativenavigation.viewcontrollers.ChildController;
16
 import com.reactnativenavigation.viewcontrollers.ChildController;
19
 import org.json.JSONException;
20
 import org.json.JSONException;
20
 import org.json.JSONObject;
21
 import org.json.JSONObject;
21
 import org.junit.Test;
22
 import org.junit.Test;
23
+import org.mockito.Mockito;
22
 
24
 
23
 import static org.assertj.core.api.Java6Assertions.assertThat;
25
 import static org.assertj.core.api.Java6Assertions.assertThat;
24
 import static org.mockito.ArgumentMatchers.any;
26
 import static org.mockito.ArgumentMatchers.any;
54
         uut.setContentLayout(contentLayout);
56
         uut.setContentLayout(contentLayout);
55
         modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
57
         modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
56
         modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
58
         modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
59
+        uut.setEventEmitter(Mockito.mock(EventEmitter.class));
57
     }
60
     }
58
 
61
 
59
     @Test
62
     @Test

+ 3
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest.java View File

8
 import com.reactnativenavigation.anim.ModalAnimator;
8
 import com.reactnativenavigation.anim.ModalAnimator;
9
 import com.reactnativenavigation.mocks.SimpleViewController;
9
 import com.reactnativenavigation.mocks.SimpleViewController;
10
 import com.reactnativenavigation.parse.Options;
10
 import com.reactnativenavigation.parse.Options;
11
+import com.reactnativenavigation.react.EventEmitter;
11
 import com.reactnativenavigation.utils.CommandListener;
12
 import com.reactnativenavigation.utils.CommandListener;
12
 import com.reactnativenavigation.utils.CommandListenerAdapter;
13
 import com.reactnativenavigation.utils.CommandListenerAdapter;
13
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
14
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
14
 import com.reactnativenavigation.viewcontrollers.ViewController;
15
 import com.reactnativenavigation.viewcontrollers.ViewController;
15
 
16
 
16
 import org.junit.Test;
17
 import org.junit.Test;
18
+import org.mockito.Mockito;
17
 
19
 
18
 import java.util.EmptyStackException;
20
 import java.util.EmptyStackException;
19
 
21
 
56
         presenter = spy(new ModalPresenter(animator));
58
         presenter = spy(new ModalPresenter(animator));
57
         uut = new ModalStack(presenter);
59
         uut = new ModalStack(presenter);
58
         uut.setContentLayout(activityContentView);
60
         uut.setContentLayout(activityContentView);
61
+        uut.setEventEmitter(Mockito.mock(EventEmitter.class));
59
         modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
62
         modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
60
         modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
63
         modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
61
         modal3 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_3, new Options()));
64
         modal3 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_3, new Options()));

+ 6
- 1
lib/src/adapters/NativeEventsReceiver.ts View File

5
   ComponentDidDisappearEvent,
5
   ComponentDidDisappearEvent,
6
   NavigationButtonPressedEvent,
6
   NavigationButtonPressedEvent,
7
   SearchBarUpdatedEvent,
7
   SearchBarUpdatedEvent,
8
-  SearchBarCancelPressedEvent
8
+  SearchBarCancelPressedEvent,
9
+  ModalDismissedEvent
9
 } from '../interfaces/ComponentEvents';
10
 } from '../interfaces/ComponentEvents';
10
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
11
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
11
 
12
 
41
     return this.emitter.addListener('RNN.NavigationButtonPressed', callback);
42
     return this.emitter.addListener('RNN.NavigationButtonPressed', callback);
42
   }
43
   }
43
 
44
 
45
+  public registerModalDismissedListener(callback: (event: ModalDismissedEvent) => void): EventSubscription {
46
+    return this.emitter.addListener('RNN.ModalDismissed', callback);
47
+  }
48
+
44
   public registerSearchBarUpdatedListener(callback: (event: SearchBarUpdatedEvent) => void): EventSubscription {
49
   public registerSearchBarUpdatedListener(callback: (event: SearchBarUpdatedEvent) => void): EventSubscription {
45
     return this.emitter.addListener('RNN.SearchBarUpdated', callback);
50
     return this.emitter.addListener('RNN.SearchBarUpdated', callback);
46
   }
51
   }

+ 9
- 0
lib/src/events/ComponentEventsObserver.test.tsx View File

13
   const navigationButtonPressedFn = jest.fn();
13
   const navigationButtonPressedFn = jest.fn();
14
   const searchBarUpdatedFn = jest.fn();
14
   const searchBarUpdatedFn = jest.fn();
15
   const searchBarCancelPressedFn = jest.fn();
15
   const searchBarCancelPressedFn = jest.fn();
16
+  const modalDismissedFn = jest.fn();
16
   let subscription;
17
   let subscription;
17
 
18
 
18
   class SimpleScreen extends React.Component<any, any> {
19
   class SimpleScreen extends React.Component<any, any> {
47
       navigationButtonPressedFn(event);
48
       navigationButtonPressedFn(event);
48
     }
49
     }
49
 
50
 
51
+    modalDismissed(event) {
52
+      modalDismissedFn(event);
53
+    }
54
+
50
     searchBarUpdated(event) {
55
     searchBarUpdated(event) {
51
       searchBarUpdatedFn(event);
56
       searchBarUpdatedFn(event);
52
     }
57
     }
85
     expect(navigationButtonPressedFn).toHaveBeenCalledTimes(1);
90
     expect(navigationButtonPressedFn).toHaveBeenCalledTimes(1);
86
     expect(navigationButtonPressedFn).toHaveBeenCalledWith({ buttonId: 'myButtonId', componentId: 'myCompId' });
91
     expect(navigationButtonPressedFn).toHaveBeenCalledWith({ buttonId: 'myButtonId', componentId: 'myCompId' });
87
 
92
 
93
+    uut.notifyModalDismissed({ componentId: 'myCompId' });
94
+    expect(modalDismissedFn).toHaveBeenCalledTimes(1);
95
+    expect(modalDismissedFn).toHaveBeenLastCalledWith({ componentId: 'myCompId' })
96
+
88
     uut.notifySearchBarUpdated({ componentId: 'myCompId', text: 'theText', isFocused: true });
97
     uut.notifySearchBarUpdated({ componentId: 'myCompId', text: 'theText', isFocused: true });
89
     expect(searchBarUpdatedFn).toHaveBeenCalledTimes(1);
98
     expect(searchBarUpdatedFn).toHaveBeenCalledTimes(1);
90
     expect(searchBarUpdatedFn).toHaveBeenCalledWith({ componentId: 'myCompId', text: 'theText', isFocused: true });
99
     expect(searchBarUpdatedFn).toHaveBeenCalledWith({ componentId: 'myCompId', text: 'theText', isFocused: true });

+ 8
- 1
lib/src/events/ComponentEventsObserver.ts View File

6
   NavigationButtonPressedEvent,
6
   NavigationButtonPressedEvent,
7
   SearchBarUpdatedEvent,
7
   SearchBarUpdatedEvent,
8
   SearchBarCancelPressedEvent,
8
   SearchBarCancelPressedEvent,
9
-  ComponentEvent
9
+  ComponentEvent,
10
+  ModalDismissedEvent
10
 } from '../interfaces/ComponentEvents';
11
 } from '../interfaces/ComponentEvents';
11
 import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
12
 import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
12
 
13
 
18
     this.notifyComponentDidAppear = this.notifyComponentDidAppear.bind(this);
19
     this.notifyComponentDidAppear = this.notifyComponentDidAppear.bind(this);
19
     this.notifyComponentDidDisappear = this.notifyComponentDidDisappear.bind(this);
20
     this.notifyComponentDidDisappear = this.notifyComponentDidDisappear.bind(this);
20
     this.notifyNavigationButtonPressed = this.notifyNavigationButtonPressed.bind(this);
21
     this.notifyNavigationButtonPressed = this.notifyNavigationButtonPressed.bind(this);
22
+    this.notifyModalDismissed = this.notifyModalDismissed.bind(this);
21
     this.notifySearchBarUpdated = this.notifySearchBarUpdated.bind(this);
23
     this.notifySearchBarUpdated = this.notifySearchBarUpdated.bind(this);
22
     this.notifySearchBarCancelPressed = this.notifySearchBarCancelPressed.bind(this);
24
     this.notifySearchBarCancelPressed = this.notifySearchBarCancelPressed.bind(this);
23
   }
25
   }
28
     this.nativeEventsReceiver.registerComponentDidAppearListener(this.notifyComponentDidAppear);
30
     this.nativeEventsReceiver.registerComponentDidAppearListener(this.notifyComponentDidAppear);
29
     this.nativeEventsReceiver.registerComponentDidDisappearListener(this.notifyComponentDidDisappear);
31
     this.nativeEventsReceiver.registerComponentDidDisappearListener(this.notifyComponentDidDisappear);
30
     this.nativeEventsReceiver.registerNavigationButtonPressedListener(this.notifyNavigationButtonPressed);
32
     this.nativeEventsReceiver.registerNavigationButtonPressedListener(this.notifyNavigationButtonPressed);
33
+    this.nativeEventsReceiver.registerModalDismissedListener(this.notifyModalDismissed);
31
     this.nativeEventsReceiver.registerSearchBarUpdatedListener(this.notifySearchBarUpdated);
34
     this.nativeEventsReceiver.registerSearchBarUpdatedListener(this.notifySearchBarUpdated);
32
     this.nativeEventsReceiver.registerSearchBarCancelPressedListener(this.notifySearchBarCancelPressed);
35
     this.nativeEventsReceiver.registerSearchBarCancelPressedListener(this.notifySearchBarCancelPressed);
33
   }
36
   }
62
     this.triggerOnAllListenersByComponentId(event, 'navigationButtonPressed');
65
     this.triggerOnAllListenersByComponentId(event, 'navigationButtonPressed');
63
   }
66
   }
64
 
67
 
68
+  notifyModalDismissed(event: ModalDismissedEvent) {
69
+    this.triggerOnAllListenersByComponentId(event, 'modalDismissed');
70
+  }
71
+
65
   notifySearchBarUpdated(event: SearchBarUpdatedEvent) {
72
   notifySearchBarUpdated(event: SearchBarUpdatedEvent) {
66
     this.triggerOnAllListenersByComponentId(event, 'searchBarUpdated');
73
     this.triggerOnAllListenersByComponentId(event, 'searchBarUpdated');
67
   }
74
   }

+ 7
- 0
lib/src/events/EventsRegistry.test.tsx View File

60
     expect(mockNativeEventsReceiver.registerNavigationButtonPressedListener).toHaveBeenCalledWith(cb);
60
     expect(mockNativeEventsReceiver.registerNavigationButtonPressedListener).toHaveBeenCalledWith(cb);
61
   });
61
   });
62
 
62
 
63
+  it('delegates modalDismissed to nativeEventsReceiver', () => {
64
+    const cb = jest.fn();
65
+    uut.registerModalDismissedListener(cb);
66
+    expect(mockNativeEventsReceiver.registerModalDismissedListener).toHaveBeenCalledTimes(1);
67
+    expect(mockNativeEventsReceiver.registerModalDismissedListener).toHaveBeenCalledWith(cb);
68
+  });
69
+
63
   it('delegates searchBarUpdated to nativeEventsReceiver', () => {
70
   it('delegates searchBarUpdated to nativeEventsReceiver', () => {
64
     const cb = jest.fn();
71
     const cb = jest.fn();
65
     uut.registerSearchBarUpdatedListener(cb);
72
     uut.registerSearchBarUpdatedListener(cb);

+ 6
- 1
lib/src/events/EventsRegistry.ts View File

7
   ComponentDidDisappearEvent,
7
   ComponentDidDisappearEvent,
8
   NavigationButtonPressedEvent,
8
   NavigationButtonPressedEvent,
9
   SearchBarUpdatedEvent,
9
   SearchBarUpdatedEvent,
10
-  SearchBarCancelPressedEvent
10
+  SearchBarCancelPressedEvent,
11
+  ModalDismissedEvent
11
 } from '../interfaces/ComponentEvents';
12
 } from '../interfaces/ComponentEvents';
12
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
13
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
13
 
14
 
38
     return this.nativeEventsReceiver.registerNavigationButtonPressedListener(callback);
39
     return this.nativeEventsReceiver.registerNavigationButtonPressedListener(callback);
39
   }
40
   }
40
 
41
 
42
+  public registerModalDismissedListener(callback: (event: ModalDismissedEvent) => void): EventSubscription {
43
+    return this.nativeEventsReceiver.registerModalDismissedListener(callback);
44
+  }
45
+
41
   public registerSearchBarUpdatedListener(callback: (event: SearchBarUpdatedEvent) => void): EventSubscription {
46
   public registerSearchBarUpdatedListener(callback: (event: SearchBarUpdatedEvent) => void): EventSubscription {
42
     return this.nativeEventsReceiver.registerSearchBarUpdatedListener(callback);
47
     return this.nativeEventsReceiver.registerSearchBarUpdatedListener(callback);
43
   }
48
   }

+ 4
- 0
lib/src/interfaces/ComponentEvents.ts View File

14
   buttonId: string;
14
   buttonId: string;
15
 }
15
 }
16
 
16
 
17
+export interface ModalDismissedEvent extends ComponentEvent {
18
+  componentId: string;
19
+}
20
+
17
 export interface SearchBarUpdatedEvent extends ComponentEvent {
21
 export interface SearchBarUpdatedEvent extends ComponentEvent {
18
   text: string;
22
   text: string;
19
   isFocused: boolean;
23
   isFocused: boolean;

+ 8
- 1
playground/src/screens/StaticLifecycleOverlay.js View File

34
         events: [...this.state.events, { event: 'navigationButtonPressed', buttonId, componentId }]
34
         events: [...this.state.events, { event: 'navigationButtonPressed', buttonId, componentId }]
35
       });
35
       });
36
     }));
36
     }));
37
+    this.listeners.push(Navigation.events().registerModalDismissedListener(({ componentId }) => {
38
+      this.setState({
39
+        events: [...this.state.events, { event: 'modalDismissed', componentId }]
40
+      });
41
+    }));
37
   }
42
   }
38
 
43
 
39
   componentWillUnmount() {
44
   componentWillUnmount() {
47
       return <Text style={styles.h2}>{`${event.commandId}`}</Text>;
52
       return <Text style={styles.h2}>{`${event.commandId}`}</Text>;
48
     } else if (event.componentName) {
53
     } else if (event.componentName) {
49
       return <Text style={styles.h2}>{`${event.event} | ${event.componentName}`}</Text>;
54
       return <Text style={styles.h2}>{`${event.event} | ${event.componentName}`}</Text>;
50
-    } else {
55
+    } else if (event.buttonId) {
51
       return <Text style={styles.h2}>{`${event.event} | ${event.buttonId}`}</Text>;
56
       return <Text style={styles.h2}>{`${event.event} | ${event.buttonId}`}</Text>;
57
+    } else {
58
+      return <Text style={styles.h2}>{`${event.event} | ${event.componentId}`}</Text>;
52
     }
59
     }
53
   }
60
   }
54
 
61