Yariv Ziporin
01/02/2023, 4:28 PMrobercoding
01/02/2023, 5:23 PMTravis Griggs
01/02/2023, 7:01 PMnuhkoca
01/02/2023, 7:47 PMViewModel
in text click and subscribe the output in composable function as follows;
val url by viewModel.output.url.subscribeAsState(initial = null)
However, since the url is always the same string, only the first click opens browser, subsequent ones don’t do anything due to subscribeAsState
How do I make this work properly for identical strings?ursus
01/02/2023, 10:27 PMImage
to be never skipped?
Image(
modifier = Modifier
.size(48.dp)
.padding(12.dp),
painter = painterResource(id = R.drawable.ic_headphones),
contentDescription = null,
)
I’m looking around in Layout monitor and I see this never skipped when ui is recomposedritesh
01/03/2023, 9:05 AMLazy
- What if i don't have a unique key for my model and i know that List<>
data set positions won't be re-arranged but only new data-set will be appended, i can live without giving unique keys (without going into the path of generating some unique keys - like UUID for each item) to it i believe or there's a trade-off?Rafs
01/03/2023, 9:53 AMLaunchedEffect
from my composable is getting called before onDispose
of the destination navigation composable’s DisposableEffect
Brais Gabin
01/03/2023, 11:09 AMList<@Composable () -> Unit>
. And I want to display it in a LazyColumn
with a Space
between each of them.
LazyColumn {
items(list) { composable ->
composable.invoke()
Space(height = 4.dp)
}
}
The problem is that some of them can emit nothing to the tree. That means that visually I get double Space
between some components. How would you avoid this problem? Those functions that emit nothing could start emitting at any point if their state change.FunkyMuse
01/03/2023, 11:55 AMandroid.intent.action.SEND
With compose navigation component?
I want to open a nested navigation destination that accepts a uri which is basically a string encoded when passing the argument and decoding when reading itKotlinLeaner
01/03/2023, 12:09 PMMutableSet
with mutableStateListOf
?
val list by lazy { mutableStateListOf<ScanResult>() }
Many Thanksdorche
01/03/2023, 2:50 PMhandleDeepLink
, back stack seems gone so now the when the user presses back after the payment flow confusingly that closes the app.Hasan Nagizade
01/03/2023, 4:45 PMval focusManager = LocalFocusManager.current
focusManager.clearFocus()
this code removes the focus from InputField
and closes the keyboard. How can I close the keyboard but keep focus on InputField
?Norbi
01/03/2023, 8:11 PMRick Regan
01/03/2023, 8:26 PMCrossfade
is leaking its state holder. I have a Slider that I can interact with normally (no crossfades) but that will crossfade to its default value when a “reset” Button is pressed. I do this using a MutableState within a MutableState, the outer one being the target for Crossfade, and the inner one being the slider value (code in 🧵.)
In the heap dump (after forcing garbage collection) I can see that the number of allocated SliderStateHolder/SliderState objects increases with each reset. Inasmuch as I understand heap dumps, the references look like they’re coming from “SnapshotStateList”, which would seem to indicate Compose continues to track the old states. I’d like to understand why (and what I could do to prevent it). Thanks.John O'Reilly
01/03/2023, 10:21 PMAaron Waller
01/04/2023, 7:25 AMShakil Karim
01/04/2023, 10:42 AMShakil Karim
01/04/2023, 10:47 AMelye
01/04/2023, 11:26 AMclass AppViewModel : ViewModel() {
private var todoList = listOf(
TodoItem(0, "My First Task"),
TodoItem(1, "My Second Task", true)
)
private val _todoListFlow = MutableStateFlow(todoList)
val todoListFlow: StateFlow<List<TodoItem>> get() = _todoListFlow
fun setUrgent(index: Int, value: Boolean) {
val modified = todoList.toMutableList()
modified[index] = modified[index].copy(urgent = value)
todoList = modified
_todoListFlow.value = modified
}
}
val viewModel = AppViewModel()
@Composable
fun MyTodoList {
val todoListState = viewModel.todoListFlow.collectAsState()
LazyColumn(modifier = Modifier.fillMaxHeight()) {
items(items = todoListState.value, itemContent = { item ->
Row {
Text(text = item.title)
Checkbox(
checked = item.urgent,
onCheckedChange = {
val index = todoListState.value.indexOf(item)
viewModel.setUrgent(index, it)
}
)
}
})
}
}
But I dislike to update a field in the list, I have to create a modify list to pass to the stateFlow.
fun setUrgent(index: Int, value: Boolean) {
val modified = todoList.toMutableList()
modified[index] = modified[index].copy(urgent = value)
todoList = modified
_todoListFlow.value = modified
}
I can fix it using Solution in https://stackoverflow.com/a/75004437/3286489, but feel it is wrong, as that solution is having MutableState in ViewModel.
I wonder how can I avoid the need to create the entire list to send through the StateFlow, if I just need to change a variable that update the compose view?oday
01/04/2023, 12:00 PMobject TestTags {
const val eventsListTag = "Events List"
const val errorPromptTag = "Error Prompt"
const val emptyPromptTag = "Empty Prompt"
}
how do you do this?Hasan Nagizade
01/04/2023, 12:37 PMonFocusChanged
is not getting triggered every time user clicks on InputField
? how to make InputField
get focus every time user clicks on it?elye
01/04/2023, 1:05 PMmyanmarking
01/04/2023, 1:33 PMElio Maroun
01/04/2023, 2:55 PMAloneWalker
01/04/2023, 3:17 PMiroyo
01/04/2023, 4:16 PMonGloballyPositioned
on the Image
modifier to get the size and then set a global variable of an Interceptor.. What I have is something like:
Image(
painter = painter,
modifier = modifier.onGloballyPositioned {
coilInterceptor.config.params[PARAM_WIDTH] = it.size.width.toString()
},
where: coilInterceptor is a singleton Interceptor…. I’m trying to avoid this. I much rather prefer passing to the ImageRequest
directly the url with the size concatenatedLandry Norris
01/04/2023, 6:00 PMvar orientation by remember { mutableStateOf(Configuration.ORIENTATION_PORTRAIT) }
val config = LocalConfiguration.current
LaunchedEffect(config) {
// Save any changes to the orientation value on the configuration object
snapshotFlow { config.orientation }
.collect { orientation = it }
}
Andy Himberger
01/04/2023, 8:09 PMZach Klippenstein (he/him) [MOD]
01/04/2023, 9:30 PMalp
01/04/2023, 11:18 PMandroidx.swiperefreshlayout.widget.SwipeRefreshLayout
?
There are examples here with a fix using Modifier.nestedScroll(rememberNestedScrollInteropConnection())
for bottom sheet but it seems like it doesn’t work with hierarchy like:
<SwipeRefreshLayout>
<ComposeView>
</SwipeRefreshLayout>
scrolling up immediately triggers the swipe refresh.alp
01/04/2023, 11:18 PMandroidx.swiperefreshlayout.widget.SwipeRefreshLayout
?
There are examples here with a fix using Modifier.nestedScroll(rememberNestedScrollInteropConnection())
for bottom sheet but it seems like it doesn’t work with hierarchy like:
<SwipeRefreshLayout>
<ComposeView>
</SwipeRefreshLayout>
scrolling up immediately triggers the swipe refresh.ephemient
01/04/2023, 11:28 PMSwipeRefreshLayout
is a NestedScrollingParent3
like CoordinatorLayout
)val state = rememberLazyListState()
LaunchedEffect(listState) {
swipeRefreshLayout.setOnChildScrollUpCallback { _, _ -> listState.firstVisibleItemScrollOffset > 0 }
}
LazyColumn(state = state, ...)
alp
01/05/2023, 12:35 AMNestedScrollingParent3
ViewGroups CoordinatorLayout
for example?
In more real-world complex scenario, such as when compose code is encapsulated within a fragment, there is not way to propagate SwipeRefreshLayout
reference to the compose code, as far as I understand, NestedScrollingParent3
abstraction should solve this issueephemient
01/05/2023, 1:45 AMSwipeRefreshLayout
is a NestedScrollingParent3
, but ComposeView
is not a NestedScrollingChild3
alp
01/05/2023, 1:50 AMNestedScrollInteropConnection
makes it a NestedScrollingChild3
ephemient
01/05/2023, 1:54 AMComposeView
is returning false from canScrollVertically
before a gesture starts, it seemsSwipeRefreshLayout
doesn't delegate a pull down into ComposeView
, but if you pull even a little bit first then it all worksalp
01/05/2023, 1:57 AMephemient
01/05/2023, 1:59 AMalp
01/05/2023, 1:59 AM