Browse Source

Snacker works on BottomTabsLayout

Guy Carmeli 8 years ago
parent
commit
df30086c6c

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

@@ -103,6 +103,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
103 103
         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT);
104 104
         lp.addRule(ABOVE, bottomTabs.getId());
105 105
         snackbarContainer.setLayoutParams(lp);
106
+        getScreenStackParent().addView(snackbarContainer);
106 107
     }
107 108
 
108 109
     private void showInitialScreenStack() {
@@ -177,7 +178,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
177 178
 
178 179
     @Override
179 180
     public void showSnackbar(SnackbarParams params) {
180
-        // TODO: implement me
181
+        snackbarContainer.addSnackbar(params);
181 182
     }
182 183
 
183 184
     public void selectBottomTabByTabIndex(Integer index) {

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/SnackbarParams.java View File

@@ -5,4 +5,5 @@ public class SnackbarParams {
5 5
     public StyleParams.Color textColor;
6 6
     public String buttonText;
7 7
     public StyleParams.Color buttonColor;
8
+    public int duration;
8 9
 }

+ 15
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/SnackbarParamsParser.java View File

@@ -1,10 +1,10 @@
1 1
 package com.reactnativenavigation.params.parsers;
2 2
 
3 3
 import android.os.Bundle;
4
+import android.support.design.widget.Snackbar;
4 5
 
5 6
 import com.reactnativenavigation.params.AppStyle;
6 7
 import com.reactnativenavigation.params.SnackbarParams;
7
-import com.reactnativenavigation.params.StyleParams;
8 8
 
9 9
 public class SnackbarParamsParser extends Parser {
10 10
     public SnackbarParams parse(Bundle params) {
@@ -13,6 +13,20 @@ public class SnackbarParamsParser extends Parser {
13 13
         result.textColor = getColor(params, "textColor", AppStyle.appStyle.snackbarTextColor);
14 14
         result.buttonText = params.getString("buttonText");
15 15
         result.buttonColor = getColor(params, "buttonColor", AppStyle.appStyle.snackbarButtonColor);
16
+        result.duration = getDuration(params.getString("duration", "short"));
16 17
         return result;
17 18
     }
19
+
20
+    private int getDuration(String duration) {
21
+        switch (duration) {
22
+            case "short":
23
+                return Snackbar.LENGTH_SHORT;
24
+            case "long":
25
+                return Snackbar.LENGTH_LONG;
26
+            case "indefinite":
27
+                return Snackbar.LENGTH_INDEFINITE;
28
+            default:
29
+                return Snackbar.LENGTH_SHORT;
30
+        }
31
+    }
18 32
 }

+ 10
- 3
android/app/src/main/java/com/reactnativenavigation/views/SnackbarContainer.java View File

@@ -1,12 +1,19 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4
-import android.widget.LinearLayout;
4
+import android.support.design.widget.CoordinatorLayout;
5
+import android.support.design.widget.Snackbar;
5 6
 
6
-public class SnackbarContainer extends LinearLayout {
7
+import com.reactnativenavigation.params.SnackbarParams;
8
+
9
+public class SnackbarContainer extends CoordinatorLayout {
7 10
 
8 11
     public SnackbarContainer(Context context) {
9 12
         super(context);
10
-        setOrientation(LinearLayout.VERTICAL);
13
+    }
14
+
15
+    public void addSnackbar(SnackbarParams params) {
16
+        Snackbar snackbar = Snackbar.make(this, params.text, params.duration);
17
+        snackbar.show();
11 18
     }
12 19
 }

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

@@ -419,7 +419,7 @@ function addNavigationStyleParams(screen) {
419 419
 }
420 420
 
421 421
 function showSnackbar(navigator, params) {
422
-  return newPlatformSpecific.showSnackbar(params.text);
422
+  return newPlatformSpecific.showSnackbar(params);
423 423
 }
424 424
 
425 425
 export default {

+ 2
- 2
src/platformSpecific.android.js View File

@@ -108,8 +108,8 @@ function setBottomTabBadgeByNavigatorId(navigatorId, badge) {
108 108
   NativeReactModule.setBottomTabBadgeByNavigatorId(navigatorId, badge);
109 109
 }
110 110
 
111
-function showSnackbar(text) {
112
-  NativeReactModule.showSnackbar(text);
111
+function showSnackbar(params) {
112
+  NativeReactModule.showSnackbar(params);
113 113
 }
114 114
 
115 115
 module.exports = {