Skip to content

Commit 14f8771

Browse files
committed
fix(compose): add contentType to heterogeneous lazy lists
Enables Compose to reuse compositions only between items of the same type, improving scroll performance in mixed-content lists. - UserProfileScreenContent: section_header, profile_value, contact_method, empty_state, social_account - UserFlagsEditor: section_header, read_only_row, editable_row - LabsScreenContent: section_header, feature_flag, empty_state, list_item - TokenList: empty_state, header, token_row, reserves, footer
1 parent 7236f31 commit 14f8771

4 files changed

Lines changed: 26 additions & 23 deletions

File tree

apps/flipcash/features/lab/src/main/kotlin/com/flipcash/app/lab/internal/LabsScreenContent.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel) {
5555
).sheetResignmentBehavior(state),
5656
contentPadding = PaddingValues(bottom = CodeTheme.dimens.grid.x3),
5757
) {
58-
item {
58+
item(contentType = "section_header") {
5959
SectionHeader(stringResource(R.string.title_settingsSectionFeatures))
6060
}
61-
items(betaFlags, key = { it.flag.key }) { feature ->
61+
items(betaFlags, key = { it.flag.key }, contentType = { "feature_flag" }) { feature ->
6262
if (feature.flag.isOptionFlag) {
6363
SettingsOptionRow(
6464
title = feature.flag.title,
@@ -87,7 +87,7 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel) {
8787
}
8888

8989
if (betaFlags.isEmpty()) {
90-
item {
90+
item(contentType = "empty_state") {
9191
Box {
9292
Column(
9393
modifier = Modifier.align(Alignment.Center),
@@ -113,8 +113,8 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel) {
113113
}
114114
}
115115

116-
item { SectionHeader(stringResource(R.string.title_settingsSectionHomeScreen)) }
117-
item {
116+
item(contentType = "section_header") { SectionHeader(stringResource(R.string.title_settingsSectionHomeScreen)) }
117+
item(contentType = "list_item") {
118118
ListItem(
119119
headline = stringResource(R.string.title_settingsButtonOrder),
120120
icon = painterResource(R.drawable.ic_bottom_navigation),
@@ -124,8 +124,8 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel) {
124124
}
125125

126126
if (isStaff) {
127-
item { SectionHeader(stringResource(R.string.title_settingsSectionDeveloper)) }
128-
item {
127+
item(contentType = "section_header") { SectionHeader(stringResource(R.string.title_settingsSectionDeveloper)) }
128+
item(contentType = "list_item") {
129129
ListItem(
130130
headline = stringResource(R.string.subtitle_settingsUserFlags),
131131
icon = rememberVectorPainter(Icons.Default.Token),

apps/flipcash/features/myaccount/src/main/kotlin/com/flipcash/app/myaccount/internal/UserProfileScreenContent.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ internal fun UserProfileScreenContent(
3232
) {
3333
LazyColumn(modifier = Modifier.fillMaxSize()) {
3434
// Display Name section
35-
item { SectionHeader(stringResource(R.string.title_sectionDisplayName)) }
36-
item {
35+
item(contentType = "section_header") { SectionHeader(stringResource(R.string.title_sectionDisplayName)) }
36+
item(contentType = "profile_value") {
3737
val name = state.displayName
3838
if (!name.isNullOrEmpty()) {
3939
ProfileValueRow(value = name)
@@ -51,8 +51,8 @@ internal fun UserProfileScreenContent(
5151
}
5252

5353
// Phone section
54-
item { SectionHeader(stringResource(R.string.title_sectionPhone)) }
55-
item {
54+
item(contentType = "section_header") { SectionHeader(stringResource(R.string.title_sectionPhone)) }
55+
item(contentType = "contact_method") {
5656
if (state.phoneNumber != null) {
5757
ContactMethodRow(
5858
value = state.phoneNumber,
@@ -71,8 +71,8 @@ internal fun UserProfileScreenContent(
7171
}
7272

7373
// Email section
74-
item { SectionHeader(stringResource(R.string.title_sectionEmail)) }
75-
item {
74+
item(contentType = "section_header") { SectionHeader(stringResource(R.string.title_sectionEmail)) }
75+
item(contentType = "contact_method") {
7676
if (state.emailAddress != null) {
7777
ContactMethodRow(
7878
value = state.emailAddress,
@@ -89,9 +89,9 @@ internal fun UserProfileScreenContent(
8989
}
9090

9191
// Social Accounts section
92-
item { SectionHeader(stringResource(R.string.title_sectionSocialAccounts)) }
92+
item(contentType = "section_header") { SectionHeader(stringResource(R.string.title_sectionSocialAccounts)) }
9393
if (state.socialAccounts.isEmpty()) {
94-
item {
94+
item(contentType = "empty_state") {
9595
Text(
9696
text = stringResource(R.string.subtitle_noSocialAccounts),
9797
style = CodeTheme.typography.textMedium,
@@ -103,7 +103,7 @@ internal fun UserProfileScreenContent(
103103
)
104104
}
105105
} else {
106-
items(state.socialAccounts, key = { (it as? SocialAccount.TwitterX)?.id ?: it }) { account ->
106+
items(state.socialAccounts, key = { (it as? SocialAccount.TwitterX)?.id ?: it }, contentType = { "social_account" }) { account ->
107107
when (account) {
108108
is SocialAccount.TwitterX -> SocialAccountRow(
109109
account = account,

apps/flipcash/features/userflags/src/main/kotlin/com/flipcash/app/userflags/internal/UserFlagsEditor.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,21 @@ private fun UserFlagsEditor(
7474
contentPadding = PaddingValues(bottom = CodeTheme.dimens.grid.x3),
7575
) {
7676
// Read-only section
77-
item { SectionHeader("Read-Only") }
77+
item(contentType = "section_header") { SectionHeader("Read-Only") }
7878
items(
7979
items = state.readOnlyEntries,
8080
key = { it.label },
81+
contentType = { "read_only_row" },
8182
) { entry ->
8283
ReadOnlyRow(entry)
8384
}
8485

8586
// Editable section
86-
item { SectionHeader("Overridable") }
87+
item(contentType = "section_header") { SectionHeader("Overridable") }
8788
items(
8889
items = state.editableEntries,
8990
key = { it.field.label },
91+
contentType = { "editable_row" },
9092
) { entry ->
9193
EditableRow(
9294
modifier = Modifier.fillMaxWidth(),

apps/flipcash/shared/tokens/src/main/kotlin/com/flipcash/app/tokens/ui/TokenList.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,19 @@ fun TokenList(
8282
state = listState
8383
) {
8484
if (tokens != null && tokens.isEmpty() && emptyState != null) {
85-
item {
85+
item(contentType = "empty_state") {
8686
emptyState()
8787
}
8888
} else {
8989
header?.let { content ->
90-
item {
90+
item(contentType = "header") {
9191
content()
9292
}
9393
}
9494
items(
9595
items = filteredTokens.orEmpty(),
96-
key = { item -> item.token.address.base58() }) { item ->
96+
key = { item -> item.token.address.base58() },
97+
contentType = { "token_row" }) { item ->
9798
TokenBalanceRow(
9899
modifier = Modifier
99100
.fillParentMaxWidth()
@@ -113,7 +114,7 @@ fun TokenList(
113114
Fiat(0.0, cashReserves.rate.currency)
114115
)
115116
) {
116-
item {
117+
item(contentType = "reserves") {
117118
it(Mint.usdf, cashReserves)
118119
HorizontalDivider(
119120
modifier = Modifier.padding(bottom = CodeTheme.dimens.inset),
@@ -124,7 +125,7 @@ fun TokenList(
124125
}
125126

126127
footer?.let {
127-
item {
128+
item(contentType = "footer") {
128129
Box(modifier = Modifier.alpha(if (footerSettled) 1f else 0f)) {
129130
it(false)
130131
}

0 commit comments

Comments
 (0)