chansek
03/17/2022, 11:06 AM@Composable
fun Payment(
price: Double,
onResult: (Int, PaymentResponse) -> Unit
) {
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
onResult(RC_PAY, appNotFoundError ?: handlePaymentResult(it.data))
}
launcher.launch(preparePaymentIntent(price))
}
How do I handle the exception caused by launcher.launch
when there is not Acitivity found to handle the Intent
passed to launch
?Kata
03/17/2022, 1:18 PMPaging
with custom unique keys(UUID) and LazyColumn
I found the following issue:
When I scroll through a bigger list(with 150 elements, paging 30) too fast then the app crashes with:
"Key $slotId was already used. If you are using LazyColumn/Row please make sure you provide a unique key for each item."
Issue is coming from SubcomposeLayout.kt line 353
.
Now if I scroll though the list really slowly then everything works fine.
Once everything is loaded and I scroll through it fast then there is no issue.
Anybody has an idea what could be the issue? Is this maybe a bug inside compose?
What I found is by adjusting the paging size to something smaller the crash happens earlier and when modifying the paging to something bigger than the list itself then the crash is not happening. I tried is with compose version 1.1.0
and also with 1.2.0-alpha05
Slackbot
03/17/2022, 1:19 PMskwalking
03/17/2022, 2:33 PMMohan
03/17/2022, 5:09 PMMohan
03/17/2022, 5:10 PMRobert Menke
03/17/2022, 7:49 PMjonc
03/17/2022, 11:26 PMgraphicsLayer
modifier to an Image
. I need the size of the image respective to content scale in order to implement some customized gestures. I've tried onSizeChanged
and onGloballyPositioned
but those seem to be used for the layouts rather than graphics so it isn't called when transformations are made through graphicsLayer
Lance Gao
03/18/2022, 2:07 AMBox{}
and start with a fade-in animation?Zoltan Demant
03/18/2022, 5:11 AMVERY_BOLD
naming pattern, since compose they (and a lot of other variables) follow a MuchSofterPattern
. Im curious about how you manage any type of consistency between the two in your projects? Personally, I prefer the latter - but refactoring isnt very simple when the old style enums are part of external datasets, json structures, etc. I feel liek Im stuck with UPPER_CASE
and BeautifulCase
(sorry, I couldnt find the actual appropiate names for them) and I rarely know when to use which as a result.Abhilash
03/18/2022, 9:31 AMthelumiereguy
03/18/2022, 10:32 AMFabio
03/18/2022, 1:39 PMTextField
to decimal numbers. I just posted a question on StackOverflow with the full details, but I could also post them here if you prefer. The TL;DR is that even if I do not update my state in response to the onValueChange
callback (or if I just set the previous value and ignore the new one), the text I get in the next onValueChange
still includes the changes I rejected.Bradleycorn
03/18/2022, 3:22 PMAndroidViewBinding
Composable to inflate a FragmentContainerView
with a Fragment and show it within composable “screen”.
So far though, it seems like I have to create a wrapper xml layout resource with a FragmentContainerView
for every fragment. I was hoping to find a way to just define a single xml layout resource (compose_fragment_container.xml) and write a composable that uses it with AndroidViewBinding
to load an arbitrary Fragment. But so far no luck. Anyone know a way to do this? My current (not working) code in the 🧵Marko Novakovic
03/18/2022, 4:07 PMcolintheshots
03/18/2022, 7:47 PMModifier.imePadding
or Modifier.navigationBarsWithImePadding
, the UI elements are scrolled completely offscreen and I’m left with a blank space where they were. I was able to workaround the issue by giving my textfield a weight of 1f and this keeps the buttons onscreen above the keyboard and below the textfield, but I can’t use this on screens with more than one textfield. Are there any alternatives to Modifier.weight(1f) that will work better here?Robert Menke
03/18/2022, 9:56 PMcontentType
parameter for items
that I can understand. Let’s say I have a LazyColumn
where each item is a FooItem
. What am I supposed to be supplying to contentType
?
fun items(
count: Int,
key: ((index: Int) -> Any)? = null,
contentType: (index: Int) -> Any? = { null },
itemContent: @Composable LazyItemScope.(index: Int) -> Unit
) {
error("The method is not implemented")
}
Mjahangiry75
03/19/2022, 8:39 AMBottomSheet
dialog in a screen? just like Dialog
nuhkoca
03/19/2022, 3:33 PMSuccess
and Error
states already work as expected because they aren’t centered on the screen but LoadingView
should be centered instead but it is always placed on top. How do I fix this? Thank you.
...
Scaffold(topBar = topBar) {
Box(
modifier = Modifier
.padding(it)
.verticalScroll(rememberScrollState())
) {
when (collectionState) {
CollectionState.Loading -> LoadingView()
is CollectionState.Success -> {
ScreenView(
collection = collectionState.collection,
onWatchlistItemClick = onWatchlistItemClick,
onDisclaimerTextClicked = onDisclaimerTextClicked
)
}
CollectionState.Error -> ErrorView(onTryAgainClicked = onTryAgainClicked)
}
}
}
...
@Composable
private fun LoadingView() {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}
harry.singh
03/19/2022, 10:23 PMChannel(Channel.BUFFERED)
as a flow in a Composable function but I'm only ever seeing the latest element and missing all of the elements before the latest one. I've added all of the code here.
I debugged collectAsState
and I'm seeing all of the elements in the produceState
composable function but not in my composable function. Any ideas why this might be happening?andrew
03/20/2022, 12:32 AMAndroid75
03/20/2022, 4:39 AMAndroid75
03/20/2022, 6:05 AMAndroid75
03/20/2022, 6:05 AMZach Klippenstein (he/him) [MOD]
03/20/2022, 4:52 PMleadingIcon
work?zt
03/20/2022, 10:55 PMFunkyMuse
03/20/2022, 11:05 PMmcpiroman
03/21/2022, 8:54 AMalthaf
03/21/2022, 10:21 AMclass LoginViewModel : ViewModel() {
val registeredUsers = mutableStateListOf<UIRegisteredUser>()
in the view model
1. Is there way to protect this registeredUsers list from updating the object values from other than view model ? I'm tryting to avoid accidental modification these values from out side view model, trying to keep vm as single source of truth.althaf
03/21/2022, 10:23 AMprivate val _quickLinks = MutableLiveData<List<UIQuickLink>>()
val quickLink: LiveData<List<UIQuickLink>> = _quickLinks
So that, quickLink access are only observed than posted with new values from UI, here update to quickLink happens from only view modelalthaf
03/21/2022, 10:23 AMprivate val _quickLinks = MutableLiveData<List<UIQuickLink>>()
val quickLink: LiveData<List<UIQuickLink>> = _quickLinks
So that, quickLink access are only observed than posted with new values from UI, here update to quickLink happens from only view modelf.babic
03/21/2022, 10:24 AMState
instead of a MutableState
using a second property.
You could also do it with a function instead of a propertyalthaf
03/21/2022, 10:32 AMval _registeredUsers = mutableStateListOf<UIRegisteredUser>()
val registeredUser: State<UIRegisteredUser> = _registeredUsers
val _registeredUsers = mutableStateListOf<UIRegisteredUser>()
val registeredUser: SnapshotStateList<UIRegisteredUser> = _registeredUsers
SnapshotStateList
Is mutable 😕f.babic
03/21/2022, 10:36 AMmutableStateListOf
instead of mutableStateOf
?
We're using the latter in our code and seems to work fine, haven't had issues per se.althaf
03/21/2022, 10:50 AMprivate val _registeredUsers = mutableStateOf<List<UIRegisteredUser>>(value = listOf())
val registeredUser: State<List<UIRegisteredUser>> = _registeredUsers
This above appears to work , however following use case we are not able to accomplish with above approach, where as with mutableStateListOf() these worked fine, however, object became insecure
init {
_registeredUsers.value.toMutableStateList().addAll(mockRegisteredUsers)
}
fun onUserSelected(user: UIRegisteredUser) {
viewModelScope.coroutineContext.run {
_registeredUsers.value.toMutableStateList().let { userList ->
userList.find { it.isSelected }?.let {
userList.indexOf(it).also { index ->
userList.remove(it)
userList.add(index, it.copy(isSelected = false))
}
}
userList.find { it == user }?.let {
userList.indexOf(it).also { index ->
userList.remove(it)
userList.add(index, it.copy(isSelected = true))
}
}
}
}
}
f.babic
03/21/2022, 10:55 AM_registeredUsers.value.toMutableStateList().addAll(mockRegisteredUsers)
You could have:
_registeredUsers.value = _registeredUsers.value + mockRegisteredUsers
Basically, instead of havign a mutable list that can be changed anywhere, you use immutable lists but make sure to add/remove items from the given list and producing a new list instead.
That gives you control in the ViewModel of whatever you want to do, but the rest of the world won't be able to mutate incorrectlyalthaf
03/21/2022, 10:57 AMprivate val _registeredUsers = mutableStateOf<ArrayList<UIRegisteredUser>>(value = arrayListOf())
val registeredUsers: State<List<UIRegisteredUser>> = _registeredUsers
fun onUserSelected(user: UIRegisteredUser) {
viewModelScope.coroutineContext.run {
_registeredUsers.value.let { userList ->
userList.find { it.isSelected }?.let {
userList.indexOf(it).also { index ->
userList.remove(it)
userList.add(index, it.copy(isSelected = false))
}
}
userList.find { it == user }?.let {
userList.indexOf(it).also { index ->
userList.remove(it)
userList.add(index, it.copy(isSelected = true))
}
}
}
}
}
f.babic
03/21/2022, 11:00 AM_registeredUsers.value = newValue
when you mutate the list within those find
calls, you need to make sure to push the new state to the UIalthaf
03/21/2022, 11:09 AMSelectLoginUsersScreenContent(registeredUsers = loginViewModel.registeredUsers.value, onUserSelected = onUserSelected)
fun onUserSelected(user: UIRegisteredUser) {
viewModelScope.coroutineContext.run {
_registeredUsers.value.let { userList ->
userList.find { it.isSelected }?.let {
userList.indexOf(it).also { index ->
userList.remove(it)
userList.add(index, it.copy(isSelected = false))
}
}
userList.find { it == user }?.let {
userList.indexOf(it).also { index ->
userList.remove(it)
userList.add(index, it.copy(isSelected = true))
}
}
_registeredUsers.value = userList
}
}
}
f.babic
03/21/2022, 11:19 AMval registeredUsers by loginViewModel.registeredUsers
SelectLoginUsersScreenContent(registeredUsers = registeredUsers, onUserSelected = onUserSelected)
Basically the way we expose state in our VMs is the following:
private var threadMessagesState: MessagesState by mutableStateOf(MessagesState())
And then we just fetch it using an exposed property or somethingalthaf
03/21/2022, 11:31 AMval registeredUsers by loginViewModel.registeredUsers
SelectLoginUsersScreenContent(
registeredUsers = registeredUsers,
onUserSelected = onUserSelected
)
😭 didnt work @f.babicAlbert Chang
03/21/2022, 11:42 AMprivate val _registeredUsers = mutableStateListOf<UIRegisteredUser>()
val registeredUsers: List<UIRegisteredUser> = _registeredUsers
althaf
03/21/2022, 11:44 AMAlbert Chang
03/21/2022, 11:45 AMalthaf
03/21/2022, 11:48 AMprivate val _registeredUsers = mutableStateListOf<UIRegisteredUser>()
val registeredUsers: List<UIRegisteredUser> = _registeredUsers