Skip to content
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

[Woo POS] Improve next page trigger #14827

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

joshheald
Copy link
Contributor

@joshheald joshheald commented Jan 8, 2025

Part of: #14696
Merge after: #14818

Description

This PR simplifies and improves the trigger for loadNextPage on POS item lists. This is preliminary work before adding pagination support for variation lists. The root and child lists also now use the same ItemList component, which contains everything it needs to show the scrollview and its content.

Previously we tracked the scroll position and compared it to a threshold based on view height. This resulted in loading the next page whenever the view is scrolled.

Now we show the loading cell whenever we get to the bottom of the list, as long as there are still pages to load.

When the loading cell appears, we start the next page fetch request.

Steps to reproduce

Set the page size for ProductsRemote.loadProductsForPointOfSale to something small enough that you can see multiple pages loading, but large enough that the page more than fills the screen. I use 10.

Open the POS and check that you can load multiple pages.

Observe network requests and check that we don't make any extra requests.

Breakpoint in loadNextItems to see that it's only called when expected.

Check that the new page is _only_loaded when the bottom of the list content is scrolled in to view.

Check that variation lists don't trigger any requests. This is preparatory work for variation pagination support.

Testing information

N.B. If you test this with a very small page size, it won't work, because the loading cell doesn't disappear and reappear between load events, but for realistic page sizes (10+) it works well.

This fixes a bug where scrolling any amount on the list, even if it's not at the end, would result in a next page load.


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

Previously we tracked the scroll position and compared it to a threshold based on view height. This resulted in loading the next page whenever the view is scrolled.

This changes the approach to show the loading cell whenever we get to the bottom of the list, as long as there are still pages to load.

When the loading cell appears, which with the move to LazyVStack is only when it’s scrolled in to view, we start the next page fetch request.
This avoids us calling `loadNextItems` for the root list when a child list is scrolled to the bottom.

It also lays the groundwork for calling the correct next item function when we add pagination support.
@joshheald joshheald added type: task An internally driven task. feature: POS labels Jan 8, 2025
@joshheald joshheald added this to the 21.4 milestone Jan 8, 2025
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 8, 2025

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14827-52315e4
Version21.3
Bundle IDcom.automattic.alpha.woocommerce
Commit52315e4
App Center BuildWooCommerce - Prototype Builds #12446
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Base automatically changed from feat/14702-replace-POSParentProduct-with-POSVariableParentProduct to trunk January 9, 2025 00:48
Copy link
Contributor

@jaclync jaclync left a comment

Choose a reason for hiding this comment

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

Works well for stores with partial first page and multi-page products :shipit: I will comment about my thoughts on the infinite scroll separately in #14833. This PR is good to go.

case parent(POSItem)
}

@Environment(\.floatingControlAreaSize) var floatingControlAreaSize: CGSize
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could be private?

Suggested change
@Environment(\.floatingControlAreaSize) var floatingControlAreaSize: CGSize
@Environment(\.floatingControlAreaSize) private var floatingControlAreaSize: CGSize

Comment on lines +39 to +40
guard case .root = node else { return }
Task { await posModel.loadNextItems() }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this is where we'll trigger the child item next page load as well. Do you plan to add a different loadNextItems given a parent node, or add a parameter to loadNextItems with the parent item?

itemStates: [:]))
} else {
let itemStates = itemsViewState.itemsStack.itemStates
.filter { allItems.contains($0.key) }
itemsViewState = .init(containerState: .content,
itemsStack: ItemsStackState(root: .loaded(allItems),
itemsStack: ItemsStackState(root: .loaded(allItems, hasMoreItems: pagedItems.hasMorePages),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe can have a test case for this when pagedItems.hasMorePages is true, if not already? Asking because I was seeing all hasMoreItems: false in the PointOfSaleItemsControllerTests diffs.

@wpmobilebot wpmobilebot modified the milestones: 21.4, 21.5 Jan 10, 2025
@wpmobilebot
Copy link
Collaborator

Version 21.4 has now entered code-freeze, so the milestone of this PR has been updated to 21.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: POS type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants