Kaynağa Gözat

Wire up tab show/hide and tab selection

Jason Skuby 8 yıl önce
ebeveyn
işleme
5e29cc03fd

+ 11
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java Dosyayı Görüntüle

@@ -45,6 +45,9 @@ import javax.annotation.Nullable;
45 45
  */
46 46
 public abstract class BaseReactActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
47 47
 
48
+    protected static final String KEY_ANIMATED = "animated";
49
+    protected static final String KEY_HIDDEN = "hidden";
50
+    protected static final String KEY_TAB_INDEX = "tabIndex";
48 51
     protected static final String KEY_TITLE = "title";
49 52
     private static final String TAG = "BaseReactActivity";
50 53
     private static final String REDBOX_PERMISSION_MESSAGE =
@@ -366,4 +369,12 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
366 369
 
367 370
         mToolbar.setTitle(title.getString(KEY_TITLE));
368 371
     }
372
+
373
+    public void switchToTab(ReadableMap params) {
374
+        return;
375
+    }
376
+
377
+    public void toggleTabs(ReadableMap params) {
378
+        return;
379
+    }
369 380
 }

+ 18
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java Dosyayı Görüntüle

@@ -9,6 +9,7 @@ import android.widget.FrameLayout;
9 9
 
10 10
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
11 11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
12
+import com.facebook.react.bridge.ReadableMap;
12 13
 import com.reactnativenavigation.R;
13 14
 import com.reactnativenavigation.core.RctManager;
14 15
 import com.reactnativenavigation.core.objects.Screen;
@@ -189,6 +190,23 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
189 190
         }
190 191
     }
191 192
 
193
+    @Override
194
+    public void switchToTab(ReadableMap params) {
195
+        int tabIndex = params.getInt(KEY_TAB_INDEX);
196
+        mBottomNavigation.setCurrentItem(tabIndex);
197
+    }
198
+
199
+    @Override
200
+    public void toggleTabs(ReadableMap params) {
201
+        boolean hide = params.getBoolean(KEY_HIDDEN);
202
+        boolean animated = params.getBoolean(KEY_ANIMATED);
203
+        if (hide) {
204
+            mBottomNavigation.hideBottomNavigation(animated);
205
+        } else {
206
+            mBottomNavigation.restoreBottomNavigation(animated);
207
+        }
208
+    }
209
+
192 210
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
193 211
         private BottomTabActivity mActivity;
194 212
         private RnnToolBar mToolBar;

+ 28
- 0
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java Dosyayı Görüntüle

@@ -120,6 +120,34 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
120 120
         });
121 121
     }
122 122
 
123
+    @ReactMethod
124
+    public void switchToTab(final ReadableMap params) {
125
+        final BaseReactActivity context = ContextProvider.getActivityContext();
126
+        if (context == null || context.isFinishing()) {
127
+            return;
128
+        }
129
+        context.runOnUiThread(new Runnable() {
130
+            @Override
131
+            public void run() {
132
+                context.switchToTab(params);
133
+            }
134
+        });
135
+    }
136
+
137
+    @ReactMethod
138
+    public void toggleNavigatorTabs(final ReadableMap params) {
139
+        final BaseReactActivity context = ContextProvider.getActivityContext();
140
+        if (context == null || context.isFinishing()) {
141
+            return;
142
+        }
143
+        context.runOnUiThread(new Runnable() {
144
+            @Override
145
+            public void run() {
146
+                context.toggleTabs(params);
147
+            }
148
+        });
149
+    }
150
+
123 151
     @ReactMethod
124 152
     public void navigatorPush(final ReadableMap skreen) {
125 153
         final Screen screen = new Screen(skreen);

+ 16
- 1
src/platformSpecific.android.js Dosyayı Görüntüle

@@ -88,6 +88,19 @@ function navigatorSetTitle(navigator, params) {
88 88
   RctActivity.setNavigatorTitle(params);
89 89
 }
90 90
 
91
+function navigatorSwitchToTab(navigator, params) {
92
+  RctActivity.switchToTab({
93
+    tabIndex: params.tabIndex
94
+  });
95
+}
96
+
97
+function navigatorToggleTabs(navigator, params) {
98
+  RctActivity.toggleNavigatorTabs({
99
+    hidden: params.to == 'hidden',
100
+    animated: !(params.animated === false)
101
+  });
102
+}
103
+
91 104
 function showModal(params) {
92 105
   addNavigatorParams(params);
93 106
   addNavigatorButtons(params);
@@ -144,5 +157,7 @@ export default {
144 157
   dismissModal,
145 158
   dismissAllModals,
146 159
   navigatorSetButtons,
147
-  navigatorSetTitle
160
+  navigatorSetTitle,
161
+  navigatorSwitchToTab,
162
+  navigatorToggleTabs
148 163
 }