Просмотр исходного кода

Some work towards proper bottom tabs styling

Guy Carmeli 8 лет назад
Родитель
Сommit
be537459b3

+ 1
- 1
android/app/build.gradle Просмотреть файл

@@ -46,7 +46,7 @@ allprojects { p ->
46 46
 
47 47
 dependencies {
48 48
     compile fileTree(dir: "libs", include: ["*.jar"])
49
-    compile "com.aurelhubert:ahbottomnavigation:1.2.3"
49
+    compile "com.aurelhubert:ahbottomnavigation:1.3.0"
50 50
     compile "com.android.support:appcompat-v7:23.0.1"
51 51
     compile 'com.android.support:design:23.1.1'
52 52
     compile "com.facebook.react:react-native:+"  // From node_modules

+ 4
- 12
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java Просмотреть файл

@@ -55,7 +55,6 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
55 55
 
56 56
     private void createBottomTabs() {
57 57
         bottomTabs = new BottomTabs(getContext());
58
-        setBottomTabsStyle();
59 58
         bottomTabs.addTabs(params.tabParams, this);
60 59
     }
61 60
 
@@ -69,14 +68,6 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
69 68
         showStack(screenStacks[0]);
70 69
     }
71 70
 
72
-    private void setBottomTabsStyle() {
73
-//        bottomTabs.setForceTitlesDisplay(style.getBoolean(TAB_STYLE_INACTIVE_TITLES, DEFAULT_TAB_INACTIVE_TITLES));
74
-        bottomTabs.setForceTint(true);
75
-//        bottomTabs.setDefaultBackgroundColor(getColor(style, TAB_STYLE_BAR_BG_COLOR, DEFAULT_TAB_BAR_BG_COLOR));
76
-//        bottomTabs.setInactiveColor(getColor(style, TAB_STYLE_BUTTON_COLOR, DEFAULT_TAB_BUTTON_COLOR));
77
-//        bottomTabs.setAccentColor(getColor(style, TAB_STYLE_SELECTED_COLOR, DEFAULT_TAB_SELECTED_COLOR));
78
-    }
79
-
80 71
     @Override
81 72
     public View asView() {
82 73
         return this;
@@ -150,22 +141,23 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
150 141
     public void destroy() {
151 142
         for (ScreenStack screenStack : screenStacks) {
152 143
             screenStack.destroy();
153
-            removeView(screenStack);
154 144
         }
155
-        screenStacks = null;
156 145
     }
157 146
 
158 147
     @Override
159
-    public void onTabSelected(int position, boolean wasSelected) {
148
+    public boolean onTabSelected(int position, boolean wasSelected) {
160 149
         hideCurrentStack();
161 150
 
162 151
         ScreenStack newStack = screenStacks[position];
163 152
         showStack(newStack);
164 153
         currentStackIndex = position;
154
+
155
+        return true;
165 156
     }
166 157
 
167 158
     private void showStack(ScreenStack newStack) {
168 159
         newStack.setVisibility(VISIBLE);
160
+        bottomTabs.setStyleFromScreen(newStack.getCurrentScreenStyleParams());
169 161
     }
170 162
 
171 163
     private void hideCurrentStack() {

+ 11
- 3
android/app/src/main/java/com/reactnativenavigation/params/ScreenStyleParams.java Просмотреть файл

@@ -24,13 +24,21 @@ public class ScreenStyleParams {
24 24
     }
25 25
 
26 26
     public Color statusBarColor;
27
+
27 28
     public Color topBarColor;
28
-    public Color navigationBarColor;
29
-    public boolean titleBarHidden;
30 29
     public boolean topBarHidden;
31
-    public boolean backButtonHidden;
32 30
     public boolean topTabsHidden;
31
+
32
+    public boolean titleBarHidden;
33
+    public boolean backButtonHidden;
34
+
33 35
     public boolean bottomTabsHidden;
34 36
     public boolean bottomTabsHiddenOnScroll;
37
+    public Color bottomTabsColor;
38
+    public Color selectedBottomTabsButtonColor;
39
+    public Color bottomTabsButtonColor;
40
+
41
+    public Color navigationBarColor;
42
+
35 43
     public boolean drawUnderTopBar;
36 44
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenStyleParamsParser.java Просмотреть файл

@@ -19,6 +19,7 @@ public class ScreenStyleParamsParser {
19 19
         result.topTabsHidden = params.getBoolean("topTabsHidden");
20 20
         result.bottomTabsHidden = params.getBoolean("bottomTabsHidden");
21 21
         result.bottomTabsHiddenOnScroll = params.getBoolean("bottomTabsHiddenOnScroll");
22
+        result.bottomTabsColor = new ScreenStyleParams.Color(ColorParser.parse(params.getString("bottomTabsColor")));
22 23
         result.drawUnderTopBar = params.getBoolean("drawUnderTopBar", false);
23 24
         return result;
24 25
     }

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Просмотреть файл

@@ -153,4 +153,8 @@ public abstract class Screen extends RelativeLayout implements ScrollDirectionLi
153 153
                                       TitleBarLeftButtonParams titleBarLeftButtonParams) {
154 154
         topBar.setTitleBarRightButton(navigatorEventId, backButtonListener, titleBarLeftButtonParams);
155 155
     }
156
+
157
+    public ScreenStyleParams getStyleParams() {
158
+        return screenParams.styleParams;
159
+    }
156 160
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java Просмотреть файл

@@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
5 5
 import android.widget.FrameLayout;
6 6
 
7 7
 import com.reactnativenavigation.params.ScreenParams;
8
+import com.reactnativenavigation.params.ScreenStyleParams;
8 9
 import com.reactnativenavigation.params.TitleBarButtonParams;
9 10
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
10 11
 import com.reactnativenavigation.views.TitleBarBackButtonListener;
@@ -154,4 +155,8 @@ public class ScreenStack extends FrameLayout implements TitleBarBackButtonListen
154 155
             screen.preventMountAfterReattachedToWindow();
155 156
         }
156 157
     }
158
+
159
+    public ScreenStyleParams getCurrentScreenStyleParams() {
160
+        return stack.peek().getStyleParams();
161
+    }
157 162
 }

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java Просмотреть файл

@@ -6,12 +6,14 @@ import android.graphics.Color;
6 6
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
7 7
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
8 8
 import com.reactnativenavigation.params.ScreenParams;
9
+import com.reactnativenavigation.params.ScreenStyleParams;
9 10
 
10 11
 import java.util.List;
11 12
 
12 13
 public class BottomTabs extends AHBottomNavigation {
13 14
     public BottomTabs(Context context) {
14 15
         super(context);
16
+        setForceTint(true);
15 17
     }
16 18
 
17 19
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
@@ -22,4 +24,16 @@ public class BottomTabs extends AHBottomNavigation {
22 24
             setOnTabSelectedListener(onTabSelectedListener);
23 25
         }
24 26
     }
27
+
28
+    public void setStyleFromScreen(ScreenStyleParams params) {
29
+        if (params.bottomTabsColor.hasColor()) {
30
+            setDefaultBackgroundColor(params.bottomTabsColor.getColor());
31
+        } else {
32
+            setDefaultBackgroundColor(Color.WHITE);
33
+        }
34
+
35
+//        setForceTitlesDisplay(true);
36
+//        setInactiveColor(params.bottomTabsButtonColor.getColor());
37
+//        setAccentColor(params.selectedBottomTabsButtonColor.getColor());
38
+    }
25 39
 }

+ 4
- 1
src/deprecated/platformSpecificDeprecated.android.js Просмотреть файл

@@ -90,7 +90,10 @@ function adaptNavigationStyleToScreenStyle(screen) {
90 90
     topTabsHidden: navigatorStyle.topTabsHidden,
91 91
     bottomTabsHidden: navigatorStyle.tabBarHidden,
92 92
     bottomTabsHiddenOnScroll: navigatorStyle.bottomTabsHiddenOnScroll,
93
-    drawUnderTopBar: navigatorStyle.drawUnderNavBar
93
+    drawUnderTopBar: navigatorStyle.drawUnderNavBar,
94
+    bottomTabsColor: navigatorStyle.tabBarBackgroundColor,
95
+    bottomTabsButtonColor: navigatorStyle.tabBarButtonColor,
96
+    selectedBottomTabsButtonColor: navigatorStyle.tabBarButtonColor
94 97
   };
95 98
 
96 99
   return _.omit(screen, ['navigatorStyle']);