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

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

17
 import android.view.ViewParent;
17
 import android.view.ViewParent;
18
 import android.view.ViewTreeObserver;
18
 import android.view.ViewTreeObserver;
19
 import android.view.WindowManager;
19
 import android.view.WindowManager;
20
+import android.widget.RelativeLayout;
20
 import android.widget.TextView;
21
 import android.widget.TextView;
21
 
22
 
22
 import com.reactnativenavigation.NavigationApplication;
23
 import com.reactnativenavigation.NavigationApplication;
192
     public static void setSpanColor(SpannableString span, int color) {
193
     public static void setSpanColor(SpannableString span, int color) {
193
         span.setSpan(new ForegroundColorSpan(color), 0, span.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
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
 }