Преглед изворни кода

Support tabBarHidden property

Guy Carmeli пре 8 година
родитељ
комит
0aaed3300d

+ 25
- 3
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java Прегледај датотеку

@@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable;
5 5
 import android.os.AsyncTask;
6 6
 import android.os.Bundle;
7 7
 import android.view.Menu;
8
+import android.view.View;
8 9
 import android.widget.FrameLayout;
9 10
 
10 11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
@@ -118,6 +119,10 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
118 119
             }
119 120
         }
120 121
         StyleHelper.updateStyles(mToolbar, getCurrentScreen());
122
+
123
+        if (shouldToggleTabs(screen)) {
124
+            toggleTabs(screen.bottomTabsHidden, false);
125
+        }
121 126
     }
122 127
 
123 128
     @Override
@@ -126,7 +131,13 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
126 131
         for (ScreenStack stack : mScreenStacks) {
127 132
             if (stack.peek().navigatorId.equals(navigatorId)) {
128 133
                 Screen popped = stack.pop();
129
-                StyleHelper.updateStyles(mToolbar, getCurrentScreen());
134
+                Screen currentScreen = getCurrentScreen();
135
+                StyleHelper.updateStyles(mToolbar, currentScreen);
136
+
137
+                if (shouldToggleTabs(currentScreen)) {
138
+                    toggleTabs(currentScreen.bottomTabsHidden, false);
139
+                }
140
+
130 141
                 return popped;
131 142
             }
132 143
         }
@@ -225,13 +236,24 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
225 236
     public void toggleTabs(ReadableMap params) {
226 237
         boolean hide = params.getBoolean(KEY_HIDDEN);
227 238
         boolean animated = params.getBoolean(KEY_ANIMATED);
239
+        toggleTabs(hide, animated);
240
+    }
241
+
242
+    // TODO: support animated = false -guyca
243
+    private void toggleTabs(boolean hide, boolean animated) {
228 244
         if (hide) {
229
-            mBottomNavigation.hideBottomNavigation(animated);
245
+//            mBottomNavigation.hideBottomNavigation(animated);
246
+            mBottomNavigation.setVisibility(View.GONE);
230 247
         } else {
231
-            mBottomNavigation.restoreBottomNavigation(animated);
248
+            mBottomNavigation.setVisibility(View.VISIBLE);
249
+//            mBottomNavigation.restoreBottomNavigation(animated);
232 250
         }
233 251
     }
234 252
 
253
+    private boolean shouldToggleTabs(Screen newScreen) {
254
+        return mBottomNavigation.isShown() == newScreen.bottomTabsHidden;
255
+    }
256
+
235 257
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
236 258
         private BottomTabActivity mActivity;
237 259
         private RnnToolBar mToolBar;

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/core/objects/Screen.java Прегледај датотеку

@@ -43,6 +43,7 @@ public class Screen extends JsonObject implements Serializable {
43 43
     private static final String KEY_TAB_NORMAL_TEXT_COLOR = "tabNormalTextColor";
44 44
     private static final String KEY_TAB_SELECTED_TEXT_COLOR = "tabSelectedTextColor";
45 45
     private static final String KEY_TAB_INDICATOR_COLOR = "tabIndicatorColor";
46
+    private static final String KEY_BOTTOM_TABS_HIDDEN = "tabBarHidden";
46 47
     private static final String KEY_PROPS = "passProps";
47 48
 
48 49
     public String title;
@@ -66,6 +67,7 @@ public class Screen extends JsonObject implements Serializable {
66 67
     @Nullable @ColorInt public Integer tabNormalTextColor;
67 68
     @Nullable @ColorInt public Integer tabSelectedTextColor;
68 69
     @Nullable @ColorInt public Integer tabIndicatorColor;
70
+    public Boolean bottomTabsHidden;
69 71
 
70 72
     @NonNull
71 73
     public List<Button> getButtons() {
@@ -132,6 +134,7 @@ public class Screen extends JsonObject implements Serializable {
132 134
             tabNormalTextColor = getColor(style, KEY_TAB_NORMAL_TEXT_COLOR);
133 135
             tabSelectedTextColor = getColor(style, KEY_TAB_SELECTED_TEXT_COLOR);
134 136
             tabIndicatorColor = getColor(style, KEY_TAB_INDICATOR_COLOR);
137
+            bottomTabsHidden = getBoolean(style, KEY_BOTTOM_TABS_HIDDEN);
135 138
         }
136 139
     }
137 140
 }