-
Notifications
You must be signed in to change notification settings - Fork 285
Lazily load list #350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazily load list #350
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
| // Text(message.sender), where "message" is an object with a sender property | ||
| // Text(message.text), where "text" is an object with a text property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be uncommented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Because there's no actual message class anywhere that has a sender or text property, and this example was too complex for me to set something up idiomatically (at least in a time-efficient way).
If you feel it's necessary to have this in code, could I ask you to implement it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a simple class to represent the message structure is a common practice in DAC snippets. It helps make the code compile and snippets readable instead of the code being commented out.
While it's not strictly necessary for this particular example as you could just put a Text("Lazy list text"), it could be a good opportunity to practice this pattern, as it's frequently used in other snippets and real-world scenarios.
Would you be open to giving it a try? I'm happy to provide guidance and support if you need it.
Something like a dummy class like this would match this fake class:
data class Message(sender: String, text: String)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure--thank you for helping me learn!!
There's actually a reason why I didn't go ahead and create a data class as you're suggesting. What has me a little mixed-up are these lines:
lazyPagingItems = pager.flow.collectAsLazyPagingItems()
message = lazyPagingItems[index]
So I don't see how I can make message be an object of a new data class (such as I'd create) when it's already a variable set equal of LazyPagingItems type.
This was the complexity that stopped me from just defining my own class, and instead had me resort to commenting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tyvm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uncomment the Text composables.
…ad-list # Conflicts: # compose/snippets/src/main/java/com/example/compose/snippets/lists/LazyListSnippets.kt
# Conflicts: # compose/snippets/src/main/java/com/example/compose/snippets/lists/LazyListSnippets.kt
No description provided.