Browse Source

Add TopTabs style

Guy Carmeli 8 years ago
parent
commit
76560beb48

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java View File

45
     public Color titleBarButtonColor;
45
     public Color titleBarButtonColor;
46
     public boolean backButtonHidden;
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
     public boolean bottomTabsHidden;
54
     public boolean bottomTabsHidden;
49
     public boolean bottomTabsHiddenOnScroll;
55
     public boolean bottomTabsHiddenOnScroll;
50
     public Color bottomTabsColor;
56
     public Color bottomTabsColor;

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

23
         result.statusBarColor = getColor("statusBarColor", getDefaultStatusBarColor());
23
         result.statusBarColor = getColor("statusBarColor", getDefaultStatusBarColor());
24
 
24
 
25
         result.topBarColor = getColor("topBarColor", getDefaultTopBarColor());
25
         result.topBarColor = getColor("topBarColor", getDefaultTopBarColor());
26
-        result.titleBarHidden = getBoolean("titleBarHidden", isDefaultTopBarHidden());
26
+        result.titleBarHidden = getBoolean("titleBarHidden", getDefaultTopBarHidden());
27
         result.titleBarTitleColor = getColor("titleBarTitleColor", getDefaultTitleBarColor());
27
         result.titleBarTitleColor = getColor("titleBarTitleColor", getDefaultTitleBarColor());
28
         result.titleBarButtonColor = getColor("titleBarButtonColor", getTitleBarButtonColor());
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
         // TODO: Uncomment once we support drawBelowTopBar again
38
         // TODO: Uncomment once we support drawBelowTopBar again
33
         //result.drawScreenBelowTopBar = params.getBoolean("drawBelowTopBar", isDefaultScreenBelowTopBar());
39
         //result.drawScreenBelowTopBar = params.getBoolean("drawBelowTopBar", isDefaultScreenBelowTopBar());
34
         result.drawScreenBelowTopBar = true;
40
         result.drawScreenBelowTopBar = true;
35
 
41
 
36
-        result.bottomTabsHidden = getBoolean("bottomTabsHidden", isDefaultBottomTabsHidden());
42
+        result.bottomTabsHidden = getBoolean("bottomTabsHidden", getDefaultBottomTabsHidden());
37
         result.bottomTabsHiddenOnScroll =
43
         result.bottomTabsHiddenOnScroll =
38
-                getBoolean("bottomTabsHiddenOnScroll", isDefaultBottomTabsHiddenOnScroll());
44
+                getBoolean("bottomTabsHiddenOnScroll", getDefaultBottomTabsHiddenOnScroll());
39
         result.bottomTabsColor = getColor("bottomTabsColor", getDefaultBottomTabsColor());
45
         result.bottomTabsColor = getColor("bottomTabsColor", getDefaultBottomTabsColor());
40
         result.bottomTabsButtonColor = getColor("bottomTabsButtonColor", getDefaultBottomTabsButtonColor());
46
         result.bottomTabsButtonColor = getColor("bottomTabsButtonColor", getDefaultBottomTabsButtonColor());
41
         result.selectedBottomTabsButtonColor =
47
         result.selectedBottomTabsButtonColor =
46
         return result;
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
     @Nullable
71
     @Nullable
50
     private StyleParams.Color getDefaultNavigationColor() {
72
     private StyleParams.Color getDefaultNavigationColor() {
51
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.navigationBarColor;
73
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.navigationBarColor;
66
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.bottomTabsColor;
88
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.bottomTabsColor;
67
     }
89
     }
68
 
90
 
69
-    private boolean isDefaultBottomTabsHiddenOnScroll() {
91
+    private boolean getDefaultBottomTabsHiddenOnScroll() {
70
         return AppStyle.appStyle != null && AppStyle.appStyle.bottomTabsHiddenOnScroll;
92
         return AppStyle.appStyle != null && AppStyle.appStyle.bottomTabsHiddenOnScroll;
71
     }
93
     }
72
 
94
 
73
-    private boolean isDefaultBottomTabsHidden() {
95
+    private boolean getDefaultBottomTabsHidden() {
74
         return AppStyle.appStyle != null && AppStyle.appStyle.bottomTabsHidden;
96
         return AppStyle.appStyle != null && AppStyle.appStyle.bottomTabsHidden;
75
     }
97
     }
76
 
98
 
78
         return AppStyle.appStyle == null || AppStyle.appStyle.drawScreenBelowTopBar;
100
         return AppStyle.appStyle == null || AppStyle.appStyle.drawScreenBelowTopBar;
79
     }
101
     }
80
 
102
 
81
-    private boolean isDefaultTopTabsHidden() {
103
+    private boolean getDefaultTopTabsHidden() {
82
         return AppStyle.appStyle != null && AppStyle.appStyle.topTabsHidden;
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
         return AppStyle.appStyle != null && AppStyle.appStyle.backButtonHidden;
112
         return AppStyle.appStyle != null && AppStyle.appStyle.backButtonHidden;
87
     }
113
     }
88
 
114
 
96
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.titleBarButtonColor;
122
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.titleBarButtonColor;
97
     }
123
     }
98
 
124
 
99
-    private boolean isDefaultTopBarHidden() {
125
+    private boolean getDefaultTopBarHidden() {
100
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarHidden;
126
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarHidden;
101
     }
127
     }
102
 
128
 
123
             return defaultColor != null && defaultColor.hasColor() ? defaultColor : color;
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 View File

5
 import android.graphics.Color;
5
 import android.graphics.Color;
6
 import android.os.Build;
6
 import android.os.Build;
7
 import android.support.v7.app.AppCompatActivity;
7
 import android.support.v7.app.AppCompatActivity;
8
-import android.util.Log;
9
 import android.view.Window;
8
 import android.view.Window;
10
 import android.widget.RelativeLayout;
9
 import android.widget.RelativeLayout;
11
 
10
 
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
     public abstract void ensureUnmountOnDetachedFromWindow();
121
     public abstract void ensureUnmountOnDetachedFromWindow();
135
 
122
 
136
     public abstract void preventUnmountOnDetachedFromWindow();
123
     public abstract void preventUnmountOnDetachedFromWindow();

+ 12
- 5
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

14
 public class TopBar extends AppBarLayout {
14
 public class TopBar extends AppBarLayout {
15
 
15
 
16
     private TitleBar titleBar;
16
     private TitleBar titleBar;
17
+    private TopTabs topTabs;
17
 
18
 
18
     public TopBar(Context context) {
19
     public TopBar(Context context) {
19
         super(context);
20
         super(context);
40
         }
41
         }
41
         setVisibility(styleParams.topBarHidden ? GONE : VISIBLE);
42
         setVisibility(styleParams.topBarHidden ? GONE : VISIBLE);
42
         titleBar.setStyle(styleParams);
43
         titleBar.setStyle(styleParams);
44
+        setTopTabsStyle(styleParams);
43
     }
45
     }
44
 
46
 
45
     public void setTitleBarRightButtons(String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
47
     public void setTitleBarRightButtons(String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
47
     }
49
     }
48
 
50
 
49
     public TabLayout initTabs() {
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
     public void setTitleBarRightButton(String navigatorEventId,
57
     public void setTitleBarRightButton(String navigatorEventId,
58
         titleBar.setLeftButton(titleBarLeftButtonParams, titleBarBackButtonListener, navigatorEventId);
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 View File

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 View File

97
   return {
97
   return {
98
     statusBarColor: originalStyleObject.statusBarColor,
98
     statusBarColor: originalStyleObject.statusBarColor,
99
     topBarColor: originalStyleObject.navBarBackgroundColor,
99
     topBarColor: originalStyleObject.navBarBackgroundColor,
100
-    navigationBarColor: originalStyleObject.navigationBarColor,
101
     titleBarHidden: originalStyleObject.navBarHidden,
100
     titleBarHidden: originalStyleObject.navBarHidden,
102
     titleBarTitleColor: originalStyleObject.navBarTextColor,
101
     titleBarTitleColor: originalStyleObject.navBarTextColor,
103
     titleBarButtonColor: originalStyleObject.navBarButtonColor,
102
     titleBarButtonColor: originalStyleObject.navBarButtonColor,
104
     backButtonHidden: originalStyleObject.backButtonHidden,
103
     backButtonHidden: originalStyleObject.backButtonHidden,
105
     topTabsHidden: originalStyleObject.topTabsHidden,
104
     topTabsHidden: originalStyleObject.topTabsHidden,
106
-    bottomTabsHidden: originalStyleObject.tabBarHidden,
107
-    bottomTabsHiddenOnScroll: originalStyleObject.bottomTabsHiddenOnScroll,
105
+
108
     drawBelowTopBar: !originalStyleObject.drawUnderNavBar,
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
     bottomTabsColor: originalStyleObject.tabBarBackgroundColor,
114
     bottomTabsColor: originalStyleObject.tabBarBackgroundColor,
110
     bottomTabsButtonColor: originalStyleObject.tabBarButtonColor,
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