Browse Source

Added screen backgroundColor to BottomTabsLayout (#1427)

Brendon Sled 7 years ago
parent
commit
1603eb9bfa

+ 16
- 5
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

@@ -8,7 +8,6 @@ import android.support.v4.widget.DrawerLayout;
8 8
 import android.support.v7.app.AppCompatActivity;
9 9
 import android.view.View;
10 10
 import android.widget.RelativeLayout;
11
-
12 11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
13 12
 import com.facebook.react.bridge.Arguments;
14 13
 import com.facebook.react.bridge.Callback;
@@ -319,12 +318,24 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
319 318
         bottomTabs.setCurrentItem(getScreenStackIndex(navigatorId));
320 319
     }
321 320
 
321
+    private boolean hasBackgroundColor(StyleParams params) {
322
+        return params.screenBackgroundColor != null &&
323
+                params.screenBackgroundColor.hasColor();
324
+    }
325
+
326
+    private void setStyleFromScreen(StyleParams params) {
327
+        bottomTabs.setStyleFromScreen(params);
328
+        if (hasBackgroundColor(params)) {
329
+            asView().setBackgroundColor(params.screenBackgroundColor.getColor());
330
+        }
331
+    }
332
+
322 333
     @Override
323 334
     public void push(ScreenParams params) {
324 335
         ScreenStack screenStack = getScreenStack(params.getNavigatorId());
325 336
         screenStack.push(params, createScreenLayoutParams(params));
337
+        setStyleFromScreen(params.styleParams);
326 338
         if (isCurrentStack(screenStack)) {
327
-            bottomTabs.setStyleFromScreen(params.styleParams);
328 339
             alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
329 340
             EventBus.instance.post(new ScreenChangedEvent(params));
330 341
         }
@@ -359,7 +370,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
359 370
         ScreenStack screenStack = getScreenStack(params.getNavigatorId());
360 371
         screenStack.newStack(params, createScreenLayoutParams(params));
361 372
         if (isCurrentStack(screenStack)) {
362
-            bottomTabs.setStyleFromScreen(params.styleParams);
373
+            setStyleFromScreen(params.styleParams);
363 374
             alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
364 375
             EventBus.instance.post(new ScreenChangedEvent(params));
365 376
         }
@@ -433,7 +444,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
433 444
 
434 445
     private void showStackAndUpdateStyle(ScreenStack newStack) {
435 446
         newStack.show();
436
-        bottomTabs.setStyleFromScreen(newStack.getCurrentScreenStyleParams());
447
+        setStyleFromScreen(newStack.getCurrentScreenStyleParams());
437 448
     }
438 449
 
439 450
     private void hideCurrentStack() {
@@ -486,7 +497,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
486 497
     }
487 498
 
488 499
     private void setBottomTabsStyleFromCurrentScreen() {
489
-        bottomTabs.setStyleFromScreen(getCurrentScreenStack().getCurrentScreenStyleParams());
500
+        setStyleFromScreen(getCurrentScreenStack().getCurrentScreenStyleParams());
490 501
     }
491 502
 
492 503
     @Override