Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions WooCommerce/Classes/View Modifiers/View+DividerStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import SwiftUI

/// Custom view modifier for applying the default divider style.
struct DividerStyle: ViewModifier {

func body(content: Content) -> some View {
content
.foregroundColor(Color(.separator))
.frame(height: Layout.height)
}
}

private extension DividerStyle {
enum Layout {
static let height: CGFloat = 1
}
}

extension View {
/// Applies the default divider style to a view.
func dividerStyle() -> some View {
self.modifier(DividerStyle())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import SwiftUI

/// Shows a list of domains in domain settings with a CTA to add a domain.
struct DomainSettingsListView: View {
let domains: [DomainSettingsViewModel.Domain]
let addDomain: () -> Void

var body: some View {
VStack(alignment: .leading, spacing: 0) {
Text(Localization.header.uppercased())
.padding(Layout.headerPadding)
.foregroundColor(Color(.secondaryLabel))
.captionStyle()

ForEach(domains, id: \.name) { domain in
HStack {
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Are we planning to add some button on the right side of the item? Asking because I'm not sure why we need a HStack to embed the contents here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, we don't plan to add any button to the trailing side. Originally it was the only straightforward way for me to align the domain rows on the trailing edge, however it doesn't look needed anymore. Removed in 5ba1ff5

VStack(alignment: .leading) {
Text(domain.name)
if let renewalDate = domain.autoRenewalDate {
Text(String(format: Localization.renewalDateFormat, renewalDate.toString(dateStyle: .medium, timeStyle: .none)))
.foregroundColor(Color(.secondaryLabel))
}
}
Spacer()
}
.padding(Layout.domainPadding)
Divider()
.dividerStyle()
.padding(Layout.dividerPadding)
}

Button(Localization.addDomain) {
addDomain()
}
.padding(Layout.actionButtonPadding)
.buttonStyle(PlusButtonStyle())

Divider()
.dividerStyle()
.padding(Layout.dividerPadding)
}
}
}

private extension DomainSettingsListView {
enum Localization {
static let header = NSLocalizedString(
"Your site domains",
comment: "Header text of the site's domain list in domain settings."
)
static let renewalDateFormat = NSLocalizedString(
"Renews on %1$@",
comment: "Renewal date of a site's domain in domain settings. " +
"Reads like `Renews on October 11, 2023`."
)
static let addDomain = NSLocalizedString(
"Add a domain",
comment: "Title of button to add a domain in domain settings."
)
}

enum Layout {
static let headerPadding: EdgeInsets = .init(top: 18, leading: 16, bottom: 6, trailing: 16)
static let domainPadding: EdgeInsets = .init(top: 10, leading: 16, bottom: 10, trailing: 16)
static let actionButtonPadding: EdgeInsets = .init(top: 18, leading: 16, bottom: 18, trailing: 23)
static let dividerPadding: EdgeInsets = .init(top: 0, leading: 16, bottom: 0, trailing: 0)
static let dividerHeight: CGFloat = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nit: this doesn't seem to be used, should we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in 82d240c

}
}

struct DomainSettingsListView_Previews: PreviewProvider {
static var previews: some View {
DomainSettingsListView(domains: [
.init(isPrimary: true, name: "play.store", autoRenewalDate: .distantFuture),
.init(isPrimary: false, name: "app.store", autoRenewalDate: nil),
.init(isPrimary: false, name: "woo.store", autoRenewalDate: .now)
], addDomain: {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ struct DomainSettingsView: View {
FreeStagingDomainView(domain: freeDomain)
Spacer()
}
.padding(.horizontal, insets: Layout.defaultHorizontalPadding)
}

if viewModel.hasDomainCredit {
// TODO: 8558 - domain credit UI with redemption action
}

if viewModel.domains.isNotEmpty {
// TODO: 8558 - show domain list with search domain action
DomainSettingsListView(domains: viewModel.domains) {
// TODO: 8558 - search domain action
}
}
}
.padding(Layout.contentPadding)
Expand Down Expand Up @@ -82,7 +85,8 @@ private extension DomainSettingsView {
enum Layout {
static let dividerHeight: CGFloat = 1
static let bottomContentPadding: EdgeInsets = .init(top: 10, leading: 16, bottom: 10, trailing: 16)
static let contentPadding: EdgeInsets = .init(top: 39, leading: 16, bottom: 16, trailing: 16)
static let contentPadding: EdgeInsets = .init(top: 39, leading: 0, bottom: 16, trailing: 0)
static let defaultHorizontalPadding: EdgeInsets = .init(top: 0, leading: 16, bottom: 0, trailing: 16)
static let contentSpacing: CGFloat = 36
}
}
Expand Down
8 changes: 8 additions & 0 deletions WooCommerce/WooCommerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
02521E11243DC3C400DC7810 /* CancellableMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02521E10243DC3C400DC7810 /* CancellableMedia.swift */; };
02524A5D252ED5C60033E7BD /* ProductVariationLoadUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02524A5C252ED5C60033E7BD /* ProductVariationLoadUseCaseTests.swift */; };
02535CBB25823F7A00E137BB /* ShippingLabelPaperSize+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02535CBA25823F7A00E137BB /* ShippingLabelPaperSize+UI.swift */; };
02562AD0296D1FD100980404 /* View+DividerStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02562ACF296D1FD100980404 /* View+DividerStyle.swift */; };
02564A88246C047C00D6DB2A /* Optional+StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02564A87246C047C00D6DB2A /* Optional+StringTests.swift */; };
02564A8A246CDF6100D6DB2A /* ProductsTopBannerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02564A89246CDF6100D6DB2A /* ProductsTopBannerFactory.swift */; };
02564A8C246CE38E00D6DB2A /* SwappableSubviewContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02564A8B246CE38E00D6DB2A /* SwappableSubviewContainerView.swift */; };
Expand Down Expand Up @@ -370,6 +371,7 @@
02B2829027C352DA004A332A /* RefreshableScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2828F27C352DA004A332A /* RefreshableScrollView.swift */; };
02B2829227C4808D004A332A /* InfiniteScrollIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2829127C4808D004A332A /* InfiniteScrollIndicator.swift */; };
02B2C831249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2C830249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift */; };
02B41A96296D09D100FE3311 /* DomainSettingsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B41A95296D09D100FE3311 /* DomainSettingsListView.swift */; };
02B653AC2429F7BF00A9C839 /* MockTaxClassStoresManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B653AB2429F7BF00A9C839 /* MockTaxClassStoresManager.swift */; };
02B8650F24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B8650E24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift */; };
02BA12852461674B008D8325 /* Optional+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02BA12842461674B008D8325 /* Optional+String.swift */; };
Expand Down Expand Up @@ -2265,6 +2267,7 @@
02521E10243DC3C400DC7810 /* CancellableMedia.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancellableMedia.swift; sourceTree = "<group>"; };
02524A5C252ED5C60033E7BD /* ProductVariationLoadUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVariationLoadUseCaseTests.swift; sourceTree = "<group>"; };
02535CBA25823F7A00E137BB /* ShippingLabelPaperSize+UI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ShippingLabelPaperSize+UI.swift"; sourceTree = "<group>"; };
02562ACF296D1FD100980404 /* View+DividerStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+DividerStyle.swift"; sourceTree = "<group>"; };
02564A87246C047C00D6DB2A /* Optional+StringTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Optional+StringTests.swift"; sourceTree = "<group>"; };
02564A89246CDF6100D6DB2A /* ProductsTopBannerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsTopBannerFactory.swift; sourceTree = "<group>"; };
02564A8B246CE38E00D6DB2A /* SwappableSubviewContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwappableSubviewContainerView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2438,6 +2441,7 @@
02B2828F27C352DA004A332A /* RefreshableScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshableScrollView.swift; sourceTree = "<group>"; };
02B2829127C4808D004A332A /* InfiniteScrollIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfiniteScrollIndicator.swift; sourceTree = "<group>"; };
02B2C830249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldTextAlignmentTests.swift; sourceTree = "<group>"; };
02B41A95296D09D100FE3311 /* DomainSettingsListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainSettingsListView.swift; sourceTree = "<group>"; };
02B653AB2429F7BF00A9C839 /* MockTaxClassStoresManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTaxClassStoresManager.swift; sourceTree = "<group>"; };
02B8650E24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Product+SwiftUIPreviewHelpers.swift"; sourceTree = "<group>"; };
02BA12842461674B008D8325 /* Optional+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Optional+String.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4546,6 +4550,7 @@
02C37B7A2967096800F0CF9E /* DomainSettingsView.swift */,
02C37B7C2967B72A00F0CF9E /* FreeStagingDomainView.swift */,
02DE39D82968647100BB31D4 /* DomainSettingsViewModel.swift */,
02B41A95296D09D100FE3311 /* DomainSettingsListView.swift */,
);
path = Domains;
sourceTree = "<group>";
Expand Down Expand Up @@ -5497,6 +5502,7 @@
AE77EA4F27A47C99006A21BD /* View+AddingDividers.swift */,
AED089F127C794BC0020AE10 /* View+CurrencySymbol.swift */,
CC666F2327F329DC0045AF1E /* View+DiscardChanges.swift */,
02562ACF296D1FD100980404 /* View+DividerStyle.swift */,
);
path = "View Modifiers";
sourceTree = "<group>";
Expand Down Expand Up @@ -10913,6 +10919,7 @@
025FDD3423717D4900824006 /* AztecEditorViewController.swift in Sources */,
451B1740258B7EFB00836277 /* AddAttributeOptionsViewController.swift in Sources */,
AE6C4FDF28A15BFE00EAC00D /* FeatureAnnouncementCardCell.swift in Sources */,
02562AD0296D1FD100980404 /* View+DividerStyle.swift in Sources */,
CE5F462723AAC8C0006B1A5C /* RefundDetailsViewModel.swift in Sources */,
D8815B132638686200EDAD62 /* CardPresentModalError.swift in Sources */,
02EAA4CA2911004B00918DAB /* TextFieldStyles.swift in Sources */,
Expand Down Expand Up @@ -10942,6 +10949,7 @@
0269A63C2581D26C007B49ED /* ShippingLabelPrintingStepListView.swift in Sources */,
3188533C2639FE5800F66A9C /* CardReaderSettingsPresentedViewViewModel.swift in Sources */,
DE792E1B26EF37ED0071200C /* DefaultConnectivityObserver.swift in Sources */,
02B41A96296D09D100FE3311 /* DomainSettingsListView.swift in Sources */,
029F29FE24DA5B2D004751CA /* ProductInventorySettingsViewModel.swift in Sources */,
57CFCD28248845B4003F51EC /* PrimarySectionHeaderView.swift in Sources */,
023A059A24135F2600E3FC99 /* ReviewsViewController.swift in Sources */,
Expand Down