Browse Source

Wire up tab show/hide and tab selection

Jason Skuby 8 years ago
parent
commit
5e29cc03fd

+ 11
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java View File

45
  */
45
  */
46
 public abstract class BaseReactActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
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
     protected static final String KEY_TITLE = "title";
51
     protected static final String KEY_TITLE = "title";
49
     private static final String TAG = "BaseReactActivity";
52
     private static final String TAG = "BaseReactActivity";
50
     private static final String REDBOX_PERMISSION_MESSAGE =
53
     private static final String REDBOX_PERMISSION_MESSAGE =
366
 
369
 
367
         mToolbar.setTitle(title.getString(KEY_TITLE));
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 View File

9
 
9
 
10
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
10
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
12
+import com.facebook.react.bridge.ReadableMap;
12
 import com.reactnativenavigation.R;
13
 import com.reactnativenavigation.R;
13
 import com.reactnativenavigation.core.RctManager;
14
 import com.reactnativenavigation.core.RctManager;
14
 import com.reactnativenavigation.core.objects.Screen;
15
 import com.reactnativenavigation.core.objects.Screen;
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
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
210
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
193
         private BottomTabActivity mActivity;
211
         private BottomTabActivity mActivity;
194
         private RnnToolBar mToolBar;
212
         private RnnToolBar mToolBar;

+ 28
- 0
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java View File

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
     @ReactMethod
151
     @ReactMethod
124
     public void navigatorPush(final ReadableMap skreen) {
152
     public void navigatorPush(final ReadableMap skreen) {
125
         final Screen screen = new Screen(skreen);
153
         final Screen screen = new Screen(skreen);

+ 16
- 1
src/platformSpecific.android.js View File

88
   RctActivity.setNavigatorTitle(params);
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
 function showModal(params) {
104
 function showModal(params) {
92
   addNavigatorParams(params);
105
   addNavigatorParams(params);
93
   addNavigatorButtons(params);
106
   addNavigatorButtons(params);
144
   dismissModal,
157
   dismissModal,
145
   dismissAllModals,
158
   dismissAllModals,
146
   navigatorSetButtons,
159
   navigatorSetButtons,
147
-  navigatorSetTitle
160
+  navigatorSetTitle,
161
+  navigatorSwitchToTab,
162
+  navigatorToggleTabs
148
 }
163
 }