Adrian Tappe
11/01/2021, 5:03 PMSwipeToDismiss
state when navigating back and forth between screens.
I would like to reset
(suspend function) the dismissState
as part of a cleanup. (Or “forget” that state when navigating back to this screen)
Idea:
When the user swipes out a Card in a LazyList the card stays in the swiped out state while a SnackBar appears.
If the snackbar gets dismissed, the element is deleted via the viewModel.
If the snackbar action (Undo) gets pressed, the dismissState gets reset.
Problem:
If I navigate to another screen, the coroutineScope the snackbar is opened gets cancelled.
The dismissState will never be reset. When I navigate back to this screen, the swiped card will stay swiped.
I tried but failed:
A) Have a finally
block in the coroutine to do the cleanup.
B) Having a DisposableEffect
seems to not work as I cannot access the compose state and have no coroutine scope.
Sourcecode:
edit: in thread
Mjahangiry75
11/01/2021, 6:42 PMAfzal Najam
11/01/2021, 9:15 PMverticalScroll
modifier?
For example in the Bloom AndroidDevChallenge app home screen.Andy Himberger
11/02/2021, 12:29 AM@Composable
fun loadNetworkImage(
url: String,
imageRepository: ImageRepository
): State<Result<Image>> {
// Creates a State<T> with Result.Loading as initial value
// If either `url` or `imageRepository` changes, the running producer
// will cancel and will be re-launched with the new keys.
return produceState(initialValue = Result.Loading, url, imageRepository) {
itnoles
11/02/2021, 2:58 AMAlexander Suraphel
11/02/2021, 2:04 PMScott Kruse
11/02/2021, 2:51 PMSteffen Funke
11/02/2021, 4:04 PMderivedStateOf
be the State-equivalent of combine
in Flow / Rx-World? Meaning, if one of the inputs change, the resulting state should be recalculated? And can this also safely be used inside a ViewModel?
Background: I have e.g. a list and a search bar, and using MutableStateFlows
inside my ViewModel for data streams. Whenever the search term changes, I combine
the search term with the list, to filter it.
Works well and solid, but I think about going full Compose also in my ViewModels, therefore replacing my MutableStateFlow
s with Compose States.
Is this the correct approach, using derivedStateOf
?James Harman
11/02/2021, 4:08 PMnglauber
11/02/2021, 5:27 PMBringIntoViewRequester
works in the following situation:
1. TextField
is at the bottom of the screen and the user tap on it and it gain focus.
2. System keyboard is displayed and the TextField
becoming visible because of the following:
Modifier.bringIntoViewRequester(bringIntoViewRequester)
.onFocusChanged {
if (it.isFocused) {
coroutineScope.launch {
delay(300)
bringIntoViewRequester.bringIntoView()
}
}
}
3. The user now press the system back key and the keyboard is closed, but the TextField
still has focus.
4. Finally, if the user tap on the TextField
again. The keyboard is opened on top of the TextField
and the BringIntoViewRequester
is not triggered again because the focus haven’t changed.
I know there’s a ticket kinda related to this…
https://issuetracker.google.com/u/0/issues/192043120
Any suggestion?Colton Idle
11/02/2021, 11:19 PMBrush.linearGradient(listOf()))
My designer keeps giving me stuff like this 😅
background: linear-gradient(180deg, rgba(5, 64, 87, 0.5)
and background: linear-gradient(215.31deg, rgba(255, 255, 255, 0.1)
miqbaldc
11/03/2021, 1:50 AMHashSet
as remember { mutableStateOf(hashSetOf()) }
See video & snippet code in 🧵Colton Idle
11/03/2021, 1:51 AMJohn Aoussou
11/03/2021, 2:42 AMGumiku
11/03/2021, 5:51 AMval name: String? = null
name?.let {
Box() {
}
} ?: println("hello")
Colton Idle
11/03/2021, 6:03 AMAdib Faramarzi
11/03/2021, 6:35 AMsetContent
seems to be drawing too much CPU time. Is it natural?Bagadeshkumar R
11/03/2021, 6:40 AMSteffen Funke
11/03/2021, 7:23 AMYASAN
11/03/2021, 8:20 AMDefault FirebaseApp is not initialized in this process com.livingmaples.videoplayer.test. Make sure to call FirebaseApp.initializeApp(Context) first.
Steffen Funke
11/03/2021, 10:15 AM.dp
, RoundedCornerShape
,, etc. in some global space?
// some global .kt file
val cornerShape = RoundedCornerShape(3.dp)
val imageSizeLarge = 120.dp
...
Or does the Compose compiler take care of it, and we are free to reuse those same values all over the place?
Or are they so cheap to create that it is even encouraged to write them out each time?Sololo
11/03/2021, 12:52 PMprivate class PreviewUserInfoProvider : PreviewParameterProvider<UserInfoBean> {
override val values: Sequence<UserInfoBean>
get() = sequenceOf(UserInfoBean("111", "111", ""))
}
@Preview(
name = "user info layout",
group = "node",
showBackground = true,
backgroundColor = 0xffffff
)
@Composable
fun PreviewUserInfo(@PreviewParameter(PreviewUserInfoProvider::class) info: UserInfoBean) {
// UserInfoView(
// modifier = Modifier.size(120.dp, 30.dp),
// userInfoBean = info,
// onUserClick = {})
Text(text = info.nickName)
}
why it cannot be preview shown?natario1
11/03/2021, 1:29 PMclass Obj(val id: Int) {
@Composable fun id() = remember { id }
}
// later ...
var obj by remember { mutableStateOf(Obj(0)) }
LaunchedEffect(obj) {
delay(1000)
obj = Obj(obj.id + 1)
}
require(obj.id == obj.id())
I understand what's happening and I know how to solve it (use remember(this)
in Obj, or key
) but I wonder if this is how it should be. Wouldn't it be desirable that the compiler recognizes obj
as part of the remember call stack? Since id()
is a member function, it's pretty clear that if the object changes, the old remember should be invalidated.AmrJyniat
11/03/2021, 2:26 PMwindowSoftInputMode="adjustResize"
in manifest because this push all the content not just the FAB?Mehdi Haghgoo
11/03/2021, 2:42 PMAdam Powell
11/03/2021, 3:10 PMRick Regan
11/03/2021, 3:47 PMBoxWithConstraints
does not look like the right tool for that. For example, on a Pixel 4A, BoxWithConstraints
(at the top level, not within a Scaffold
) will give maxWidth
392.dp and maxHeight
785.dp in portrait, and maxWidth
801.dp and maxHeight
348.dp in landscape. I'd like to know that 801.dp is the max, even if the app starts in portrait. Is there a way to do that?
| Edit: Rationale in thread.rudolf.hladik
11/03/2021, 7:57 PMstickyHeaders
in LazyColumn
? I mean, I need a behaviour that e.g. 3 stickyHeaders all stick to top, not overlapping and not exchanging one-anotherJohn O'Reilly
11/03/2021, 9:06 PMImage
composable when using new Glance
API to create app wdiget?Alex C
11/04/2021, 12:03 AMval testData = listOf("item1", "item2", "item3")
composeTestRule.setContent {
LazyColumn(Modifier.testTag(TEST_TAG)) {
itemsIndexed(testData) { index, item ->
Row {
Text("index $index: ")
Spacer(modifier = Modifier.height(10.dp))
Text(item)
}
}
}
}
composeTestRule.onNodeWithTag(TEST_TAG).onChildren().assertCountEquals(3)
It turns out the actual count of the children is 6 rather than 3, which counts the Text("index $index: ")
and Text(item)
inside the Row but not the Spacer()
But what I actually want is to count how many rows in the LazyColumn.
So how can I do it?Alex C
11/04/2021, 12:03 AMval testData = listOf("item1", "item2", "item3")
composeTestRule.setContent {
LazyColumn(Modifier.testTag(TEST_TAG)) {
itemsIndexed(testData) { index, item ->
Row {
Text("index $index: ")
Spacer(modifier = Modifier.height(10.dp))
Text(item)
}
}
}
}
composeTestRule.onNodeWithTag(TEST_TAG).onChildren().assertCountEquals(3)
It turns out the actual count of the children is 6 rather than 3, which counts the Text("index $index: ")
and Text(item)
inside the Row but not the Spacer()
But what I actually want is to count how many rows in the LazyColumn.
So how can I do it?John Nichol
11/05/2021, 3:23 PM