Gauthier POULET
09/01/2020, 2:17 PMJD
09/01/2020, 2:18 PMjaqxues
09/01/2020, 2:51 PMharry248
09/01/2020, 3:02 PMSlackbot
09/01/2020, 4:45 PMMehdi Haghgoo
09/01/2020, 4:51 PMzak.taccardi
09/01/2020, 5:26 PMflow.collectAsState("initialState")
requires an initial state (when not using a StateFlow<T>
. How can we avoid having this initial state?
For example, I would like to have a composable not be considered “ready” until the Flow<T>
emits. By ready, I mean shown to the user. Is something like this possible? The idea would be something like fragment.postponeEnterTransition(..)
(link) which allows the Fragment
to asynchronously load its data before appearing to the user. This way an initial state would not need to be provided and only fully loaded data need be displayeddimsuz
09/01/2020, 5:56 PMval inputState: TextFieldValue by mutableStateOf(TextFieldValue())
TextField(value = inputState.value, onValueChange = { inputState = it })
But if I wrap in remember
than text input starts working. I am asking because Compose State codelab has examples which have only by mutableStateOf
and no remember
(for example in ViewModel section), but TextField turns out to be special here?JD
09/01/2020, 6:16 PMcarbaj0
09/01/2020, 6:20 PMSergey Y.
09/01/2020, 8:30 PMselectableItemBackgroundBorderless
attribute?
Thanks.Michał Jurczyk
09/01/2020, 9:08 PMLazyColumn
of cards and want to drag'n'drop items onto the cards from a picker.
In native UI I used to do it with setOnDragListener
listening to ACTION_DROP
and clipData
🤔Siyamed
09/01/2020, 10:55 PMMehdi Haghgoo
09/02/2020, 4:07 AMfengdai
09/02/2020, 4:19 AMWhen Compose recomposes based on new inputs, it only calls the functions or lambdas that might have changed, and skips the rest.Why is the root Compose function
RecompositionBehavior
always recomposed while the Switch
only changes the input of MaterialTheme
?
@Preview("RecompositionBehavior")
@Composable
fun RecompositionBehavior() {
Log.d("Recompose", "RecompositionBehavior")
var darkTheme by remember { mutableStateOf(false) }
MaterialTheme(
colors = if (darkTheme) darkColors else lightColors,
) {
Log.d("Recompose", "MaterialTheme")
Surface {
Switch(checked = darkTheme, onCheckedChange = { darkTheme = it })
}
}
}
Mehdi Haghgoo
09/02/2020, 8:46 AMprivate val todoViewModel by viewModels<TodoViewModel>()
Why can't we just write val todoViewModel = List<TodoViewModel>()
?Spikey Sanju
09/02/2020, 11:19 AMTimo Drick
09/02/2020, 11:47 AMvar checkBoxState by savedInstanceState { false }
Is not using the provided Registry :-(
log("${item.data} saved state: $${item.savedState}")
val restoredRegistry by remember(item.savedState) {
log("${item.data} Create new registry with: ${item.savedState}")
mutableStateOf(UiSavedStateRegistry(restoredValues = item.savedState, canBeSaved = { true }))
}
Providers(UiSavedStateRegistryAmbient provides restoredRegistry) {
log("${item.data} ${UiSavedStateRegistryAmbient.current}")
children(item.data)
onDispose {
val saved = restoredRegistry.performSave()
log("${item.data} onDispose saved: $saved")
item.savedState = saved
}
}
Maybe someone can point me into the right direction what is wrong?Daniele B
09/02/2020, 11:53 AMonBackPressed(){...}
method of the Activity without calling super.onBackPressed()
?Zach Klippenstein (he/him) [MOD]
09/02/2020, 12:07 PMdataExample
use property delegation here? It looks like it's being used as though it is the actual value of the state. Also, the link to observeAsState
is broken. Should these be reported on the issue tracker? https://developer.android.com/jetpack/compose/interop#asyncjaqxues
09/02/2020, 12:23 PMKetan
09/02/2020, 12:48 PMbuildWhen (previousState, currentState)
] while re-composing the ui widget so if data is not changed for particular child ui widget it won’t be re-composed?
Is there any way to achieve this?Mehdi Haghgoo
09/02/2020, 1:20 PMA value computed byWhat is a key?will be stored in the composition tree, and only be recomputed if the keys toremember
change. -linkremember
Mehdi Haghgoo
09/02/2020, 1:52 PM@Composable
fun TodoScreen(
items: List<TodoItem>,
onAddItem: (TodoItem) -> Unit,
onRemoveItem: (TodoItem) -> Unit
) {
Column {
LazyColumnFor(
items = items,
modifier = Modifier.weight(1f),
contentPadding = InnerPadding(top = 8.dp)
) { todo ->
TodoRow(
todo = todo,
onItemClicked = { onRemoveItem(it) },
modifier = Modifier.fillParentMaxWidth()
)
}
// For quick testing, a random item generator button
FloatingActionButton(
shape = CircleShape,
elevation = 8.dp,
icon = {
Row(modifier = Modifier.padding(16.dp)){
Icon(asset = vectorResource(id = R.drawable.add))
Text("Add New Item")
}
},
onClick = { onAddItem(generateRandomTodoItem()) },
modifier = Modifier.gravity(Alignment.CenterHorizontally),
)
}
}
Any ideas why this happens? Do I need a constraint mechanism or something for the FAB?Mehdi Haghgoo
09/02/2020, 2:12 PMTimo Drick
09/02/2020, 2:26 PMbruno.aybar
09/02/2020, 2:41 PMloloof64
09/02/2020, 5:01 PMtcracknell
09/02/2020, 6:16 PMHalil Ozercan
09/02/2020, 8:13 PM// using itemId as key would still give me the same viewModel when this composable gets recreated
val key = remember(itemId) { UUID.randomUUID().toString() }
val commentsViewModel = viewModel<CommentsViewModel>(key = key)
However, I cannot remove this particular viewModel from the store without removing other viewModels that were stored in the same place. How should I proceed with this? Is this an anti-pattern?