compose-router icon indicating copy to clipboard operation
compose-router copied to clipboard

0.1.0-dev06 - BottomNavigation Sample

Open iNoles opened this issue 4 years ago • 4 comments

It would be nice to have one. ;)

iNoles avatar Mar 07 '20 04:03 iNoles

Have you work in something with BottomNavigation and compose-router?

pdecarcer avatar Jun 05 '20 06:06 pdecarcer

I have not.

iNoles avatar Jun 05 '20 15:06 iNoles

I did this behaviour using Rxjava and JetPack BottonNavigation if you are interested

pdecarcer avatar Jun 11 '20 17:06 pdecarcer

Hello, I just managed the back stack as necessary for BottomNavigation, meaning the user always goes back to Home before leaving the app, and all other options than Home are replacing each other:

fun <T> BackStack<T>.pushBottomBar(root: T, others: List<T>, item: T) {
    if (item == root || last() != item ) {
        when {
            root == item -> {
                val removeHowMany = elements.size - elements.indexOf(item)
                repeat(removeHowMany) { pop() }
            }
            elements.any(others::contains) -> {
                replace(item)
            }
            else -> push(item)
        }
    }
}

And here's the BottomNavigation:

BottomNavigation {
    menuItems.forEach { item ->
        BottomNavigationItem(
            icon = { Icon(vectorResource(id = item.iconResId)) },
            text = { Text(stringResource(id = item.label)) },
            selected = currentRouting == item,
            onSelected = { backStack.pushBottomBar(defaultRouting, menuItems - defaultRouting, item) }
        )
    }
}

Hope this helps!

galex avatar Aug 01 '20 19:08 galex