aniruddha dhamal
03/24/2021, 2:28 PMdewildte
03/24/2021, 4:20 PMViewModel
is it better to expose a single state object or multiple objects that make up the state?
For example let’s say I have two properties title: String
and isComplete: String
that could change over time.
The first option would be to wrap them up like so:
data class State(
val title: String = ",
val isComplete: Boolean = false
)
And then exposing it like this:
// MyViewModel.kt
val state: StateFlow<State>
And consuming it like this:
@Composable
fun ToDoUI(viewModel: MyViewModel) {
val state by viewModel.state.collectAsState()
...
}
OR is it better to decompose the state and expose it like so:
// MyViewModel.kt
val title: StateFlow<String>
val isComplete: StateFlow<Boolean>
And then consume like this:
@Composable
fun ToDoUI(viewModel: MyViewModel) {
val title by viewModel.title.collectAsState()
val isComplete by viewModel.isComplete.collectAsState()
...
}
What are the ramifications for my composables between the two?
Is there any performance issues or “gotchas” I should be aware of here?alorma
03/24/2021, 5:30 PModay
03/24/2021, 5:39 PMGabriel
03/24/2021, 9:37 PMvar modifier = Modifier
if (isSelected) {
modifier.border(2.dp, Color.White)
}
julioromano
03/24/2021, 9:40 PM@Composable
fun <T> Flow<T>.rememberWithLifecycle(
minActiveState: Lifecycle.State = Lifecycle.State.STARTED
): Flow<T> {
val lifecycleOwner = LocalLifecycleOwner.current
return remember(this, lifecycleOwner) {
flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState)
}
}
P.S. Please read the thread to get an understanding of why this approach is probably a not very good idea.Colton Idle
03/25/2021, 1:57 AMTlaster
03/25/2021, 7:22 AMPointerInputChange.consumePositionChange()
but where is PointerInputChange.consumePositionChange(x, y)
? I remember there is one before.Mehdi Haghgoo
03/25/2021, 7:55 AMSpikey Sanju
03/25/2021, 8:46 AMwidth
and height
inside Box Layout
? Like we do in canvas layout?mmaillot
03/25/2021, 10:13 AMwhen
in the composable function Bubble(bubble: Bubble)
which break the padding animation. If I directly use the fun Bubble(isBig: Boolean)
, the padding animation works. Why a when
condition will break the animation ? (here my case is simple, it’s a boolean but it can be a sealed class).
Edit: put code in a gist.Utkarsh Tiwari
03/25/2021, 10:37 AMGeert
03/25/2021, 10:47 AMjulioromano
03/25/2021, 10:57 AMColor
into an old-fashioned @ColorInt
?patrick
03/25/2021, 12:22 PMMichal Klimczak
03/25/2021, 1:07 PMfillViewPort
but for LazyColumn
(or Column
)?
The point is to do something like this.julioromano
03/25/2021, 1:18 PMCard
with a backgroundColor
that has an alpha value (i.e. not 00 and not FF) I’m seeing visual artefacts in the form of a border around the card.
See attached image (code in 🧵), is this working as intended or is this a bug?Deepak Gahlot
03/25/2021, 1:26 PMKshitij Patil
03/25/2021, 1:32 PMBottomNavigationItem
ripple freeze on frequent changes?tieskedh
03/25/2021, 1:50 PMskwalking
03/25/2021, 2:08 PMColton Idle
03/25/2021, 2:10 PMKshitij Patil
03/25/2021, 2:27 PMbeta03
with zero lines of code change, that’s crazy 🤯Ky
03/25/2021, 2:52 PMMaik
03/25/2021, 3:06 PMexception: java.lang.IllegalStateException: A MonotonicFrameClock is not available in this CoroutineContext. Callers should supply an appropriate MonotonicFrameClock using withContext.
How can I give the context the appropriate clock?Yahor
03/25/2021, 3:33 PMMarko Novakovic
03/25/2021, 3:35 PMToolbar
enterAlways
scrollBehavior
? is there built if way or I have to animate AppBar
myself when scroll direction changes?Colton Idle
03/25/2021, 5:01 PMMarko Novakovic
03/25/2021, 7:18 PMCould not find androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-beta03
what’s up with this?Neal Sanche
03/25/2021, 10:05 PMNeal Sanche
03/25/2021, 10:05 PMSiyamed
03/26/2021, 9:19 PMNeal Sanche
03/26/2021, 10:40 PMIan Lake
03/27/2021, 9:36 PM