diff --git a/Modules/Sources/JetpackStats/Constants.swift b/Modules/Sources/JetpackStats/Constants.swift index 79c84092b2f8..470f22a476d3 100644 --- a/Modules/Sources/JetpackStats/Constants.swift +++ b/Modules/Sources/JetpackStats/Constants.swift @@ -1,7 +1,7 @@ import SwiftUI import ColorStudio -enum Constants { +public enum Constants { enum Colors { static let positiveChangeForeground = Color(UIColor( light: UIColor(red: 0.2, green: 0.6, blue: 0.2, alpha: 1.0), @@ -69,7 +69,7 @@ enum Constants { static let cardHorizontalInsetCompact: CGFloat = step1 /// Returns the appropriate horizontal card inset for the given size class - static func cardHorizontalInset(for sizeClass: UserInterfaceSizeClass?) -> CGFloat { + public static func cardHorizontalInset(for sizeClass: UserInterfaceSizeClass?) -> CGFloat { sizeClass == .regular ? cardHorizontalInsetRegular : cardHorizontalInsetCompact } diff --git a/Modules/Sources/JetpackStats/Screens/TrafficTabView.swift b/Modules/Sources/JetpackStats/Screens/TrafficTabView.swift index 0851b449f5f9..e40b58d08248 100644 --- a/Modules/Sources/JetpackStats/Screens/TrafficTabView.swift +++ b/Modules/Sources/JetpackStats/Screens/TrafficTabView.swift @@ -25,7 +25,7 @@ struct TrafficTabView: View { buttonAddChart timeZoneInfo } - .padding(.vertical, Constants.step2 + (horizontalSizeClass == .regular ? Constants.step1 : 0)) + .padding(.vertical, Constants.step2) .padding(.horizontal, Constants.cardHorizontalInset(for: horizontalSizeClass)) .padding(.top, topPadding) .onReceive(viewModel.scrollToCardSubject) { cardID in diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsBaseTableViewController.swift b/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsBaseTableViewController.swift index 53c507c4a98e..88f5ced0ddd8 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsBaseTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsBaseTableViewController.swift @@ -1,21 +1,17 @@ import UIKit -import DesignSystem +import SwiftUI +import WordPressUI +import JetpackStats /// Base class for site stats table view controllers /// - class SiteStatsBaseTableViewController: UIViewController { let refreshControl = UIRefreshControl() - /// This property must be set before viewDidLoad is called - currently the classes that inherit are created from storyboards - /// When storyboard is removed it can be passed in as a parameter in an initializer - var tableStyle: UITableView.Style = .grouped + var tableStyle: UITableView.Style { .insetGrouped } - // MARK: - Properties - lazy var tableView: UITableView = { - UITableView(frame: .zero, style: tableStyle) - }() + private(set) lazy var tableView = UITableView(frame: .zero, style: tableStyle) override func viewDidLoad() { super.viewDidLoad() @@ -28,16 +24,29 @@ class SiteStatsBaseTableViewController: UIViewController { } func initTableView() { - tableView.translatesAutoresizingMaskIntoConstraints = false tableView.cellLayoutMarginsFollowReadableWidth = true + + if #available(iOS 26, *) { + tableView.preservesSuperviewLayoutMargins = false + } + view.addSubview(tableView) - view.pinSubviewToAllEdges(tableView) + tableView.pinEdges() tableView.refreshControl = refreshControl } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + if #available(iOS 26, *) { + let inset = JetpackStats.Constants.cardHorizontalInset(for: UserInterfaceSizeClass(traitCollection.horizontalSizeClass)) + tableView.directionalLayoutMargins = .init(top: 0, leading: inset, bottom: 0, trailing: inset) + } + } } -// MARK: - Tableview Datasource +// MARK: - UITableViewDataSource // These methods aren't actually needed as the tableview is controlled by an instance of ImmuTableViewHandler. // However, ImmuTableViewHandler requires that the owner of the tableview is a data source and delegate. @@ -52,14 +61,14 @@ extension SiteStatsBaseTableViewController: TableViewContainer, UITableViewDataS } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - return UITableViewCell() + UITableViewCell() } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - return .DS.Padding.double + if #available(iOS 26, *) { 30 } else { 16 } } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { - return 0 + 0 } } diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift b/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift index ded60c8b8ed1..ba841e38158b 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift @@ -52,17 +52,6 @@ class SiteStatsInsightsTableViewController: SiteStatsBaseTableViewController { return ImmuTableDiffableViewHandler(takeOver: self, with: analyticsTracker) }() - // MARK: - Initialization - - init() { - super.init(nibName: nil, bundle: nil) - tableStyle = .insetGrouped - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - // MARK: - View override func viewDidLoad() { diff --git a/WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodTableViewController.swift b/WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodTableViewController.swift index 47f3a34cfb55..a93ecd68f223 100644 --- a/WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodTableViewController.swift @@ -44,7 +44,6 @@ final class SiteStatsPeriodTableViewController: SiteStatsBaseTableViewController datePickerViewModel = StatsTrafficDatePickerViewModel(period: period, date: date) datePickerView = StatsTrafficDatePickerView(viewModel: datePickerViewModel) super.init(nibName: nil, bundle: nil) - tableStyle = .insetGrouped } required init?(coder: NSCoder) { diff --git a/WordPress/Classes/ViewRelated/Stats/Shared Views/Stats Detail/SiteStatsInsightsDetailsTableViewController.swift b/WordPress/Classes/ViewRelated/Stats/Shared Views/Stats Detail/SiteStatsInsightsDetailsTableViewController.swift index 2eba1e46ef87..38272126ad68 100644 --- a/WordPress/Classes/ViewRelated/Stats/Shared Views/Stats Detail/SiteStatsInsightsDetailsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/Shared Views/Stats Detail/SiteStatsInsightsDetailsTableViewController.swift @@ -58,7 +58,6 @@ class SiteStatsInsightsDetailsTableViewController: SiteStatsBaseTableViewControl self.selectedDate = selectedDate ?? StatsDataHelper.currentDateForSite() self.selectedPeriod = selectedPeriod self.postID = postID - tableStyle = .insetGrouped title = statSection.detailsTitle initViewModel() updateHeader() diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift index 4b99738a0ced..6ea513065715 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift @@ -13,8 +13,6 @@ final class StatsSubscribersViewController: SiteStatsBaseTableViewController { init(viewModel: StatsSubscribersViewModel) { self.viewModel = viewModel super.init(nibName: nil, bundle: nil) - - tableStyle = .insetGrouped } required init?(coder: NSCoder) {