nuhkoca
04/22/2022, 2:34 PMisPageTitleReached
and isContentScrolled
changed, right?
val isPageTitleReached by derivedStateOf {
remember {
lazyListState.firstVisibleItemScrollOffset > 500
}
}
val isContentScrolled by derivedStateOf {
remember {
lazyListState.firstVisibleItemScrollOffset > 600
}
}
myanmarking
04/22/2022, 2:42 PMnuhkoca
04/22/2022, 2:46 PMval highPriorityTasks by remember(highPriorityKeywords) {
derivedStateOf { todoTasks.filter { it.containsWord(highPriorityKeywords) } }
}
myanmarking
04/22/2022, 2:48 PMnuhkoca
04/22/2022, 2:49 PMremember
and derivedStateOf
would work as expected in my example?
@Composable
private fun rememberScrollState(
lazyListState: LazyListState,
firstCondition: Int,
secondCondition: Int
) = remember(firstCondition, secondCondition) {
ScrollState(lazyListState, firstCondition, secondCondition)
}
@Immutable
private data class ScrollState(
val lazyListState: LazyListState,
val firstCondition: Int,
val secondCondition: Int
) {
val isPageTitleReached by derivedStateOf {
if (lazyListState.firstVisibleItemIndex == 0) {
lazyListState.firstVisibleItemScrollOffset > firstCondition
} else {
true
}
}
val isHeroScrolled by derivedStateOf {
if (lazyListState.firstVisibleItemIndex == 0) {
lazyListState.firstVisibleItemScrollOffset > secondCondition
} else {
true
}
}
}
myanmarking
04/22/2022, 5:18 PMnuhkoca
04/22/2022, 5:20 PMMichael Paus
04/22/2022, 5:29 PMmyanmarking
04/22/2022, 5:33 PMTash
04/22/2022, 7:52 PMdata class
has `val`s where nothing is backed by mutable data, it won’t be inferred as immutable unless it is in a module w/ the Compose compiler.
Also if your data class
contains a val list: List<Foo>
the compiler can’t infer stability even if Foo
is stable (there’s an open issue). For that you’d have to explicitly annotate that class with `@Immutable`/`@Stable`. Recently read about this here https://chris.banes.dev/composable-metrics/Michael Paus
04/23/2022, 10:01 AM