Skip to content

Commit

Permalink
feat(android): support programatic index update
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Sep 28, 2024
1 parent 3d3ca2e commit 162afca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView

class ReactBottomNavigationView(context: Context) : BottomNavigationView(context) {
private var onTabSelectedListener: ((WritableMap) -> Unit)? = null
private var items: MutableList<TabInfo>? = null
var items: MutableList<TabInfo>? = null

init {
setOnItemSelectedListener { item ->
Expand All @@ -34,7 +34,7 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
onTabSelectedListener = listener
}

fun setItems(items: MutableList<TabInfo>) {
fun updateItems(items: MutableList<TabInfo>) {
this.items = items
menu.clear()
items.forEachIndexed {index, item ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ class SwiftuiTabviewViewManager :
)
}
}
view.setItems(itemsArray)
view.updateItems(itemsArray)
}

@ReactProp(name = "selectedPage")
fun setSelectedPage(view: ReactBottomNavigationView, key: String) {
view.items?.indexOfFirst { it.key == key }?.let {
view.selectedItemId = it
}
}

public override fun createViewInstance(context: ThemedReactContext): ReactBottomNavigationView {
Expand Down

0 comments on commit 162afca

Please sign in to comment.