Bläddra i källkod

Add dismissSnackbar method (#763)

Guy Carmeli 7 år sedan
förälder
incheckning
5b63d590c2

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java Visa fil

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

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Visa fil

@@ -311,6 +311,10 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
311 311
         layout.showSnackbar(params);
312 312
     }
313 313
 
314
+    public void dismissSnackbar() {
315
+        layout.dismissSnackbar();
316
+    }
317
+
314 318
     public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
315 319
         layout.showContextualMenu(screenInstanceId, params, onButtonClicked);
316 320
         modalController.showContextualMenu(screenInstanceId, params, onButtonClicked);

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java Visa fil

@@ -406,4 +406,18 @@ public class NavigationCommandsHandler {
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 Visa fil

@@ -211,6 +211,11 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
211 211
         snackbarAndFabContainer.showSnackbar(eventId, params);
212 212
     }
213 213
 
214
+    @Override
215
+    public void dismissSnackbar() {
216
+        snackbarAndFabContainer.dismissSnackbar();
217
+    }
218
+
214 219
     @Override
215 220
     public void showSlidingOverlay(final SlidingOverlayParams params) {
216 221
         slidingOverlaysQueue.add(new SlidingOverlay(this, params));

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java Visa fil

@@ -50,4 +50,6 @@ public interface Layout extends ScreenStackContainer {
50 50
     void dismissContextualMenu(String screenInstanceId);
51 51
 
52 52
     Screen getCurrentScreen();
53
+
54
+    void dismissSnackbar();
53 55
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java Visa fil

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

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/views/SnackbarAndFabContainer.java Visa fil

@@ -55,7 +55,7 @@ public class SnackbarAndFabContainer extends CoordinatorLayout implements Snakba
55 55
         updateFab(fabParams);
56 56
     }
57 57
 
58
-    private void dismissSnackbar() {
58
+    public void dismissSnackbar() {
59 59
         if (snakbar != null) {
60 60
             snakbar.dismiss();
61 61
             snakbar = null;

+ 4
- 0
src/Screen.js Visa fil

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

+ 5
- 0
src/deprecated/platformSpecificDeprecated.android.js Visa fil

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

+ 5
- 0
src/platformSpecific.android.js Visa fil

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