Skip to content

Conversation

swankjesse
Copy link
Collaborator


  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

awaitSnapshot()
assertThat(index5ComposeCount).isEqualTo(1)

// Scrolling to a non-contiguous range causes a recomposition.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was awkward because it needed to pick bounds carefully.

@@ -92,11 +91,6 @@ public class ScrollOptimizedLoadingStrategy(

// Expand the range depending on scroll direction.
when {
// Ignore preloads.
!preloadItems -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, this was only ever used in one unit test anyway

/**
* A loading strategy that's appropriate for tests because it's simple and predictable.
*
* This is not suitable for production use it must show a placeholder before an item is loaded.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this two sentences, or missing a comma or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

 * This is not suitable for production use, because it must show a placeholder before an item is
 * loaded.

* This is not suitable for production use it must show a placeholder before an item is loaded.
*/
public class DirectLoadingStrategy : LoadingStrategy {
private var loadRange: IntRange by mutableStateOf(0..0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private var loadRange: IntRange by mutableStateOf(0..0)
private var loadRange: IntRange = 0..0

The only read is firstIndex which is only used when saving. Don't think you need a full-on state object tracking this value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t I need this to trigger a recomposition after the user scrolls?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the composition reads this. Maybe I missed it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It calls loadRange(), which reads variables here. I assume using State variables is the easiest way to express the data dependency.

*
* This is not suitable for production use it must show a placeholder before an item is loaded.
*/
public class DirectLoadingStrategy : LoadingStrategy {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming nit: I think the name should make it abundantly clear that this should never be used in production. Something like Fake/Test/Mock instead of Direct would help with this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Changed to TestLoadingStrategy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I'm using longer names to disambiguate two related ranges:
 - the visible range
 - the loaded range
@swankjesse swankjesse merged commit 2aecd58 into trunk Aug 2, 2024
@swankjesse swankjesse deleted the jwilson.0731.loading_strategy_for_testing branch August 2, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants