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 InputsWrapper( | |
name: String, | |
creditCardNumber: String, | |
onNameEntered: (value: String) -> Unit, | |
onCreditCardNumberEntered: (value: String) -> Unit, | |
) { | |
var count by remember { | |
mutableStateOf(0) | |
} |
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 StateReadsInlinedComposablesSolution2Screen() { | |
var count by remember { mutableStateOf(0) } | |
Column { | |
TextWrapper(provideCount = { 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 | |
fun StateReadsInlinedComposablesScreen() { | |
var count by remember { mutableStateOf(0) } | |
WrappedColumn { | |
Text(text = "count: $count") | |
Button(onClick = { count++ }) { | |
Text(text = "increase 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 | |
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
@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") | |
} | |
} | |
} |