mattinger
09/20/2022, 9:16 PMval screens = listOfScreens.sortedBy {
stringResource(it.label)
}
it complains that i can’t execute the stringResource function outside of composable scope. Instead i have to do this:
val context = LocalContext.current
val screens = listOfScreens.sortedBy {
context.getString(it.label)
}
I’m a little confused what has changed between either kotlin or compose that this became a compile errormkrussel
09/20/2022, 9:23 PMsortBy
is an inline function, so it should probably work. Might be a bug in the compose compiler.
Although you really don’t want to do sorting like that in a compose function. Sorting is one of the examples of using the derivedStateOf
function. Although since Compose doesn’t treat list as immutable that might not help.mkrussel
09/20/2022, 9:27 PMMR3Y
09/20/2022, 10:28 PMsortedBy
selector lambda parameter is marked as crossinline
which effectively prevents you from using non-local returns.
not sure what kotlin version exactly introduced this change, you can go through release notes Or commits to confirm it was introduced in a recent versionmattinger
09/21/2022, 2:58 AM