Skip to content

Commit 05e2468

Browse files
Show instructions as a subview instead of notice.
1 parent 1590f96 commit 05e2468

File tree

2 files changed

+73
-20
lines changed

2 files changed

+73
-20
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Split Shipments/WooShippingSplitShipmentsDetailView.swift

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@ struct WooShippingSplitShipmentsDetailView: View {
88

99
var body: some View {
1010
NavigationView {
11-
ScrollView {
12-
VStack(alignment: .leading, spacing: Layout.contentPadding) {
13-
AdaptiveStack(horizontalAlignment: .leading) {
14-
Text(viewModel.itemsCountLabel)
15-
.headlineStyle()
16-
Spacer()
17-
Text(viewModel.itemsDetailLabel)
18-
.foregroundStyle(Color(.textSubtle))
19-
}
11+
ZStack(alignment: .bottom) {
12+
ScrollView {
13+
VStack(alignment: .leading, spacing: Layout.contentPadding) {
14+
AdaptiveStack(horizontalAlignment: .leading) {
15+
Text(viewModel.itemsCountLabel)
16+
.headlineStyle()
17+
Spacer()
18+
Text(viewModel.itemsDetailLabel)
19+
.foregroundStyle(Color(.textSubtle))
20+
}
2021

21-
VStack(spacing: Layout.verticalSpacing) {
22-
ForEach(viewModel.shipmentCardViewModels) { item in
23-
CollapsibleShipmentCard(viewModel: item)
22+
VStack(spacing: Layout.verticalSpacing) {
23+
ForEach(viewModel.shipmentCardViewModels) { item in
24+
CollapsibleShipmentCard(viewModel: item)
25+
}
2426
}
2527
}
28+
.padding(Layout.contentPadding)
2629
}
27-
.padding(Layout.contentPadding)
30+
31+
noticeStack
32+
.padding(Layout.contentPadding)
2833
}
2934
.navigationBarTitleDisplayMode(.inline)
3035
.navigationTitle(Localization.title)
@@ -49,6 +54,51 @@ struct WooShippingSplitShipmentsDetailView: View {
4954
}
5055

5156
private extension WooShippingSplitShipmentsDetailView {
57+
var noticeStack: some View {
58+
VStack(spacing: Layout.contentPadding) {
59+
if let message = viewModel.instructions {
60+
InstructionsSnackbar(message: message) {
61+
viewModel.dismissInstructions()
62+
}
63+
}
64+
}
65+
}
66+
67+
private struct InstructionsSnackbar: View {
68+
let message: String
69+
let actionHandler: () -> Void
70+
71+
var body: some View {
72+
HStack(alignment: .top, spacing: Layout.hSpacing) {
73+
BoldableTextView(message)
74+
.foregroundStyle(Color(.textInverted))
75+
76+
Spacer()
77+
78+
Button {
79+
actionHandler()
80+
} label: {
81+
Image(systemName: "xmark")
82+
.foregroundStyle(Color(.withColorStudio(.gray)))
83+
}
84+
}
85+
.padding(WooShippingSplitShipmentsDetailView.Layout.contentPadding)
86+
.background {
87+
RoundedRectangle(cornerRadius: WooShippingSplitShipmentsDetailView.Layout.cornerRadius)
88+
.fill(Color(.text))
89+
.shadow(color: Color(.text).opacity(Layout.shadowColorOpacity),
90+
radius: WooShippingSplitShipmentsDetailView.Layout.shadowRadius,
91+
y: WooShippingSplitShipmentsDetailView.Layout.shadowYOffset)
92+
}
93+
}
94+
95+
private enum Layout {
96+
static let hSpacing: CGFloat = 8
97+
static let shadowColorOpacity: CGFloat = 0.16
98+
}
99+
}
100+
101+
fileprivate extension WooShippingSplitShipmentsDetailView {
52102
enum Layout {
53103
static let contentPadding: CGFloat = 16
54104
static let borderCornerRadius: CGFloat = 8

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Split Shipments/WooShippingSplitShipmentsViewModel.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ final class WooShippingSplitShipmentsViewModel: ObservableObject {
2828

2929
let shipmentCardViewModels: [CollapsibleShipmentCardViewModel]
3030

31-
@Published var instructionsNotice: Notice?
31+
@Published private(set) var instructions: String?
32+
private var dismissedInstructions: Bool = false
33+
3234

3335
init(order: Order,
3436
config: WooShippingConfig,
@@ -82,6 +84,11 @@ final class WooShippingSplitShipmentsViewModel: ObservableObject {
8284
$0.selectAll()
8385
}
8486
}
87+
88+
func dismissInstructions() {
89+
instructions = nil
90+
dismissedInstructions = true
91+
}
8592
}
8693

8794
private extension WooShippingSplitShipmentsViewModel {
@@ -94,12 +101,8 @@ private extension WooShippingSplitShipmentsViewModel {
94101
}
95102

96103
func showInstructionsNotice() {
97-
if hasSelectedAnItem() == false {
98-
instructionsNotice = Notice(message: Localization.SelectionInstructionsNotice.message,
99-
feedbackType: .success,
100-
actionTitle: Localization.SelectionInstructionsNotice.dismiss) { [weak self] in
101-
self?.instructionsNotice = nil
102-
}
104+
if !dismissedInstructions {
105+
instructions = Localization.SelectionInstructionsNotice.message
103106
}
104107
}
105108

0 commit comments

Comments
 (0)