Nathan Castlehow
07/23/2021, 4:59 AMNathan Castlehow
07/23/2021, 4:59 AMNathan Castlehow
07/23/2021, 4:59 AMIan Lake
07/23/2021, 5:37 AMkey
parameter on items
to denote what the stable and unique key is for each item? https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/package-summary#(androidx.compose.founda[…]nction1,kotlin.Function2)Nathan Castlehow
07/23/2021, 6:27 AMNathan Castlehow
07/23/2021, 6:27 AM@Composable
fun AScreen() {
val listState = rememberLazyListState()
Column(
Modifier
.fillMaxSize()
) {
Box(Modifier.fillMaxWidth()) {
val offset by remember {
derivedStateOf {
// custom calc function that works out offset based on first index etc
listState.scrollOffsetPercent(0.2f)
}
}
Text(
"some title",
modifier = Modifier
.align(Alignment.Center)
.padding(horizontal = 64.dp),
color = lerp(
Color.Transparent,
Color.Red,
offset
),
)
}
Column(Modifier.padding(horizontal = 16.dp)) {
LazyColumn(
modifier = Modifier,
state = listState,
contentPadding = PaddingValues(bottom = 136.dp)
) {
// items that recompose whilst offset isn't stable
}
}
}
}
Nathan Castlehow
07/23/2021, 6:30 AMNathan Castlehow
07/26/2021, 3:53 AM@Composable
fun ScreenAParent() {
val listState = rememberLazyListState()
ScreenA(
header = {
val offset by remember {
derivedStateOf {
// custom calc function that works out offset based on first index etc
listState.scrollOffsetPercent(0.2f)
}
}
ScreenAHeader(offset)
},
listState = listState
)
}
@Composable
fun ScreenA(
header: @Composable () -> Unit,
listState: LazyListState
) {
header()
LazyColumn(
modifier = Modifier,
state = listState,
) {
//items no longer recompose when offset changes
}
}