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
 import android.support.v7.app.AppCompatActivity;
8
 import android.support.v7.app.AppCompatActivity;
9
 import android.view.View;
9
 import android.view.View;
10
 import android.widget.RelativeLayout;
10
 import android.widget.RelativeLayout;
11
-
12
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
13
 import com.facebook.react.bridge.Arguments;
12
 import com.facebook.react.bridge.Arguments;
14
 import com.facebook.react.bridge.Callback;
13
 import com.facebook.react.bridge.Callback;
319
         bottomTabs.setCurrentItem(getScreenStackIndex(navigatorId));
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
     @Override
333
     @Override
323
     public void push(ScreenParams params) {
334
     public void push(ScreenParams params) {
324
         ScreenStack screenStack = getScreenStack(params.getNavigatorId());
335
         ScreenStack screenStack = getScreenStack(params.getNavigatorId());
325
         screenStack.push(params, createScreenLayoutParams(params));
336
         screenStack.push(params, createScreenLayoutParams(params));
337
+        setStyleFromScreen(params.styleParams);
326
         if (isCurrentStack(screenStack)) {
338
         if (isCurrentStack(screenStack)) {
327
-            bottomTabs.setStyleFromScreen(params.styleParams);
328
             alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
339
             alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
329
             EventBus.instance.post(new ScreenChangedEvent(params));
340
             EventBus.instance.post(new ScreenChangedEvent(params));
330
         }
341
         }
359
         ScreenStack screenStack = getScreenStack(params.getNavigatorId());
370
         ScreenStack screenStack = getScreenStack(params.getNavigatorId());
360
         screenStack.newStack(params, createScreenLayoutParams(params));
371
         screenStack.newStack(params, createScreenLayoutParams(params));
361
         if (isCurrentStack(screenStack)) {
372
         if (isCurrentStack(screenStack)) {
362
-            bottomTabs.setStyleFromScreen(params.styleParams);
373
+            setStyleFromScreen(params.styleParams);
363
             alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
374
             alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
364
             EventBus.instance.post(new ScreenChangedEvent(params));
375
             EventBus.instance.post(new ScreenChangedEvent(params));
365
         }
376
         }
433
 
444
 
434
     private void showStackAndUpdateStyle(ScreenStack newStack) {
445
     private void showStackAndUpdateStyle(ScreenStack newStack) {
435
         newStack.show();
446
         newStack.show();
436
-        bottomTabs.setStyleFromScreen(newStack.getCurrentScreenStyleParams());
447
+        setStyleFromScreen(newStack.getCurrentScreenStyleParams());
437
     }
448
     }
438
 
449
 
439
     private void hideCurrentStack() {
450
     private void hideCurrentStack() {
486
     }
497
     }
487
 
498
 
488
     private void setBottomTabsStyleFromCurrentScreen() {
499
     private void setBottomTabsStyleFromCurrentScreen() {
489
-        bottomTabs.setStyleFromScreen(getCurrentScreenStack().getCurrentScreenStyleParams());
500
+        setStyleFromScreen(getCurrentScreenStack().getCurrentScreenStyleParams());
490
     }
501
     }
491
 
502
 
492
     @Override
503
     @Override