this post was submitted on 18 Jul 2023
4 points (100.0% liked)

Android Development

10 readers
1 users here now

Welcome to the programming.dev Android development community!

The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License

founded 1 year ago
MODERATORS
 

Hey, I have a function that draws a composable,

@Composable
        fun home() : @Composable RowScope.() -> Unit {
            return {
                BottomNavigationItem(
                    icon = {
                        Icon(Icons.Filled.Home, "Home")
                    },
                    onClick = {},
                    selected = false,
                    label = {
                        Text("Home")
                    }
                )
            }
        }

That doesn't draw it to the GUI I am calling it with

@Composable
fun App() {
    MaterialTheme {
        BottomAppBar {
            StaticAssets.BarButtons.home()
        }
    }
}

Does anyone know why it doesn't work?

top 2 comments
sorted by: hot top controversial new old
[โ€“] sebschaef@feddit.de 1 points 1 year ago (1 children)

A Composable is not meant to return anything if it draws something. In your case it should look like this:

@Composable
fun Home() {
    BottomNavigationItem(...)
}
[โ€“] spi@programming.dev 1 points 1 year ago

Found out why apparently you have to .invoke it because it needs to be in a rowscope