Browse Source

Align FAB to screen when BottomTabs are hidden (#1400)

Guy Carmeli 7 years ago
parent
commit
b4ad066b2f

+ 19
- 3
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

@@ -1,5 +1,6 @@
1 1
 package com.reactnativenavigation.layouts;
2 2
 
3
+import android.annotation.SuppressLint;
3 4
 import android.os.Bundle;
4 5
 import android.support.annotation.NonNull;
5 6
 import android.support.annotation.Nullable;
@@ -23,10 +24,12 @@ import com.reactnativenavigation.params.ScreenParams;
23 24
 import com.reactnativenavigation.params.SideMenuParams;
24 25
 import com.reactnativenavigation.params.SlidingOverlayParams;
25 26
 import com.reactnativenavigation.params.SnackbarParams;
27
+import com.reactnativenavigation.params.StyleParams;
26 28
 import com.reactnativenavigation.params.TitleBarButtonParams;
27 29
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
28 30
 import com.reactnativenavigation.screens.Screen;
29 31
 import com.reactnativenavigation.screens.ScreenStack;
32
+import com.reactnativenavigation.utils.ViewUtils;
30 33
 import com.reactnativenavigation.views.BottomTabs;
31 34
 import com.reactnativenavigation.views.LightBox;
32 35
 import com.reactnativenavigation.views.SideMenu;
@@ -40,6 +43,7 @@ import java.util.List;
40 43
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
41 44
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
42 45
 
46
+@SuppressLint("ViewConstructor")
43 47
 public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.OnTabSelectedListener {
44 48
 
45 49
     private ActivityParams params;
@@ -120,7 +124,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
120 124
     private void createSnackbarContainer() {
121 125
         snackbarAndFabContainer = new SnackbarAndFabContainer(getContext(), this);
122 126
         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
123
-        lp.addRule(ABOVE, bottomTabs.getId());
127
+        alignSnackbarContainerWithBottomTabs(lp, getCurrentScreen().getStyleParams());
124 128
         snackbarAndFabContainer.setClickable(false);
125 129
         getScreenStackParent().addView(snackbarAndFabContainer, lp);
126 130
     }
@@ -321,27 +325,30 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
321 325
         screenStack.push(params, createScreenLayoutParams(params));
322 326
         if (isCurrentStack(screenStack)) {
323 327
             bottomTabs.setStyleFromScreen(params.styleParams);
328
+            alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
324 329
             EventBus.instance.post(new ScreenChangedEvent(params));
325 330
         }
326 331
     }
327 332
 
328 333
     @Override
329
-    public void pop(ScreenParams params) {
334
+    public void pop(final ScreenParams params) {
330 335
         getCurrentScreenStack().pop(params.animateScreenTransitions, new ScreenStack.OnScreenPop() {
331 336
             @Override
332 337
             public void onScreenPopAnimationEnd() {
333 338
                 setBottomTabsStyleFromCurrentScreen();
339
+                alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
334 340
                 EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
335 341
             }
336 342
         });
337 343
     }
338 344
 
339 345
     @Override
340
-    public void popToRoot(ScreenParams params) {
346
+    public void popToRoot(final ScreenParams params) {
341 347
         getCurrentScreenStack().popToRoot(params.animateScreenTransitions, new ScreenStack.OnScreenPop() {
342 348
             @Override
343 349
             public void onScreenPopAnimationEnd() {
344 350
                 setBottomTabsStyleFromCurrentScreen();
351
+                alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
345 352
                 EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
346 353
             }
347 354
         });
@@ -353,10 +360,19 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
353 360
         screenStack.newStack(params, createScreenLayoutParams(params));
354 361
         if (isCurrentStack(screenStack)) {
355 362
             bottomTabs.setStyleFromScreen(params.styleParams);
363
+            alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
356 364
             EventBus.instance.post(new ScreenChangedEvent(params));
357 365
         }
358 366
     }
359 367
 
368
+    private void alignSnackbarContainerWithBottomTabs(LayoutParams lp, StyleParams styleParams) {
369
+        if (styleParams.drawScreenAboveBottomTabs || !styleParams.bottomTabsHidden) {
370
+            lp.addRule(ABOVE, bottomTabs.getId());
371
+        } else {
372
+            ViewUtils.removeRuleCompat(lp, ABOVE);
373
+        }
374
+    }
375
+
360 376
     @Override
361 377
     public void destroy() {
362 378
         snackbarAndFabContainer.destroy();

+ 9
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java View File

@@ -17,6 +17,7 @@ import android.view.ViewGroup;
17 17
 import android.view.ViewParent;
18 18
 import android.view.ViewTreeObserver;
19 19
 import android.view.WindowManager;
20
+import android.widget.RelativeLayout;
20 21
 import android.widget.TextView;
21 22
 
22 23
 import com.reactnativenavigation.NavigationApplication;
@@ -192,4 +193,12 @@ public class ViewUtils {
192 193
     public static void setSpanColor(SpannableString span, int color) {
193 194
         span.setSpan(new ForegroundColorSpan(color), 0, span.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
194 195
     }
196
+
197
+    public static void removeRuleCompat(RelativeLayout.LayoutParams layoutParams, int rule) {
198
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
199
+            layoutParams.removeRule(rule);
200
+        } else {
201
+            layoutParams.addRule(rule, 0);
202
+        }
203
+    }
195 204
 }