Kshitij Patil
01/06/2021, 8:14 AMTextField
pre-focused when a Composable is loaded for the first time?gpaligot
01/06/2021, 8:16 AMfun myFunc(input: Input) = flow {
myDao.get().collect {
it.forEach {
emit(it.data)
delay(it.delayTime)
}
}
}
In my composable, I have something like this:
@Composable
fun MyComposable(input: Input) {
val myViewModel: MyViewModel = viewModel()
val data = myViewModel.myFunc(input).collectAsState()
AnotherComposable(data = data.value)
}
The issue is: When I emit new data from my flow, compose collect the data and recompose itself because the state has been updated but due to this recomposition, it recall myFunc
function, cancel the previous execution of the flow, collect data from database, emit values and loop a long time like this.
How can I change my code to avoid this loop? There is any good practice for my usecase?
Thanks in advance!TheMrCodes
01/06/2021, 11:32 AMVitor Prado
01/06/2021, 2:01 PMMehdi Haghgoo
01/06/2021, 5:07 PMJakub Ledwon
01/06/2021, 6:45 PMLogan Knight
01/06/2021, 7:36 PMKshitij Patil
01/06/2021, 7:53 PMPiotr
01/06/2021, 8:32 PMNurseyit Tursunkulov
01/07/2021, 2:28 AMNurseyit Tursunkulov
01/07/2021, 10:03 AMSe7eN
01/07/2021, 1:17 PM@Composable
fun Main() {
val state = remember { PaletteState(...) }
Scaffold(
topBar = { TopBar(onSave = { viewModel.save(state.toPalette()) } }
) {
ColorWheel(state)
}
}
@Composable
fun ColorWheel(state: PaletteState) {
val colorWheel = rememeber { ColorWheel(...) }
state.colors = colorWheel.getColors()
Content(colorWheel)
}
I have a state
that needs to be updated by a child composable. Is this the right way to do it?Mehdi Haghgoo
01/07/2021, 1:45 PMalorma
01/07/2021, 2:26 PM@nosferatu95
partHalil Ozercan
01/07/2021, 2:57 PMHomePage
composable receives a HomeViewModel
and a HomeState
object (caller passes state.value
) as its arguments.
HomePage
also hosts a NavHost which includes 2 different routes(SettingsPage
, ProfilePage
) When I pass a field from HomeState like homeState.username
to one of the composables defined in NavHost, it does not work. State changes do not reflect on children pages of HomePage
.
However, carrying homeViewModel
and homeState
directly into HomePage
composable, fixes this issue.alorma
01/07/2021, 3:23 PMtylerwilson
01/07/2021, 4:44 PMbuszi0809
01/07/2021, 5:43 PMMarcin Środa
01/07/2021, 6:04 PMvectorResource
is showing empty imageShakil Karim
01/07/2021, 7:01 PMThomas
01/07/2021, 9:05 PMscaffoldState.snackbarHostState.showSnackbar
you can only set a String, but I would like to set a Text so I can style the text using annotated string builder. When just including a Snackbar without using Scaffold it appears at the top of the screen, which is not what I want (I would like it at the bottom how it is supposed to be). Looks like the Scaffold/SnackbarHost is setting the correct positions.Chethan
01/08/2021, 6:01 AMSe7eN
01/08/2021, 11:04 AMSnapshotStateList<SnapshotStateList<MyObject>>
as a state but when I change it, the composables aren't getting recomposed. However, if I wrap it with a mutable state MutableState<SnapshotStateList<SnapshotStateList<MyObject>>
it's working fine. Is this intended?
data class MyStateHolder(
val name: MutableState<String>,
val list: SnapshotStateList<SnapshotStateList<MyObject>>
)
var state = remember { MyStateHolder(...) }
...
MyComposable(onSomeEvent = { newList -> state = state.copy(list = newList) })
SomeOtherComposable(state.list) // not getting recomposed when I change state with a new list
I'm not sure but I think it works fine if I just change an item of the list as opposed to copying the whole state for a new list.
This works fine:
data class MyStateHolder(
val name: MutableState<String>,
val list: MutableState<SnapshotStateList<SnapshotStateList<MyObject>>>
)
val state = remember { MyStateHolder(...) }
...
MyComposable(onSomeEvent = { newList -> state.list = newList })
SomeOtherComposable(state.list)
aiidziis
01/08/2021, 2:33 PMAndroidView(
viewBlock = ::WebView,
modifier = Modifier.fillMaxSize()
) { webView ->
with(webView) {
settings.javaScriptEnabled = true
webViewClient = WebViewClient()
loadUrl("<https://google.com>")
}
}
alorma
01/08/2021, 4:12 PMNavHost(
navController = navController,
startDestination = "splash"
) {
composable(Navigation.ROUTE_SPLASH) { InitScreen(navController) }
composable(Navigation.ROUTE_LOGIN) { LoginScreen(navController) }
composable(Navigation.ROUTE_USER) { UserScreen(navController) }
composable(Navigation.ROUTE_GO_WALK) { GoWalkScreen(navController) }
}
From splash I navigate to login or user..., but when I hit the back button of the devices it goes again to splash.
How can avoid that, and if I'm at login, or User close the app when back button is hitbuszi0809
01/08/2021, 4:24 PMorangy
01/08/2021, 5:11 PMLazyVerticalGrid
works internally. I want to implement LazyTileMap
(a big table of cells into which one looks through a small viewport, I need it for a game-like experience) which would only compose tiles that are visible and will allow scrolling and (optionally) zooming. But I’m currently lost in all these layout stuff, subcomposition, measurements, etc. What is the best guide into this? I’ve read Custom layouts section, but it seems it’s a tiny fraction of the underlying machinery.orangy
01/08/2021, 6:20 PMLayout
composable function has content
parameter first and not last, so it would allow for container-like invocation?Cyril Find
01/08/2021, 6:47 PMRafs
01/08/2021, 9:25 PMModifier
.offset(x = { offset.x }, y = { offset.y })
has been removed from alpha09
Rafs
01/08/2021, 9:25 PMModifier
.offset(x = { offset.x }, y = { offset.y })
has been removed from alpha09
Luke
01/08/2021, 9:51 PMPlease use offset with lambda parameters insteadbut it's not in the library
Rafs
01/08/2021, 9:58 PMAdam Powell
01/08/2021, 10:02 PMModifier.offset { IntOffset(...) }
replaceWith
on the old method was staleRafs
01/08/2021, 10:39 PMvar boxPosition by remember { mutableStateOf(Offset.Zero) }
Box(
modifier = Modifier
.fillMaxSize()
) {
Box(
modifier = Modifier
.dragGestureFilter(dragObserver = object : DragObserver {
override fun onDrag(dragDistance: Offset): Offset {
boxPosition += dragDistance
return dragDistance
}
})
.offset {
IntOffset(boxPosition.x.toInt(), boxPosition.y.toInt())
}
.background(color = Color.Black)
.preferredSize(100.dp)
)
}
Thx. In this code snippet, the drag observer rarely get's called. It was working fine on alpha08 @Adam PowellAdam Powell
01/08/2021, 10:42 PM