allan.conda
12/16/2020, 12:34 PMLaunchedEffect(error) {
snackbarState.showSnackbar(error.message)
}
I have this but this doesn’t run if exactly the same error happens.Tony Kazanjian
12/16/2020, 6:23 PMVadim
12/16/2020, 6:55 PMIcon(vectorResource(R.drawable.ic_accessory_arrow))
where ic_accessory_arrow
is a vector drawable. This code crashes on API 21 with android.content.res.Resources$NotFoundException: File res/drawable-xxhdpi-v4/ic_accessory_arrow.png from xml type xml resource ID #0x7f0800e3
exception. So, what should I do for older SDKs? Write it like that?
// Random number here: I don't even know which API versions implicitly convert vector drawables to png
if (Build.VERSION.SDK_INT > 23) {
Icon(vectorResource(…))
} else {
Icon(imageResource(…))
}
Nemanja Scepanovic
12/16/2020, 8:48 PMDialogFragment
, created with composables, when explicitly dismissed by some callback (ex. button click)? This composable has ScollableColumn/LazyColumn
, and if I replace it with a regular Column
everything is working? Stacktrace in the thread. Cheers 😄Sam
12/16/2020, 9:01 PMalpha09
was released today 🥳🥳🥳 check out the latest here https://developer.android.com/jetpack/androidx/versions/all-channeltcracknell
12/16/2020, 9:05 PMDoris Liu
12/16/2020, 11:12 PMTransition
animation to make it easier to use and more extensible. tl;dr No more `PropKey`s and `transitionDefinition`s, and instead animations can be declared dynamically. 🎉 Please give the new Transition (available since alpha 09) a try. I would love to hear what you think! 🙏 (P.S. Seeking isn't supported yet, but dynamic target values (e.g. theme-specific values) are now supported.)robnik
12/16/2020, 11:19 PMval model: ContactSellerViewModel by viewModel()
Any ideas?matvei
12/17/2020, 1:04 PMModifier.nestedScroll
. Basic components like LazyColumn
and BackdropScaffold
already support this, but you can do even more yourself!
Let me know if you have any feedback or feature requests 🙂Joost Klitsie
12/17/2020, 1:48 PMJohn O'Reilly
12/17/2020, 5:24 PMpadding()
then default system padding values are used (using Modifier.padding()
). In Compose it looks like 0dp
is used if no parameters are passed. Would be nice I think to use SwiftUI's approach here..
VStack {
....
}
.padding()
robnik
12/17/2020, 6:01 PMText
to wrap to a second line to avoid pushing things off screen? Inside a screen-wide Column I have:
Row {
Text("A somewhat long line that needs to wrap probably")
Spacer(Modifier.width(3.dp))
Switch(model.foo, { model.foo = it })
}
The Text and Switch are overlapping a bit, and the Switch half pushed off screen.John O'Reilly
12/17/2020, 7:58 PMText
elements within something like HStack
as shown below. Is anything similar possible right now with Compose (or planned)?
HStack {
Text("some text")
Text("some more text")
}
.font(.caption)
zoha131
12/17/2020, 8:50 PMsuspend
if something goes wrong inside composable
function and app crashes then AS don’t provide any fatal error in the logcat. Is there any way to get the fatal report from AS?Dominaezzz
12/17/2020, 8:56 PMLazyColum(reverseLayout=true)
with VerticalScrollbar(...)
? (Mine goes in the wrong direction)Denis
12/17/2020, 10:42 PMModifier.scale
(or .graphicsLayer
with `scaleX`/`scaleY` parameters)? Here's a sample code:
@Preview
@Composable
fun TestScale() {
Row(Modifier.fillMaxSize()) {
val origin0 = TransformOrigin(0f, 0f)
Box(Modifier.graphicsLayer(scaleX = .5f, scaleY = .5f, transformOrigin = origin0)) {
SomeComposable(Color.Cyan)
}
Box(Modifier.graphicsLayer(scaleX = 2f, scaleY = 2f, transformOrigin = origin0)) {
SomeComposable(Color.Green)
}
Box(Modifier.graphicsLayer(scaleX = 3f, scaleY = 3f, transformOrigin = origin0)) {
SomeComposable(Color.Yellow)
}
}
}
@Composable
fun SomeComposable(color: Color) {
Box(modifier = Modifier.background(color).padding(16.dp)) {
Text("OK")
}
}
I want it to draw 3 boxes side-by-side but it looks like it doesn't respect scale at all. And there are those original size wireframes drawn when you hover over the the boxes. Do I need to write a custom layout or is there anything wrong with my code?Madhava
12/18/2020, 1:03 AMChethan
12/18/2020, 5:02 AMAfzal Najam
12/18/2020, 6:11 AMlen
12/18/2020, 11:18 AMFlowRow
being removed? It felt nice for things like a list of chips. Is a replacement planned? I don't really like the idea of creating a custom layout for it.Raul Portales
12/18/2020, 12:32 PMjava.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/ViewTreeLifecycleOwner
I updated the dependencies to use androidx.lifecycle:lifecycle-common-java8
instead of androidx.lifecycle:lifecycle-compiler
and androidx.lifecycle:lifecycle-common
but the crash is still happening.
Any ideas of what can I be missing?Lilly
12/18/2020, 3:00 PMziv kesten
12/18/2020, 3:15 PMHitanshu Dhawan
12/18/2020, 5:13 PMLazyColumnFor
I’m using alpha08, and I can find methods like LazyListState.snapToItemIndex
but this is without smooth scrolling and the method LazyListState.smoothScrollBy
doesn’t take the index.
How to smooth scroll to a specific index? Does the API exists for this right now?Casey Brooks
12/18/2020, 5:22 PM@Composable
annotation instead of a composable
keyword, and might this change in the future?
Compose goes way past the normal annotation-processing, and the semantics of composable functions seem to follow more closely with the suspend
keyword. And Facebook’s new AI library adds a differentiable fun
keyword so it seems natural that Compose would support a composable fun
keyword as well.Danilo Herrera
12/18/2020, 6:01 PMLilly
12/18/2020, 8:36 PMshimmer
in this channel but the most recent result is from Mai. Maybe the author used another keyword than shimmer
when posted it. Does someone have an idea?3bdoelnaggar
12/18/2020, 9:05 PMlilypuchi
12/19/2020, 6:30 AM1.0.0alpha-09
Since `Dp.VectorConverter` and similar converters have both the deprecated (at compose.animation
) and relocated version (at compose.animation.core
) with the same name, I’m getting the Overload resolution ambiguity error and unable to build ahead. 🤔Lilly
12/19/2020, 2:04 PMval devices = remember { mutableStateListOf<DeviceModel>() }
LaunchedEffect(subject = viewModel.devices, block = {
viewModel.devices.collect { model ->
if (!devices.contains(model)) devices.add(model)
}
})
and
val devices by produceState(initialValue = mutableStateListOf<DeviceModel>(), viewModel) {
viewModel.devices.collect { model ->
if (!value.contains(model)) value.add(model)
}
}
Lilly
12/19/2020, 2:04 PMval devices = remember { mutableStateListOf<DeviceModel>() }
LaunchedEffect(subject = viewModel.devices, block = {
viewModel.devices.collect { model ->
if (!devices.contains(model)) devices.add(model)
}
})
and
val devices by produceState(initialValue = mutableStateListOf<DeviceModel>(), viewModel) {
viewModel.devices.collect { model ->
if (!value.contains(model)) value.add(model)
}
}
allan.conda
12/19/2020, 2:17 PMLilly
12/19/2020, 3:55 PMmutableStateList
?Dominaezzz
12/19/2020, 5:09 PMList<DeviceModel>
for the second case, then they become more comparable.Adam Powell
12/19/2020, 5:12 PMPersistentList
, I think MutableStateList
uses the persistent collections under the hoodDominaezzz
12/19/2020, 5:12 PMLinkedHashSet
.Lilly
12/20/2020, 4:14 AMlinkedSetOf
or mutableListOf
for second snippt, no items are shown which makes sense, because I don't do value = device
so devices
doesn't change but when I use mutableStateListOf
and do value.add(device)
, devices
changed. Or am I wrong? Btw...it seems that PersistentList
doesn't exist, same for MutableStateList
?!Adam Powell
12/20/2020, 4:22 AMvar list = mutableListOf()
- you don't need both the list and the reference to the list to be mutableproduceState
is about that leading var
Lilly
12/20/2020, 4:27 AMis about that leadingproduceState
var
Adam Powell
12/20/2020, 4:30 AMproduceState
is just a convenience around
val state = remember { mutableStateOf(initialValue) }
LaunchedEffect {
state.block()
}
return state
Lilly
12/20/2020, 4:33 AMAdam Powell
12/20/2020, 4:33 AMLilly
12/20/2020, 4:34 AMAdam Powell
12/20/2020, 4:34 AMLilly
12/20/2020, 4:36 AMAdam Powell
12/20/2020, 5:00 AMmutableStateListOf
and mutableStateMapOf
for snapshot-observable collections at the moment, we don't have a set. If you combine PersistentSet
from kotlinx.collections.immutable and produceState
from compose you should have what you needPersistentSet
is an efficient immutable set type that potentially returns a new set instance whenever you add or remove from it, and if you store that reference in a mutableStateOf
holder, you get the observability you need with an efficient immutable set implementationLilly
12/21/2020, 3:56 AMAdam Powell
12/21/2020, 4:01 AMLilly
12/21/2020, 9:43 PMAdam Powell
12/21/2020, 10:42 PMwithMutableSnapshot
. Any changes you make within an explicit mutable snapshot all happen together or not at all, and changes aren't made visible to other threads unless you commit all changes together or otherwise pass the snapshot between threads explicitly.Lilly
12/21/2020, 11:12 PMval devices = remember { mutableStateOf(persistentListOf<DeviceModel>()) }
LaunchedEffect(subject = viewModel.deviceFlow, block = {
viewModel.deviceFlow.collect { model ->
if (!devices.value.contains(model)) {
devices.value = devices.value.add(model)
}
}
})
BluetoothDeviceListComponent(devices.value, onConnectDevice)
What do I wrong? :/Dominaezzz
12/21/2020, 11:15 PMDeviceModel
have an equals
implementation?Lilly
12/21/2020, 11:18 PMdata class DeviceModel(val bluetoothDevice: BluetoothDevice, val rssi: Int)
data classes generate equals functions right?Adam Powell
12/21/2020, 11:20 PMLilly
12/22/2020, 1:03 AMdata class BluetoothDeviceModel(val bluetoothDevice: BluetoothDevice, val rssi: Int) {
override fun equals(other: Any?): Boolean {
if (other is BluetoothDeviceModel) {
return this.bluetoothDevice.address == other.bluetoothDevice.address
}
return false
}
}
Additionally when I want to update the list with newer devices there are multiple options. To preserve the order of the items I came up with this solution:
val devices = remember { mutableStateListOf<DiscoverBluetoothDevicesUseCase.BluetoothDeviceModel>() }
LaunchedEffect(subject = viewModel.deviceFlow, block = {
viewModel.deviceFlow.collect { model ->
withMutableSnapshot {
devices.indexOf(model).takeIf { it != -1 }?.let { i ->
devices.remove(devices[i])
devices.add(i, model)
} ?: devices.add(model)
}
}
})
@Adam Powell Is this implementation legit regarding performance and do I use withMutableSnapshot
properly?Adam Powell
12/22/2020, 1:47 AM