|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +struct ShippingLabelPackagesForm: View { |
| 4 | + @ObservedObject private var viewModel: ShippingLabelPackagesFormViewModel |
| 5 | + @Environment(\.presentationMode) var presentation |
| 6 | + |
| 7 | + init(viewModel: ShippingLabelPackagesFormViewModel) { |
| 8 | + self.viewModel = viewModel |
| 9 | + ServiceLocator.analytics.track(.shippingLabelPurchaseFlow, withProperties: ["state": "packages_started"]) |
| 10 | + } |
| 11 | + |
| 12 | + var body: some View { |
| 13 | + GeometryReader { geometry in |
| 14 | + ScrollView { |
| 15 | + ForEach(Array(viewModel.itemViewModels.enumerated()), id: \.offset) { index, element in |
| 16 | + ShippingLabelPackageItem(packageNumber: index + 1, |
| 17 | + isCollapsible: viewModel.foundMultiplePackages, |
| 18 | + safeAreaInsets: geometry.safeAreaInsets, |
| 19 | + viewModel: element) |
| 20 | + } |
| 21 | + .padding(.bottom, insets: geometry.safeAreaInsets) |
| 22 | + } |
| 23 | + .background(Color(.listBackground)) |
| 24 | + .ignoresSafeArea(.container, edges: [.horizontal, .bottom]) |
| 25 | + } |
| 26 | + .navigationTitle(Localization.title) |
| 27 | + .navigationBarItems(trailing: Button(action: { |
| 28 | + ServiceLocator.analytics.track(.shippingLabelPurchaseFlow, |
| 29 | + withProperties: ["state": "packages_selected"]) |
| 30 | + // TODO-4599: Update selection |
| 31 | + presentation.wrappedValue.dismiss() |
| 32 | + }, label: { |
| 33 | + Text(Localization.doneButton) |
| 34 | + })) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +private extension ShippingLabelPackagesForm { |
| 39 | + enum Localization { |
| 40 | + static let title = NSLocalizedString("Package Details", |
| 41 | + comment: "Navigation bar title of shipping label package details screen") |
| 42 | + static let doneButton = NSLocalizedString("Done", comment: "Done navigation button in the Package Details screen in Shipping Label flow") |
| 43 | + } |
| 44 | + |
| 45 | + enum Constants { |
| 46 | + static let dividerPadding: CGFloat = 16 |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +struct ShippingLabelPackagesForm_Previews: PreviewProvider { |
| 51 | + static var previews: some View { |
| 52 | + let viewModel = ShippingLabelPackagesFormViewModel(order: ShippingLabelPackagesFormViewModel.sampleOrder(), |
| 53 | + packagesResponse: ShippingLabelPackagesFormViewModel.samplePackageDetails(), |
| 54 | + selectedPackages: []) |
| 55 | + |
| 56 | + ShippingLabelPackagesForm(viewModel: viewModel) |
| 57 | + .environment(\.colorScheme, .light) |
| 58 | + .previewDisplayName("Light") |
| 59 | + |
| 60 | + ShippingLabelPackagesForm(viewModel: viewModel) |
| 61 | + .environment(\.colorScheme, .dark) |
| 62 | + .previewDisplayName("Dark") |
| 63 | + } |
| 64 | +} |
0 commit comments