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

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

5
     public StyleParams.Color textColor;
5
     public StyleParams.Color textColor;
6
     public String buttonText;
6
     public String buttonText;
7
     public StyleParams.Color buttonColor;
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
 package com.reactnativenavigation.params.parsers;
1
 package com.reactnativenavigation.params.parsers;
2
 
2
 
3
 import android.os.Bundle;
3
 import android.os.Bundle;
4
+import android.support.design.widget.Snackbar;
4
 
5
 
5
 import com.reactnativenavigation.params.AppStyle;
6
 import com.reactnativenavigation.params.AppStyle;
6
 import com.reactnativenavigation.params.SnackbarParams;
7
 import com.reactnativenavigation.params.SnackbarParams;
7
-import com.reactnativenavigation.params.StyleParams;
8
 
8
 
9
 public class SnackbarParamsParser extends Parser {
9
 public class SnackbarParamsParser extends Parser {
10
     public SnackbarParams parse(Bundle params) {
10
     public SnackbarParams parse(Bundle params) {
13
         result.textColor = getColor(params, "textColor", AppStyle.appStyle.snackbarTextColor);
13
         result.textColor = getColor(params, "textColor", AppStyle.appStyle.snackbarTextColor);
14
         result.buttonText = params.getString("buttonText");
14
         result.buttonText = params.getString("buttonText");
15
         result.buttonColor = getColor(params, "buttonColor", AppStyle.appStyle.snackbarButtonColor);
15
         result.buttonColor = getColor(params, "buttonColor", AppStyle.appStyle.snackbarButtonColor);
16
+        result.duration = getDuration(params.getString("duration", "short"));
16
         return result;
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
 package com.reactnativenavigation.views;
1
 package com.reactnativenavigation.views;
2
 
2
 
3
 import android.content.Context;
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
     public SnackbarContainer(Context context) {
11
     public SnackbarContainer(Context context) {
9
         super(context);
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
 }
419
 }
420
 
420
 
421
 function showSnackbar(navigator, params) {
421
 function showSnackbar(navigator, params) {
422
-  return newPlatformSpecific.showSnackbar(params.text);
422
+  return newPlatformSpecific.showSnackbar(params);
423
 }
423
 }
424
 
424
 
425
 export default {
425
 export default {

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

108
   NativeReactModule.setBottomTabBadgeByNavigatorId(navigatorId, badge);
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
 module.exports = {
115
 module.exports = {