Skip to content

Commit b8423db

Browse files
committed
Add a loading indicator to POSPageHeaderView
1 parent 73434ab commit b8423db

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

WooCommerce/Classes/POS/Presentation/Reusable Views/POSPageHeaderView.swift

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ struct POSPageHeaderItem: Identifiable {
2424
let title: String
2525
let subtitle: String?
2626
let isSelected: Bool
27+
let isLoading: Bool
2728
let action: (() -> Void)?
2829

29-
init(title: String, subtitle: String? = nil, isSelected: Bool, action: (() -> Void)? = nil) {
30+
init(title: String, subtitle: String? = nil, isSelected: Bool, isLoading: Bool = false, action: (() -> Void)? = nil) {
3031
self.title = title
3132
self.subtitle = subtitle
3233
self.isSelected = isSelected
34+
self.isLoading = isLoading
3335
self.action = action
3436
}
3537
}
@@ -52,10 +54,11 @@ struct POSPageHeaderView<TrailingContent: View>: View {
5254
init(
5355
title: String,
5456
subtitle: String? = nil,
57+
isLoading: Bool = false,
5558
backButtonConfiguration: POSPageHeaderBackButtonConfiguration? = nil,
5659
@ViewBuilder trailingContent: () -> TrailingContent = { EmptyView() }
5760
) {
58-
self.items = [.init(title: title, subtitle: subtitle, isSelected: true)]
61+
self.items = [.init(title: title, subtitle: subtitle, isSelected: true, isLoading: isLoading)]
5962
self.backButtonConfiguration = backButtonConfiguration
6063
self.trailingContent = trailingContent()
6164
}
@@ -79,20 +82,29 @@ struct POSPageHeaderView<TrailingContent: View>: View {
7982
HStack(alignment: hStackAlignment, spacing: POSSpacing.large) {
8083
ForEach(0..<items.count, id: \.self) { index in
8184
VStack(alignment: .leading, spacing: Constants.titleSubtitleSpacing) {
82-
Button(action: {
83-
items[index].action?()
84-
}) {
85-
Text(items[index].title)
86-
.font(.posHeadingBold)
87-
.lineLimit(1)
88-
.minimumScaleFactor(0.5)
89-
.dynamicTypeSize(...POSHeaderLayoutConstants.maximumDynamicTypeSize)
90-
.foregroundColor(items[index].isSelected ? .posOnSurface : .posOnSurfaceVariantLowest)
85+
HStack(spacing: POSSpacing.small) {
86+
Button(action: {
87+
items[index].action?()
88+
}) {
89+
Text(items[index].title)
90+
.font(.posHeadingBold)
91+
.lineLimit(1)
92+
.minimumScaleFactor(0.5)
93+
.dynamicTypeSize(...POSHeaderLayoutConstants.maximumDynamicTypeSize)
94+
.foregroundColor(items[index].isSelected ? .posOnSurface : .posOnSurfaceVariantLowest)
95+
}
96+
.disabled(items[index].isSelected)
97+
.accessibilityElement()
98+
.accessibilityAddTraits(items.count == 1 ? .isHeader : [.isHeader, .isButton])
99+
.accessibilityLabel(items[index].title)
100+
101+
if items[index].isLoading {
102+
ProgressView()
103+
.progressViewStyle(.circular)
104+
.scaleEffect(0.7)
105+
.transition(.opacity.combined(with: .scale))
106+
}
91107
}
92-
.disabled(items[index].isSelected)
93-
.accessibilityElement()
94-
.accessibilityAddTraits(items.count == 1 ? .isHeader : [.isHeader, .isButton])
95-
.accessibilityLabel(items[index].title)
96108

97109
if let subtitle = items[index].subtitle {
98110
Text(subtitle)
@@ -193,6 +205,13 @@ private enum Constants {
193205
backButtonConfiguration: .init(state: .enabled, action: {})
194206
)
195207

208+
// Header with loading indicator.
209+
POSPageHeaderView(
210+
title: "Orders",
211+
isLoading: true,
212+
backButtonConfiguration: .init(state: .enabled, action: {})
213+
)
214+
196215
// Header with subtitle and disabled back button.
197216
POSPageHeaderView(
198217
title: "Cash payment",

0 commit comments

Comments
 (0)