Browse Source

Add dismissSnackbar method (#763)

Guy Carmeli 7 years ago
parent
commit
5b63d590c2

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java View File

204
         NavigationCommandsHandler.showSnackbar(snackbarParams);
204
         NavigationCommandsHandler.showSnackbar(snackbarParams);
205
     }
205
     }
206
 
206
 
207
+    @ReactMethod
208
+    public void dismissSnackbar() {
209
+        NavigationCommandsHandler.dismissSnackbar();
210
+    }
211
+
207
     @ReactMethod
212
     @ReactMethod
208
     public void showContextualMenu(final String screenInstanceId, final ReadableMap params, final Callback onButtonClicked) {
213
     public void showContextualMenu(final String screenInstanceId, final ReadableMap params, final Callback onButtonClicked) {
209
         ContextualMenuParams contextualMenuParams =
214
         ContextualMenuParams contextualMenuParams =

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

311
         layout.showSnackbar(params);
311
         layout.showSnackbar(params);
312
     }
312
     }
313
 
313
 
314
+    public void dismissSnackbar() {
315
+        layout.dismissSnackbar();
316
+    }
317
+
314
     public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
318
     public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
315
         layout.showContextualMenu(screenInstanceId, params, onButtonClicked);
319
         layout.showContextualMenu(screenInstanceId, params, onButtonClicked);
316
         modalController.showContextualMenu(screenInstanceId, params, onButtonClicked);
320
         modalController.showContextualMenu(screenInstanceId, params, onButtonClicked);

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java View File

406
             }
406
             }
407
         });
407
         });
408
     }
408
     }
409
+
410
+    public static void dismissSnackbar() {
411
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
412
+        if (currentActivity == null) {
413
+            return;
414
+        }
415
+
416
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
417
+            @Override
418
+            public void run() {
419
+                currentActivity.dismissSnackbar();
420
+            }
421
+        });
422
+    }
409
 }
423
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

211
         snackbarAndFabContainer.showSnackbar(eventId, params);
211
         snackbarAndFabContainer.showSnackbar(eventId, params);
212
     }
212
     }
213
 
213
 
214
+    @Override
215
+    public void dismissSnackbar() {
216
+        snackbarAndFabContainer.dismissSnackbar();
217
+    }
218
+
214
     @Override
219
     @Override
215
     public void showSlidingOverlay(final SlidingOverlayParams params) {
220
     public void showSlidingOverlay(final SlidingOverlayParams params) {
216
         slidingOverlaysQueue.add(new SlidingOverlay(this, params));
221
         slidingOverlaysQueue.add(new SlidingOverlay(this, params));

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java View File

50
     void dismissContextualMenu(String screenInstanceId);
50
     void dismissContextualMenu(String screenInstanceId);
51
 
51
 
52
     Screen getCurrentScreen();
52
     Screen getCurrentScreen();
53
+
54
+    void dismissSnackbar();
53
 }
55
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java View File

215
         snackbarAndFabContainer.showSnackbar(navigatorEventId, params);
215
         snackbarAndFabContainer.showSnackbar(navigatorEventId, params);
216
     }
216
     }
217
 
217
 
218
+    @Override
219
+    public void dismissSnackbar() {
220
+        snackbarAndFabContainer.dismissSnackbar();
221
+    }
222
+
218
     @Override
223
     @Override
219
     public void showSlidingOverlay(final SlidingOverlayParams params) {
224
     public void showSlidingOverlay(final SlidingOverlayParams params) {
220
         slidingOverlaysQueue.add(new SlidingOverlay(this, params));
225
         slidingOverlaysQueue.add(new SlidingOverlay(this, params));

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

55
         updateFab(fabParams);
55
         updateFab(fabParams);
56
     }
56
     }
57
 
57
 
58
-    private void dismissSnackbar() {
58
+    public void dismissSnackbar() {
59
         if (snakbar != null) {
59
         if (snakbar != null) {
60
             snakbar.dismiss();
60
             snakbar.dismiss();
61
             snakbar = null;
61
             snakbar = null;

+ 4
- 0
src/Screen.js View File

108
     return platformSpecific.showSnackbar(this, params);
108
     return platformSpecific.showSnackbar(this, params);
109
   }
109
   }
110
 
110
 
111
+  dismissSnackbar() {
112
+    return platformSpecific.dismissSnackbar();
113
+  }
114
+
111
   showContextualMenu(params, onButtonPressed) {
115
   showContextualMenu(params, onButtonPressed) {
112
     return platformSpecific.showContextualMenu(this, params, onButtonPressed);
116
     return platformSpecific.showContextualMenu(this, params, onButtonPressed);
113
   }
117
   }

+ 5
- 0
src/deprecated/platformSpecificDeprecated.android.js View File

562
   return newPlatformSpecific.showSnackbar(adapted);
562
   return newPlatformSpecific.showSnackbar(adapted);
563
 }
563
 }
564
 
564
 
565
+function dismissSnackbar() {
566
+  return newPlatformSpecific.dismissSnackbar();
567
+}
568
+
565
 function showContextualMenu(navigator, params) {
569
 function showContextualMenu(navigator, params) {
566
   const contextualMenu = {
570
   const contextualMenu = {
567
     buttons: [],
571
     buttons: [],
611
   navigatorToggleTabs,
615
   navigatorToggleTabs,
612
   navigatorToggleNavBar,
616
   navigatorToggleNavBar,
613
   showSnackbar,
617
   showSnackbar,
618
+  dismissSnackbar,
614
   showContextualMenu,
619
   showContextualMenu,
615
   dismissContextualMenu
620
   dismissContextualMenu
616
 };
621
 };

+ 5
- 0
src/platformSpecific.android.js View File

132
   NativeReactModule.showSnackbar(params);
132
   NativeReactModule.showSnackbar(params);
133
 }
133
 }
134
 
134
 
135
+function dismissSnackbar() {
136
+  NativeReactModule.dismissSnackbar();
137
+}
138
+
135
 function showContextualMenu(screenInstanceID, params, onButtonPressed) {
139
 function showContextualMenu(screenInstanceID, params, onButtonPressed) {
136
   NativeReactModule.showContextualMenu(screenInstanceID, params, onButtonPressed);
140
   NativeReactModule.showContextualMenu(screenInstanceID, params, onButtonPressed);
137
 }
141
 }
163
   setBottomTabBadgeByNavigatorId,
167
   setBottomTabBadgeByNavigatorId,
164
   setBottomTabBadgeByIndex,
168
   setBottomTabBadgeByIndex,
165
   showSnackbar,
169
   showSnackbar,
170
+  dismissSnackbar,
166
   showContextualMenu,
171
   showContextualMenu,
167
   dismissContextualMenu
172
   dismissContextualMenu
168
 };
173
 };