Roar Gronmo
12/06/2019, 11:25 AM@Lambda
annotation in front of the function which should intendly be the lambda function.
i.e.:
private fun BottomBar(
post: Post,
@Lambda onUnimplementedAction: () -> Unit){
...
}
If it isn't already suggested before.
RGbmo
12/06/2019, 11:31 AMAndrew Kelly
12/06/2019, 12:17 PMButton(text = "Hello") { Text("world")}
is that the compiler should throw a warning, that a @Composible shouldn’t be allowed as a click handler…there is enough info already to warn the user that the lambda is not working as they expect it to be.Roar Gronmo
12/06/2019, 12:27 PMprivate fun BottomBarAction(
@DrawableRes id: Int,
onClick: ()[1] -> Unit,
onLongClick: ()[2] -> Unit
)[1]{
//HandleClick
}[2]{
//HandleLongClick
}
Maybe bad suggestion 😋bmo
12/06/2019, 12:45 PMBottomBarAction(
id = someId,
onClick = { ... },
onLongClick = {... }
)
The trailing lambda is a nice touch but it can be tricky indeed as she points it out. Right now, their solution is good as it avoid overlaps of method signatures but it forces them to be very careful not to break it.Roar Gronmo
12/06/2019, 12:51 PMbmo
12/06/2019, 12:55 PMRoar Gronmo
12/06/2019, 1:03 PM@Lambda
may be a solution...
(Psst: I'm not offended, I'm to old for that). 🧓Column {
TopAppBar(
title = { Text(text = "JetNews") },
navigationIcon = {
VectorImageButton(id = R.drawable.ic_jetnews_logo) {
openDrawer()
}
}
)
}
or
Column {
TopAppBar(
title = { Text(text = "JetNews") },
navigationIcon = {
VectorImageButton(
id = R.drawable.ic_jetnews_logo,
onClick = {
openDrawer()
}
)
}
)
}
I must say the latter one is to prefer, because you understand what the actually action does (is it onClick
, onLongClick
or something else...?).
But not using the lambda method, will we miss some functionality, or are all the options/benefits there ?@Composable
public fun <T> TabRow(
items: List<T>,
selectedIndex: Int,
scrollable: Boolean,
indicatorContainer: @Composable()
(List<TabRow.TabPosition>) → Unit,
tab: @Composable()
(Int, T) → Unit
): Unit
At the definition now (as I understand), the lambda points to the latest added parameter, tab: @Composable() (Int, T)->Unit,
but it could in theory be the indicatorContainer: @Composable() (List<TabRow.TabPosition>) -> Unit
. So to make that happen, we need to override and switch theese two parameters ?
I rather stick to using parameter reference here...
BTW: If there was this @Lambda
annotation defining which one was the defined lambda, when an ambiguity existed, it would be clear for everybody, and you could define it anywhere in the sequence of lambda likes, but only one (at this time, maybe named ones later @Lambda(MyLambdaName)
. How those should be referenced in the code structure, I'm not sure... )Leland Richardson [G]
12/11/2019, 5:58 PMRoar Gronmo
12/11/2019, 6:54 PMLeland Richardson [G]
12/11/2019, 7:35 PMButton(text="Hello", onClick={ ... })
and
Button(onClick={ ... }, content={ Text("Hello") })
Button { println("Hello world") }
and
Button("Click me") { println("hello world") }
Button({ Text("Click me") }) { println("hello world") }
Roar Gronmo
12/11/2019, 7:48 PMLeland Richardson [G]
12/11/2019, 8:03 PMRoar Gronmo
12/11/2019, 8:08 PM...
MaterialTheme {
ModalDrawerLayout(
drawerState = drawerState,
onStateChange = onDrawerStateChange,
gesturesEnabled = drawerState == Opened,
lambda drawerContent, //<-- lambda prefix
bodyContent = {
AppContent(
openDrawer = {
onDrawerStateChanged(Opened)
}
)
}
){ //lambda is drawerContent
AppDrawer(
closeDrawer = {
onDrawerStateChange(Closed)
}
)
}
}
(for you who reads this, it will not work in kotlin (at the moment 😁) )
RG@Composable
fun ModalDrawerLayout(
drawerState: DrawerState,
onStateChange: (DrawerState) -> Unit,
gesturesEnabled: Boolean = true,
drawerContent: @Composable() () -> Unit,
lambda bodyContent: @Composable() () -> Unit ) //<- it clearly shows which parameter is the defined lambda (and it is simply overridable if it should be used otherwise), as shown in previous example.
(for you who reads this, it will not work in kotlin (at the moment 😁) )
RG@Composable
fun ModalDrawerLayout(
drawerState: DrawerState,
onStateChange: (DrawerState) -> Unit,
gesturesEnabled: Boolean = true,
drawerContent: @Composable() () -> Unit,
bodyContent: @Composable() () -> lambda Unit ) //<- it clearly shows which parameter is the defined lambda (and it is simply overridable if it should be used otherwise), as shown in previous example.
(for you who reads this, it will not work in kotlin (at the moment 😁) )
RG@Composable
fun ModalDrawerLayout(
drawerState: DrawerState,
onStateChange: (DrawerState) -> Unit,
gesturesEnabled: Boolean = true,
drawerContent: @Composable() () -> Unit,
bodyContent: @Composable() () -> Unit lambda ) //<- it clearly shows which parameter is the defined lambda (and it is simply overridable if it should be used otherwise), as shown in previous example.
(for you who reads this, it will not work in kotlin (at the moment 😁) )
RG@Composable
fun ModalDrawerLayout(
drawerState: DrawerState,
onStateChange: (DrawerState) -> Unit,
gesturesEnabled: Boolean = true,
drawerContent: @Composable() () -> Unit lambda, //<-
bodyContent: @Composable() () -> Unit)
// Here drawerContent is lambda.
(for you who reads this, it will not work in kotlin (at the moment 😁) )
RG