Skip to content

Commit 7a178bf

Browse files
authored
Merge pull request #6176 from woocommerce/fix/infinite-scroll-migration-to-lazyvstack
Migrated `InfiniteScrollList` from `List` to `LazyVStack`
2 parents cdf7c8e + 78f1f4b commit 7a178bf

File tree

5 files changed

+45
-27
lines changed

5 files changed

+45
-27
lines changed

WooCommerce/Classes/ViewRelated/Inbox/Inbox.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ struct Inbox: View {
1818
InfiniteScrollList(isLoading: viewModel.shouldShowBottomActivityIndicator,
1919
loadAction: viewModel.onLoadNextPageAction) {
2020
ForEach(viewModel.noteRowViewModels) { rowViewModel in
21-
if #available(iOS 15.0, *) {
22-
// In order to show full-width separator, the default list separator is hidden and a `Divider` is shown inside the row.
23-
InboxNoteRow(viewModel: rowViewModel)
24-
.listRowSeparator(.hidden)
25-
} else {
26-
InboxNoteRow(viewModel: rowViewModel)
27-
}
21+
InboxNoteRow(viewModel: rowViewModel)
2822
}
23+
.background(Constants.listForeground)
2924
}
3025
case .empty:
3126
// TODO: 5954 - update empty state
@@ -34,17 +29,19 @@ struct Inbox: View {
3429
image: .emptyProductsTabImage)
3530
.frame(maxHeight: .infinity)
3631
case .syncingFirstPage:
37-
List {
38-
ForEach(viewModel.placeholderRowViewModels) { rowViewModel in
39-
InboxNoteRow(viewModel: rowViewModel)
40-
.redacted(reason: .placeholder)
41-
.shimmering()
32+
ScrollView {
33+
LazyVStack(spacing: 0) {
34+
ForEach(viewModel.placeholderRowViewModels) { rowViewModel in
35+
InboxNoteRow(viewModel: rowViewModel)
36+
.redacted(reason: .placeholder)
37+
.shimmering()
38+
}
39+
.background(Constants.listForeground)
4240
}
4341
}
44-
.listStyle(PlainListStyle())
4542
}
4643
}
47-
.background(Color(.listBackground).ignoresSafeArea())
44+
.background(Constants.listBackground.ignoresSafeArea())
4845
.navigationTitle(Localization.title)
4946
.onAppear {
5047
viewModel.onLoadTrigger.send()
@@ -53,6 +50,12 @@ struct Inbox: View {
5350
}
5451

5552
private extension Inbox {
53+
54+
enum Constants {
55+
static let listForeground: Color = Color(.listForeground)
56+
static let listBackground: Color = Color(.listBackground)
57+
}
58+
5659
enum Localization {
5760
static let title = NSLocalizedString("Inbox", comment: "Title for the screen that shows inbox notes.")
5861
static let emptyStateTitle = NSLocalizedString("Congrats, you’ve read everything!",

WooCommerce/Classes/ViewRelated/Inbox/InboxNoteRow.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ struct InboxNoteRow: View {
6767
}
6868
.padding(Constants.defaultPadding)
6969

70-
if #available(iOS 15.0, *) {
71-
// In order to show full-width separator, the default list separator is hidden and a `Divider` is shown inside the row.
72-
Divider()
73-
.frame(height: Constants.dividerHeight)
74-
}
70+
Divider()
71+
.frame(height: Constants.dividerHeight)
7572
}
76-
.listRowInsets(.zero)
7773
}
7874
}
7975

WooCommerce/Classes/ViewRelated/Orders/Order Creation/ProductsSection/AddProductToOrder.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ struct AddProductToOrder: View {
2121
loadAction: viewModel.syncNextPage) {
2222
ForEach(viewModel.productRows) { rowViewModel in
2323
createProductRow(rowViewModel: rowViewModel)
24+
.padding(Constants.defaultPadding)
25+
Divider().frame(height: Constants.dividerHeight)
26+
.padding(.leading, Constants.defaultPadding)
2427
}
2528
}
29+
.background(Color(.listForeground))
2630
case .empty:
2731
EmptyState(title: Localization.emptyStateMessage, image: .emptyProductsTabImage)
2832
.frame(maxHeight: .infinity)
@@ -74,6 +78,11 @@ struct AddProductToOrder: View {
7478
}
7579

7680
private extension AddProductToOrder {
81+
enum Constants {
82+
static let dividerHeight: CGFloat = 1
83+
static let defaultPadding: CGFloat = 16
84+
}
85+
7786
enum Localization {
7887
static let title = NSLocalizedString("Add Product", comment: "Title for the screen to add a product to an order")
7988
static let close = NSLocalizedString("Close", comment: "Text for the close button in the Add Product screen")

WooCommerce/Classes/ViewRelated/Orders/Order Creation/ProductsSection/AddProductVariationToOrder.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ struct AddProductVariationToOrder: View {
2121
loadAction: viewModel.syncNextPage) {
2222
ForEach(viewModel.productVariationRows) { rowViewModel in
2323
ProductRow(viewModel: rowViewModel)
24+
.padding(Constants.defaultPadding)
2425
.onTapGesture {
2526
viewModel.selectVariation(rowViewModel.productOrVariationID)
2627
isPresented.toggle()
2728
}
29+
Divider().frame(height: Constants.dividerHeight)
30+
.padding(.leading, Constants.defaultPadding)
2831
}
32+
.background(Color(.listForeground))
2933
}
3034
case .empty:
3135
EmptyState(title: Localization.emptyStateMessage, image: .emptyProductsTabImage)
@@ -64,6 +68,11 @@ struct AddProductVariationToOrder: View {
6468
}
6569

6670
private extension AddProductVariationToOrder {
71+
enum Constants {
72+
static let dividerHeight: CGFloat = 1
73+
static let defaultPadding: CGFloat = 16
74+
}
75+
6776
enum Localization {
6877
static let emptyStateMessage = NSLocalizedString("No product variations found",
6978
comment: "Message displayed if there are no product variations for a product.")

WooCommerce/Classes/ViewRelated/ReusableViews/SwiftUI Components/InfiniteScrollList.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ struct InfiniteScrollList<Content: View>: View {
3030
}
3131

3232
var body: some View {
33-
List {
34-
listContent
33+
ScrollView {
34+
LazyVStack(spacing: 0) {
35+
listContent
3536

36-
InfiniteScrollIndicator(showContent: isLoading)
37-
.onAppear {
38-
loadAction()
39-
}
37+
InfiniteScrollIndicator(showContent: isLoading)
38+
.onAppear {
39+
loadAction()
40+
}
41+
}
4042
}
41-
.listStyle(PlainListStyle())
4243
}
4344
}
4445

0 commit comments

Comments
 (0)