Просмотр исходного кода

Add toggle bottomTabs

works best with drawUnderTabBar
Guy Carmeli 8 лет назад
Родитель
Сommit
4f1ed3a0fd

+ 4
- 3
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java Просмотреть файл

@@ -88,8 +88,8 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
88 88
     }
89 89
 
90 90
     @ReactMethod
91
-    public void setTopBarVisible(String screenInstanceID, boolean hidden, boolean animated) {
92
-        NavigationCommandsHandler.setTopBarVisible(screenInstanceID, hidden, animated);
91
+    public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
92
+        NavigationCommandsHandler.setTopBarVisible(screenInstanceId, hidden, animated);
93 93
     }
94 94
 
95 95
     @ReactMethod
@@ -97,7 +97,8 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
97 97
     }
98 98
 
99 99
     @ReactMethod
100
-    public void setBottomTabsVisible(final ReadableMap params) {
100
+    public void setBottomTabsVisible(boolean hidden, boolean animated) {
101
+        NavigationCommandsHandler.setBottomTabsVisible(hidden, animated);
101 102
     }
102 103
 
103 104
     @ReactMethod

+ 7
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Просмотреть файл

@@ -7,6 +7,7 @@ import android.view.KeyEvent;
7 7
 
8 8
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
9 9
 import com.reactnativenavigation.NavigationApplication;
10
+import com.reactnativenavigation.layouts.BottomTabsLayout;
10 11
 import com.reactnativenavigation.layouts.Layout;
11 12
 import com.reactnativenavigation.layouts.LayoutFactory;
12 13
 import com.reactnativenavigation.params.ActivityParams;
@@ -147,6 +148,12 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
147 148
         modalController.setTopBarVisible(screenInstanceId, hidden, animated);
148 149
     }
149 150
 
151
+    public void setBottomTabsVisible(boolean hidden, boolean animated) {
152
+        if (layout instanceof BottomTabsLayout) {
153
+            ((BottomTabsLayout) layout).setBottomTabsVisible(hidden, animated);
154
+        }
155
+    }
156
+
150 157
     void setTitleBarTitle(String screenInstanceId, String title) {
151 158
         layout.setTitleBarTitle(screenInstanceId, title);
152 159
         modalController.setTitleBarTitle(screenInstanceId, title);

+ 14
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java Просмотреть файл

@@ -48,7 +48,6 @@ public class NavigationCommandsHandler {
48 48
         });
49 49
     }
50 50
 
51
-
52 51
     public static void pop(Bundle screenParams) {
53 52
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
54 53
         if (currentActivity == null) {
@@ -108,6 +107,20 @@ public class NavigationCommandsHandler {
108 107
         });
109 108
     }
110 109
 
110
+    public static void setBottomTabsVisible(final boolean hidden, final boolean animated) {
111
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
112
+        if (currentActivity == null) {
113
+            return;
114
+        }
115
+
116
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
117
+            @Override
118
+            public void run() {
119
+                currentActivity.setBottomTabsVisible(hidden, animated);
120
+            }
121
+        });
122
+    }
123
+
111 124
     public static void setScreenTitleBarTitle(final String screenInstanceId, final String title) {
112 125
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
113 126
         if (currentActivity == null) {

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java Просмотреть файл

@@ -93,6 +93,10 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
93 93
         }
94 94
     }
95 95
 
96
+    public void setBottomTabsVisible(boolean hidden, boolean animated) {
97
+        bottomTabs.setVisibility(hidden, animated);
98
+    }
99
+
96 100
     @Override
97 101
     public void setTitleBarTitle(String screenInstanceId, String title) {
98 102
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {

+ 20
- 0
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java Просмотреть файл

@@ -5,6 +5,7 @@ import android.graphics.Color;
5 5
 
6 6
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
7 7
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
8
+import com.reactnativenavigation.animation.VisibilityAnimator;
8 9
 import com.reactnativenavigation.params.ScreenParams;
9 10
 import com.reactnativenavigation.params.StyleParams;
10 11
 import com.reactnativenavigation.utils.ViewUtils;
@@ -12,10 +13,14 @@ import com.reactnativenavigation.utils.ViewUtils;
12 13
 import java.util.List;
13 14
 
14 15
 public class BottomTabs extends AHBottomNavigation {
16
+
17
+    private VisibilityAnimator visibilityAnimator;
18
+
15 19
     public BottomTabs(Context context) {
16 20
         super(context);
17 21
         setForceTint(true);
18 22
         setId(ViewUtils.generateViewId());
23
+        createVisibilityAnimator();
19 24
     }
20 25
 
21 26
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
@@ -27,6 +32,10 @@ public class BottomTabs extends AHBottomNavigation {
27 32
         }
28 33
     }
29 34
 
35
+    public void setVisibility(boolean hidden, boolean animated) {
36
+        visibilityAnimator.setVisible(hidden, animated);
37
+    }
38
+
30 39
     public void setStyleFromScreen(StyleParams params) {
31 40
         setBackgroundColor(params.bottomTabsColor);
32 41
 
@@ -52,4 +61,15 @@ public class BottomTabs extends AHBottomNavigation {
52 61
     private void setVisibility(boolean bottomTabsHidden) {
53 62
         setVisibility(bottomTabsHidden ? GONE : VISIBLE);
54 63
     }
64
+
65
+    private void createVisibilityAnimator() {
66
+        ViewUtils.runOnPreDraw(this, new Runnable() {
67
+            @Override
68
+            public void run() {
69
+                visibilityAnimator = new VisibilityAnimator(BottomTabs.this,
70
+                        VisibilityAnimator.HideDirection.Down,
71
+                        getHeight());
72
+            }
73
+        });
74
+    }
55 75
 }

+ 3
- 5
src/deprecated/platformSpecificDeprecated.android.js Просмотреть файл

@@ -24,7 +24,6 @@ function startSingleScreenApp(params) {
24 24
   /*
25 25
    * adapt to new API
26 26
    */
27
-  console.log('0');
28 27
   screen.screenId = screen.screen;
29 28
   params.screen = adaptNavigationStyleToScreenStyle(screen);
30 29
   params.screen = adaptNavigationParams(screen);
@@ -227,10 +226,9 @@ function navigatorToggleNavBar(navigator, params) {
227 226
 }
228 227
 
229 228
 function navigatorToggleTabs(navigator, params) {
230
-  //RctActivity.toggleNavigatorTabs({
231
-  //  hidden: params.to === 'hidden',
232
-  //  animated: !(params.animated === false)
233
-  //});
229
+  const visibility = params.to === 'hidden';
230
+  const animated = !(params.animated === false);
231
+  newPlatformSpecific.toggleBottomTabsVisible(visibility, animated);
234 232
 }
235 233
 
236 234
 function showModal(params) {

+ 5
- 0
src/platformSpecific.android.js Просмотреть файл

@@ -30,6 +30,10 @@ function toggleTopBarVisible(screenInstanceID, visible, animated) {
30 30
   NativeReactModule.setTopBarVisible(screenInstanceID, visible, animated);
31 31
 }
32 32
 
33
+function toggleBottomTabsVisible(visible, animated) {
34
+  NativeReactModule.setBottomTabsVisible(visible, animated);
35
+}
36
+
33 37
 function setScreenTitleBarTitle(screenInstanceID, title) {
34 38
   NativeReactModule.setScreenTitleBarTitle(screenInstanceID, title);
35 39
 }
@@ -57,6 +61,7 @@ module.exports = {
57 61
   popToRoot,
58 62
   newStack,
59 63
   toggleTopBarVisible,
64
+  toggleBottomTabsVisible,
60 65
   setScreenTitleBarTitle,
61 66
   setScreenTitleBarButtons,
62 67
   showModal,