Browse Source

Implement setTabBadge in Android

Guy Carmeli 8 years ago
parent
commit
2628683e0f

+ 7
- 1
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java View File

72
     }
72
     }
73
 
73
 
74
     @ReactMethod
74
     @ReactMethod
75
-    public void setTabBadge(final ReadableMap params) {
75
+    public void setBottomTabBadgeByIndex(Integer index, String badge) {
76
+        NavigationCommandsHandler.setBottomTabBadgeByIndex(index, badge);
77
+    }
78
+
79
+    @ReactMethod
80
+    public void setBottomTabBadgeByNavigatorId(String navigatorId, String badge) {
81
+        NavigationCommandsHandler.setBottomTabBadgeByNavigatorId(navigatorId, badge);
76
     }
82
     }
77
 
83
 
78
     @ReactMethod
84
     @ReactMethod

+ 12
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

224
             ((BottomTabsLayout) layout).selectBottomTabByNavigatorId(navigatorId);
224
             ((BottomTabsLayout) layout).selectBottomTabByNavigatorId(navigatorId);
225
         }
225
         }
226
     }
226
     }
227
+
228
+    public void setBottomTabBadgeByIndex(Integer index, String badge) {
229
+        if (layout instanceof BottomTabsLayout) {
230
+            ((BottomTabsLayout) layout).setBottomTabBadgeByIndex(index, badge);
231
+        }
232
+    }
233
+
234
+    public void setBottomTabBadgeByNavigatorId(String navigatorId, String badge) {
235
+        if (layout instanceof BottomTabsLayout) {
236
+            ((BottomTabsLayout) layout).setBottomTabBadgeByNavigatorId(navigatorId, badge);
237
+        }
238
+    }
227
 }
239
 }

+ 28
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java View File

266
             }
266
             }
267
         });
267
         });
268
     }
268
     }
269
+
270
+    public static void setBottomTabBadgeByIndex(final Integer index, final String badge) {
271
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
272
+        if (currentActivity == null) {
273
+            return;
274
+        }
275
+
276
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
277
+            @Override
278
+            public void run() {
279
+                currentActivity.setBottomTabBadgeByIndex(index, badge);
280
+            }
281
+        });
282
+    }
283
+
284
+    public static void setBottomTabBadgeByNavigatorId(final String navigatorId, final String badge) {
285
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
286
+        if (currentActivity == null) {
287
+            return;
288
+        }
289
+
290
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
291
+            @Override
292
+            public void run() {
293
+                currentActivity.setBottomTabBadgeByNavigatorId(navigatorId, badge);
294
+            }
295
+        });
296
+    }
269
 }
297
 }

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

252
         return screenStacks[index];
252
         return screenStacks[index];
253
     }
253
     }
254
 
254
 
255
+    public void setBottomTabBadgeByIndex(Integer index, String badge) {
256
+        bottomTabs.setNotification(badge, index);
257
+    }
258
+
259
+    public void setBottomTabBadgeByNavigatorId(String navigatorId, String badge) {
260
+        bottomTabs.setNotification(badge, getScreenStackIndex(navigatorId));
261
+    }
262
+
255
     private int getScreenStackIndex(String navigatorId) throws ScreenStackNotFoundException {
263
     private int getScreenStackIndex(String navigatorId) throws ScreenStackNotFoundException {
256
         for (int i = 0; i < screenStacks.length; i++) {
264
         for (int i = 0; i < screenStacks.length; i++) {
257
             if (screenStacks[i].getNavigatorId().equals(navigatorId)) {
265
             if (screenStacks[i].getNavigatorId().equals(navigatorId)) {

+ 6
- 4
src/deprecated/platformSpecificDeprecated.android.js View File

232
 }
232
 }
233
 
233
 
234
 function navigatorSetTabBadge(navigator, params) {
234
 function navigatorSetTabBadge(navigator, params) {
235
-  //RctActivity.setTabBadge({
236
-  //  tabIndex: params.tabIndex,
237
-  //  badge: params.badge
238
-  //});
235
+  const badge = params.badge.toString();
236
+  if (params.tabIndex >= 0) {
237
+    newPlatformSpecific.setBottomTabBadgeByIndex(params.tabIndex, badge);
238
+  } else {
239
+    newPlatformSpecific.setBottomTabBadgeByNavigatorId(navigator.navigatorID, badge);
240
+  }
239
 }
241
 }
240
 
242
 
241
 function navigatorSetTitle(navigator, params) {
243
 function navigatorSetTitle(navigator, params) {

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

100
   NativeReactModule.selectBottomTabByTabIndex(index);
100
   NativeReactModule.selectBottomTabByTabIndex(index);
101
 }
101
 }
102
 
102
 
103
+function setBottomTabBadgeByIndex(index, badge) {
104
+  NativeReactModule.setBottomTabBadgeByIndex(index, badge);
105
+}
106
+
107
+function setBottomTabBadgeByNavigatorId(navigatorId, badge) {
108
+  NativeReactModule.setBottomTabBadgeByNavigatorId(navigatorId, badge);
109
+}
110
+
103
 module.exports = {
111
 module.exports = {
104
   startApp,
112
   startApp,
105
   push,
113
   push,
116
   toggleSideMenuVisible,
124
   toggleSideMenuVisible,
117
   setSideMenuVisible,
125
   setSideMenuVisible,
118
   selectBottomTabByNavigatorId,
126
   selectBottomTabByNavigatorId,
119
-  selectBottomTabByTabIndex
127
+  selectBottomTabByTabIndex,
128
+  setBottomTabBadgeByNavigatorId,
129
+  setBottomTabBadgeByIndex
120
 };
130
 };