This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun StateReadsInlinedComposablesScreen() { | |
var count by remember { mutableStateOf(0) } | |
Column { | |
Text(text = "count: $count") | |
Button(onClick = { count++ }) { | |
Text(text = "count++") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
private fun WrappedLazyColumnApproach2(items: ImmutableList<Int>) { | |
LazyColumn { | |
items(items = items, key = { item -> item }) { item -> | |
Text(text = "item $item") | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Immutable | |
class ImmutableListWrapper(val items: List<Int>) | |
// optimized using @Immutable marked ImmutableWrapper | |
@Composable | |
private fun WrappedLazyColumnApproach1(wrapper: ImmutableListWrapper) { | |
LazyColumn { | |
items(items = wrapper.items, key = { item -> item }) { item -> | |
Text(text = "item $item") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun UnstableListScreen() { | |
val items = remember { (0..100).map { it } } | |
Box { | |
WrappedLazyColumn(items) | |
} | |
} | |
@Composable | |
private fun WrappedLazyColumn(items: List<Int>) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun UnstableLambdaScreen(viewModel: TypicalViewModel = hiltViewModel()) { | |
val focusRequester = LocalFocusManager.current | |
val onNameEnteredClick: (value: String) -> Unit = remember { | |
return@remember viewModel::onNameEntered | |
} | |
val clearFocus = remember { { focusRequester.clearFocus() } } | |
Column { | |
// stable lambdas, skippable button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun UnstableLambdaScreen(viewModel: TypicalViewModel = hiltViewModel()) { | |
Column { | |
// stable | |
Button(onClick = viewModel::onContinueClick) { | |
Text(text = "button with stable lambda") | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun UnstableLambdaScreen() { | |
val focusRequester = LocalFocusManager.current | |
Column { | |
// unstable lambda results in unskippable Button | |
Button(onClick = { focusRequester.clearFocus() }) { | |
Text(text = "button with unstable lambda") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun UnstableLambdaScreen(viewModel: TypicalViewModel = hiltViewModel()) { | |
Column { | |
// button is not skippable due to usage of viewModel.onContinueClick() | |
Button(onClick = { viewModel.onContinueClick() }) { | |
Text(text = "button with unstable lambda") | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Immutable | |
data class ImmutableUserWrapper(val user: User) | |
@Composable | |
private fun UserDetails(wrapper: ImmutableUserWrapper) { | |
Text(text = "name: ${wrapper.user.name} id:${wrapper.user.id}") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// not skippable if User is unstable | |
@Composable | |
private fun UserDetails(user: User) { | |
Text(text = "name: ${user.name} id:${user.id}") | |
} | |
// skippable even of User is unstable | |
@Composable | |
private fun UserDetails(id: Long, name: String) { | |
Text(text = "name: $name id: $id") |