1
Scaffold(
           bottomBar = { SootheBottomNavigation() },
           content = { padding ->
           HomeScreen(Modifier.padding(padding))
       }
       ) 

   @Composable
    fun HomeScreen(modifier: Modifier = Modifier) {
    
         
    }

How do you pass content composable without the lambda into Scaffold? Below is the parameter for Scaffold

content: @Composable (PaddingValues) -> Unit
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sjso
  • 277
  • 2
  • 11
  • what do you want to achieve? the same functionality with different aesthetics? or do you want to omit the Scaffold's content? – Horațiu Udrea Aug 04 '22 at 08:54
  • I want to learn how to pass functions without lambdas. I'm confused. This doesnt work for composable functions ( https://play.kotlinlang.org/byExample/04_functional/01_Higher-Order%20Functions) – sjso Aug 04 '22 at 09:05
  • yes same functionality with different aesthetics – sjso Aug 04 '22 at 09:08

1 Answers1

1

I'm not sure if I understood your question...

I think you want to do this:

@Composable
fun ScreenContent(paddingValues: PaddingValues) {
    Text("Hello")
}

@Composable
fun MyScreen() {
    Scaffold(
        content = ::ScreenContent // ERROR here
    )
}

But seems like this is not supported, since this error is displayed:

"Function References of @Composable functions are not currently supported"

An alternative would be:

val ScreenContent: @Composable (PaddingValues) -> Unit = { it ->
    Text("Hello")
}

@Composable
fun MyScreen() {
    Scaffold(
        content = ScreenContent
    )
}

But to be honest, I would go with the regular lambda calls...

@Composable 
fun ScreenContent(paddingValues: PaddingValues) { 
    Text("Hello")
}

@Composable
fun MyScreen() {
    Scaffold(
        content = { ScreenContent(it) }
    )
}
nglauber
  • 18,674
  • 6
  • 70
  • 75