Explorar el Código

Add TopTabs style

Guy Carmeli hace 8 años
padre
commit
76560beb48

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java Ver fichero

@@ -45,6 +45,12 @@ public class StyleParams {
45 45
     public Color titleBarButtonColor;
46 46
     public boolean backButtonHidden;
47 47
 
48
+    public Color topTabTextColor;
49
+    public Color selectedTopTabTextColor;
50
+    public Color selectedTopTabColor;
51
+    public int selectedTopTabIndicatorHeight;
52
+    public Color selectedTopTabIndicatorColor;
53
+
48 54
     public boolean bottomTabsHidden;
49 55
     public boolean bottomTabsHiddenOnScroll;
50 56
     public Color bottomTabsColor;

+ 42
- 10
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java Ver fichero

@@ -23,19 +23,25 @@ public class StyleParamsParser {
23 23
         result.statusBarColor = getColor("statusBarColor", getDefaultStatusBarColor());
24 24
 
25 25
         result.topBarColor = getColor("topBarColor", getDefaultTopBarColor());
26
-        result.titleBarHidden = getBoolean("titleBarHidden", isDefaultTopBarHidden());
26
+        result.titleBarHidden = getBoolean("titleBarHidden", getDefaultTopBarHidden());
27 27
         result.titleBarTitleColor = getColor("titleBarTitleColor", getDefaultTitleBarColor());
28 28
         result.titleBarButtonColor = getColor("titleBarButtonColor", getTitleBarButtonColor());
29
-        result.backButtonHidden = getBoolean("backButtonHidden", isDefaultBackButtonHidden());
30
-        result.topTabsHidden = getBoolean("topTabsHidden", isDefaultTopTabsHidden());
29
+        result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
30
+        result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
31
+
32
+        result.topTabTextColor = getColor("topTabTextColor", getDefaultTopTabTextColor());
33
+        result.selectedTopTabTextColor = getColor("selectedTopTabTextColor", getDefaultSelectedTopTabTextColor());
34
+        result.selectedTopTabColor = getColor("selectedTopTabColor", getDefaultSelectedTopTabColor());
35
+        result.selectedTopTabIndicatorHeight = getInt("selectedTopTabIndicatorHeight", getDefaultSelectedTopTabIndicatorHeight());
36
+        result.selectedTopTabIndicatorColor = getColor("selectedTopTabIndicatorColor", getDefaultSelectedTopTabIndicatorColor());
31 37
 
32 38
         // TODO: Uncomment once we support drawBelowTopBar again
33 39
         //result.drawScreenBelowTopBar = params.getBoolean("drawBelowTopBar", isDefaultScreenBelowTopBar());
34 40
         result.drawScreenBelowTopBar = true;
35 41
 
36
-        result.bottomTabsHidden = getBoolean("bottomTabsHidden", isDefaultBottomTabsHidden());
42
+        result.bottomTabsHidden = getBoolean("bottomTabsHidden", getDefaultBottomTabsHidden());
37 43
         result.bottomTabsHiddenOnScroll =
38
-                getBoolean("bottomTabsHiddenOnScroll", isDefaultBottomTabsHiddenOnScroll());
44
+                getBoolean("bottomTabsHiddenOnScroll", getDefaultBottomTabsHiddenOnScroll());
39 45
         result.bottomTabsColor = getColor("bottomTabsColor", getDefaultBottomTabsColor());
40 46
         result.bottomTabsButtonColor = getColor("bottomTabsButtonColor", getDefaultBottomTabsButtonColor());
41 47
         result.selectedBottomTabsButtonColor =
@@ -46,6 +52,22 @@ public class StyleParamsParser {
46 52
         return result;
47 53
     }
48 54
 
55
+    private StyleParams.Color getDefaultSelectedTopTabIndicatorColor() {
56
+        return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.selectedTopTabIndicatorColor;
57
+    }
58
+
59
+    private int getDefaultSelectedTopTabIndicatorHeight() {
60
+        return AppStyle.appStyle == null ? -1 : AppStyle.appStyle.selectedTopTabIndicatorHeight;
61
+    }
62
+
63
+    private StyleParams.Color getDefaultSelectedTopTabColor() {
64
+        return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.selectedTopTabColor;
65
+    }
66
+
67
+    private StyleParams.Color getDefaultSelectedTopTabTextColor() {
68
+        return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.selectedTopTabTextColor;
69
+    }
70
+
49 71
     @Nullable
50 72
     private StyleParams.Color getDefaultNavigationColor() {
51 73
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.navigationBarColor;
@@ -66,11 +88,11 @@ public class StyleParamsParser {
66 88
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.bottomTabsColor;
67 89
     }
68 90
 
69
-    private boolean isDefaultBottomTabsHiddenOnScroll() {
91
+    private boolean getDefaultBottomTabsHiddenOnScroll() {
70 92
         return AppStyle.appStyle != null && AppStyle.appStyle.bottomTabsHiddenOnScroll;
71 93
     }
72 94
 
73
-    private boolean isDefaultBottomTabsHidden() {
95
+    private boolean getDefaultBottomTabsHidden() {
74 96
         return AppStyle.appStyle != null && AppStyle.appStyle.bottomTabsHidden;
75 97
     }
76 98
 
@@ -78,11 +100,15 @@ public class StyleParamsParser {
78 100
         return AppStyle.appStyle == null || AppStyle.appStyle.drawScreenBelowTopBar;
79 101
     }
80 102
 
81
-    private boolean isDefaultTopTabsHidden() {
103
+    private boolean getDefaultTopTabsHidden() {
82 104
         return AppStyle.appStyle != null && AppStyle.appStyle.topTabsHidden;
83 105
     }
84 106
 
85
-    private boolean isDefaultBackButtonHidden() {
107
+    private StyleParams.Color getDefaultTopTabTextColor() {
108
+        return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.topTabTextColor;
109
+    }
110
+
111
+    private boolean getDefaultBackButtonHidden() {
86 112
         return AppStyle.appStyle != null && AppStyle.appStyle.backButtonHidden;
87 113
     }
88 114
 
@@ -96,7 +122,7 @@ public class StyleParamsParser {
96 122
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.titleBarButtonColor;
97 123
     }
98 124
 
99
-    private boolean isDefaultTopBarHidden() {
125
+    private boolean getDefaultTopBarHidden() {
100 126
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarHidden;
101 127
     }
102 128
 
@@ -123,4 +149,10 @@ public class StyleParamsParser {
123 149
             return defaultColor != null && defaultColor.hasColor() ? defaultColor : color;
124 150
         }
125 151
     }
152
+
153
+    private int getInt(String selectedTopTabIndicatorHeight, int defaultSelectedTopTabIndicatorHeight) {
154
+        return params.containsKey(selectedTopTabIndicatorHeight) ?
155
+                (int) params.getDouble(selectedTopTabIndicatorHeight) :
156
+                defaultSelectedTopTabIndicatorHeight;
157
+    }
126 158
 }

+ 0
- 13
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Ver fichero

@@ -5,7 +5,6 @@ import android.app.Activity;
5 5
 import android.graphics.Color;
6 6
 import android.os.Build;
7 7
 import android.support.v7.app.AppCompatActivity;
8
-import android.util.Log;
9 8
 import android.view.Window;
10 9
 import android.widget.RelativeLayout;
11 10
 
@@ -119,18 +118,6 @@ public abstract class Screen extends RelativeLayout {
119 118
         }
120 119
     }
121 120
 
122
-    @Override
123
-    protected void onAttachedToWindow() {
124
-        super.onAttachedToWindow();
125
-        Log.d("LOG", "Screen.onAttachedToWindow " + this);
126
-    }
127
-
128
-    @Override
129
-    protected void onDetachedFromWindow() {
130
-        super.onDetachedFromWindow();
131
-        Log.d("LOG", "Screen.onDetachedFromWindow " + this);
132
-    }
133
-
134 121
     public abstract void ensureUnmountOnDetachedFromWindow();
135 122
 
136 123
     public abstract void preventUnmountOnDetachedFromWindow();

+ 12
- 5
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java Ver fichero

@@ -14,6 +14,7 @@ import java.util.List;
14 14
 public class TopBar extends AppBarLayout {
15 15
 
16 16
     private TitleBar titleBar;
17
+    private TopTabs topTabs;
17 18
 
18 19
     public TopBar(Context context) {
19 20
         super(context);
@@ -40,6 +41,7 @@ public class TopBar extends AppBarLayout {
40 41
         }
41 42
         setVisibility(styleParams.topBarHidden ? GONE : VISIBLE);
42 43
         titleBar.setStyle(styleParams);
44
+        setTopTabsStyle(styleParams);
43 45
     }
44 46
 
45 47
     public void setTitleBarRightButtons(String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
@@ -47,9 +49,9 @@ public class TopBar extends AppBarLayout {
47 49
     }
48 50
 
49 51
     public TabLayout initTabs() {
50
-        TabLayout tabLayout = new TabLayout(getContext());
51
-        addView(tabLayout);
52
-        return tabLayout;
52
+        topTabs = new TopTabs(getContext());
53
+        addView(topTabs);
54
+        return topTabs;
53 55
     }
54 56
 
55 57
     public void setTitleBarRightButton(String navigatorEventId,
@@ -58,7 +60,12 @@ public class TopBar extends AppBarLayout {
58 60
         titleBar.setLeftButton(titleBarLeftButtonParams, titleBarBackButtonListener, navigatorEventId);
59 61
     }
60 62
 
61
-    public TitleBar getTitleBar() {
62
-        return titleBar;
63
+    private void setTopTabsStyle(StyleParams style) {
64
+        if (topTabs == null) {
65
+            return;
66
+        }
67
+
68
+        topTabs.setTopTabsTextColor(style);
69
+        topTabs.setSelectedTabIndicatorStyle(style);
63 70
     }
64 71
 }

+ 40
- 0
android/app/src/main/java/com/reactnativenavigation/views/TopTabs.java Ver fichero

@@ -0,0 +1,40 @@
1
+package com.reactnativenavigation.views;
2
+
3
+import android.content.Context;
4
+import android.content.res.ColorStateList;
5
+import android.support.design.widget.TabLayout;
6
+
7
+import com.reactnativenavigation.params.StyleParams;
8
+
9
+public class TopTabs extends TabLayout {
10
+
11
+    public TopTabs(Context context) {
12
+        super(context);
13
+    }
14
+
15
+    void setSelectedTabIndicatorStyle(StyleParams style) {
16
+        if (style.selectedTopTabIndicatorColor.hasColor()) {
17
+            setSelectedTabIndicatorColor(style.selectedTopTabIndicatorColor.getColor());
18
+        }
19
+
20
+        if (style.selectedTopTabIndicatorHeight >= 0) {
21
+            setSelectedTabIndicatorHeight(style.selectedTopTabIndicatorHeight);
22
+        }
23
+    }
24
+
25
+    void setTopTabsTextColor(StyleParams style) {
26
+        ColorStateList originalTabColors = getTabTextColors();
27
+        int selectedTabColor = originalTabColors != null ? originalTabColors.getColorForState(TabLayout.SELECTED_STATE_SET, -1) : -1;
28
+        int tabTextColor = originalTabColors != null ? originalTabColors.getColorForState(TabLayout.EMPTY_STATE_SET, -1) : -1;
29
+
30
+        if (style.topTabTextColor.hasColor()) {
31
+            tabTextColor = style.topTabTextColor.getColor();
32
+        }
33
+
34
+        if (style.selectedTopTabTextColor.hasColor()) {
35
+            selectedTabColor = style.selectedTopTabTextColor.getColor();
36
+        }
37
+
38
+        setTabTextColors(tabTextColor, selectedTabColor);
39
+    }
40
+}

+ 13
- 4
src/deprecated/platformSpecificDeprecated.android.js Ver fichero

@@ -97,18 +97,27 @@ function convertStyleParams(originalStyleObject) {
97 97
   return {
98 98
     statusBarColor: originalStyleObject.statusBarColor,
99 99
     topBarColor: originalStyleObject.navBarBackgroundColor,
100
-    navigationBarColor: originalStyleObject.navigationBarColor,
101 100
     titleBarHidden: originalStyleObject.navBarHidden,
102 101
     titleBarTitleColor: originalStyleObject.navBarTextColor,
103 102
     titleBarButtonColor: originalStyleObject.navBarButtonColor,
104 103
     backButtonHidden: originalStyleObject.backButtonHidden,
105 104
     topTabsHidden: originalStyleObject.topTabsHidden,
106
-    bottomTabsHidden: originalStyleObject.tabBarHidden,
107
-    bottomTabsHiddenOnScroll: originalStyleObject.bottomTabsHiddenOnScroll,
105
+
108 106
     drawBelowTopBar: !originalStyleObject.drawUnderNavBar,
107
+
108
+    topTabTextColor: originalStyleObject.topTabTextColor,
109
+    selectedTopTabTextColor: originalStyleObject.selectedTopTabTextColor,
110
+    selectedTopTabColor: originalStyleObject.selectedTopTabColor,
111
+    selectedTopTabIndicatorHeight: originalStyleObject.selectedTopTabIndicatorHeight,
112
+    selectedTopTabIndicatorColor: originalStyleObject.selectedTopTabIndicatorColor,
113
+
109 114
     bottomTabsColor: originalStyleObject.tabBarBackgroundColor,
110 115
     bottomTabsButtonColor: originalStyleObject.tabBarButtonColor,
111
-    bottomTabsSelectedButtonColor: originalStyleObject.tabBarSelectedButtonColor
116
+    bottomTabsSelectedButtonColor: originalStyleObject.tabBarSelectedButtonColor,
117
+    bottomTabsHidden: originalStyleObject.tabBarHidden,
118
+    bottomTabsHiddenOnScroll: originalStyleObject.bottomTabsHiddenOnScroll,
119
+
120
+    navigationBarColor: originalStyleObject.navigationBarColor
112 121
   }
113 122
 }
114 123