From 2fe819717e05f8acbc52ee9b4f5635de9907515f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Sun, 29 Sep 2024 12:29:27 +0200 Subject: [PATCH] feat: support badges on Android --- android/src/main/java/com/rcttabview/RCTTabView.kt | 10 ++++++++-- example/app.json | 4 +++- example/src/App.tsx | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/rcttabview/RCTTabView.kt b/android/src/main/java/com/rcttabview/RCTTabView.kt index 5fb5afd7..27628504 100644 --- a/android/src/main/java/com/rcttabview/RCTTabView.kt +++ b/android/src/main/java/com/rcttabview/RCTTabView.kt @@ -2,7 +2,6 @@ package com.rcttabview import android.content.Context import android.view.MenuItem -import android.view.ViewGroup import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.google.android.material.bottomnavigation.BottomNavigationView @@ -39,8 +38,15 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context menu.clear() items.forEachIndexed {index, item -> // TODO: Handle custom icons - // TODO: Handle badges menu.add(0, index, 0, item.title).setIcon(android.R.drawable.btn_star) + + if (item.badge.isNotEmpty()) { + val badge = this.getOrCreateBadge(index) + badge.isVisible = true + badge.text = item.badge + } else { + removeBadge(index) + } } } } diff --git a/example/app.json b/example/app.json index cabc8dfc..4afd3e84 100644 --- a/example/app.json +++ b/example/app.json @@ -1,10 +1,12 @@ { "name": "ReactNativeBottomTabs", "displayName": "ReactNativeBottomTabs", + "singleApp": "bottomtabs-example", "components": [ { "appKey": "ReactNativeBottomTabs", - "displayName": "ReactNativeBottomTabs" + "displayName": "ReactNativeBottomTabs", + "slug": "bottomtabs-example" } ], "resources": { diff --git a/example/src/App.tsx b/example/src/App.tsx index 977b3668..96258506 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -9,8 +9,8 @@ import { Albums } from './Screens/Albums'; import { useState } from 'react'; const items: TabViewItems = [ - { key: 'article', title: 'Article', icon: 'document.fill' }, - { key: 'albums', title: 'Albums', icon: 'square.grid.2x2.fill', badge: '3' }, + { key: 'article', title: 'Article', icon: 'document.fill', badge: '!' }, + { key: 'albums', title: 'Albums', icon: 'square.grid.2x2.fill', badge: '5' }, { key: 'contacts', title: 'Contacts', icon: 'person.fill' }, ];