Browse Source

Snackback can be displayed statically from Navigation (#859)

When snackbar cta is clicked - event is dispatched with the specified eventId
Guy Carmeli 7 years ago
parent
commit
018c12dd2c

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/EventEmitter.java View File

@@ -1,5 +1,6 @@
1 1
 package com.reactnativenavigation.bridge;
2 2
 
3
+import com.facebook.react.bridge.Arguments;
3 4
 import com.facebook.react.bridge.WritableMap;
4 5
 import com.reactnativenavigation.NavigationApplication;
5 6
 import com.reactnativenavigation.react.ReactGateway;
@@ -38,4 +39,11 @@ public class EventEmitter {
38 39
         }
39 40
         reactGateway.getReactEventEmitter().sendEvent(eventId, arguments);
40 41
     }
42
+
43
+    public void sendEvent(String eventId) {
44
+        if (!NavigationApplication.instance.isReactContextInitialized()) {
45
+            return;
46
+        }
47
+        reactGateway.getReactEventEmitter().sendEvent(eventId, Arguments.createMap());
48
+    }
41 49
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/views/Snakbar.java View File

@@ -58,6 +58,7 @@ class Snakbar {
58 58
             snackbar.setAction(params.buttonText, new View.OnClickListener() {
59 59
                 @Override
60 60
                 public void onClick(View v) {
61
+                    NavigationApplication.instance.getEventEmitter().sendEvent(params.eventId);
61 62
                     NavigationApplication.instance.getEventEmitter().sendNavigatorEvent(params.eventId, navigatorEventId);
62 63
                 }
63 64
             });

+ 5
- 0
src/Navigation.js View File

@@ -111,6 +111,10 @@ function dismissAllModals(params = {}) {
111 111
   return platformSpecific.dismissAllModals(params);
112 112
 }
113 113
 
114
+function showSnackbar(params = {}) {
115
+  return platformSpecific.showSnackbar(params);
116
+}
117
+
114 118
 function showLightBox(params = {}) {
115 119
   return platformSpecific.showLightBox(params);
116 120
 }
@@ -160,6 +164,7 @@ export default {
160 164
   showModal: showModal,
161 165
   dismissModal: dismissModal,
162 166
   dismissAllModals: dismissAllModals,
167
+  showSnackbar: showSnackbar,
163 168
   showLightBox: showLightBox,
164 169
   dismissLightBox: dismissLightBox,
165 170
   showInAppNotification: showInAppNotification,

+ 1
- 1
src/deprecated/platformSpecificDeprecated.android.js View File

@@ -567,7 +567,7 @@ function addNavigationStyleParams(screen) {
567 567
   screen.navigatorStyle = Object.assign({}, Screen.navigatorStyle, screen.navigatorStyle);
568 568
 }
569 569
 
570
-function showSnackbar(navigator, params) {
570
+function showSnackbar(params) {
571 571
   const adapted = _.cloneDeep(params);
572 572
   if (adapted.backgroundColor) {
573 573
     adapted.backgroundColor = processColor(adapted.backgroundColor);