Skip to content

Commit 17dff0c

Browse files
[WCAG 2.1 AA] Resolve remaining Blaze accessibility layout issues (#15703)
2 parents 468ba5c + 4a75ed8 commit 17dff0c

File tree

6 files changed

+67
-13
lines changed

6 files changed

+67
-13
lines changed

WooCommerce/Classes/ViewRelated/Blaze/BudgetSetting/BlazeScheduleSettingView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ struct BlazeScheduleSettingView: View {
5151
displayedComponents: [.date]) {
5252
EmptyView()
5353
}
54-
.datePickerStyle(.compact)
54+
.if(sizeCategory.isAccessibilityCategory) { view in
55+
view.datePickerStyle(.graphical)
56+
}
57+
.if(!sizeCategory.isAccessibilityCategory) { view in
58+
view.datePickerStyle(.compact)
59+
}
5560
}
5661

5762
// Toggle to switch between evergreen and not. Hidden under a feature flag.

WooCommerce/Classes/ViewRelated/Blaze/CampaignCreation/BlazeCampaignCreationForm.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private extension BlazeCampaignCreationForm {
329329
if viewModel.isLoadingAISuggestions ||
330330
viewModel.ctaText.isNotEmpty {
331331
Text(viewModel.isLoadingAISuggestions ? "CTA placeholder" : viewModel.ctaText)
332-
.font(.system(size: Constants.ctaButtonFontSize))
332+
.font(.caption)
333333
.foregroundColor(Constants.backgroundViewColor)
334334
.padding(Layout.ctaButtonPadding)
335335
.background(Constants.ctaButtonColor)
@@ -478,8 +478,6 @@ private extension BlazeCampaignCreationForm {
478478

479479
static let ctaButtonTextColor = Color.white
480480

481-
static let ctaButtonFontSize: CGFloat = 13
482-
483481
static let supportTag = "origin:blaze-native-campaign-creation"
484482
}
485483

WooCommerce/Classes/ViewRelated/Blaze/ConfirmPayment/BlazeConfirmPaymentView.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ struct BlazeConfirmPaymentView: View {
77
@ScaledMetric private var scale: CGFloat = 1.0
88
@ObservedObject private var viewModel: BlazeConfirmPaymentViewModel
99
@Environment(\.dismiss) private var dismiss
10+
@Environment(\.sizeCategory) private var sizeCategory
1011

1112
@State private var externalURL: URL?
1213
@State private var showingAddPaymentWebView: Bool = false
1314
@State private var isShowingSupport = false
1415

15-
private let agreementText: NSAttributedString = {
16+
/// Computed property to ensure the attributed string is recreated with current accessibility font settings
17+
/// when dynamic type size changes, rather than being fixed at initialization time.
18+
private var agreementText: NSAttributedString {
1619
let content = String.localizedStringWithFormat(Localization.agreement, Localization.termsOfService, Localization.adPolicy, Localization.learnMore)
1720
let paragraph = NSMutableParagraphStyle()
1821
paragraph.alignment = .center
@@ -31,7 +34,7 @@ struct BlazeConfirmPaymentView: View {
3134
mutableAttributedText.setAsLink(textToFind: Localization.learnMore,
3235
linkURL: Constants.learnMoreLink)
3336
return mutableAttributedText
34-
}()
37+
}
3538

3639
init(viewModel: BlazeConfirmPaymentViewModel) {
3740
self.viewModel = viewModel
@@ -60,7 +63,11 @@ struct BlazeConfirmPaymentView: View {
6063
.padding(.horizontal, Layout.contentPadding)
6164
}
6265

63-
Divider()
66+
if sizeCategory.isAccessibilityCategory {
67+
footerView
68+
} else {
69+
Divider()
70+
}
6471
}
6572
.padding(.vertical, Layout.contentPadding)
6673
}
@@ -74,7 +81,9 @@ struct BlazeConfirmPaymentView: View {
7481
}
7582
}
7683
.safeAreaInset(edge: .bottom) {
77-
footerView
84+
if !sizeCategory.isAccessibilityCategory {
85+
footerView
86+
}
7887
}
7988
.task {
8089
await viewModel.updatePaymentInfo()

WooCommerce/Classes/ViewRelated/Products/Cells/Product Images/ProductImagesHeaderTableViewCell.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Yosemite
44
final class ProductImagesHeaderTableViewCell: UITableViewCell {
55

66
@IBOutlet weak var collectionView: UICollectionView!
7+
@IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint!
78

89
/// View Model
910
///
@@ -34,6 +35,7 @@ final class ProductImagesHeaderTableViewCell: UITableViewCell {
3435

3536
configureBackground()
3637
configureSeparator()
38+
updateCollectionViewHeight()
3739
}
3840

3941
/// Configure cell
@@ -54,15 +56,25 @@ final class ProductImagesHeaderTableViewCell: UITableViewCell {
5456
}
5557
}
5658

57-
/// Rotation management
59+
/// Rotation management and accessibility changes
5860
///
5961
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
6062
super.traitCollectionDidChange(previousTraitCollection)
6163
if traitCollection != previousTraitCollection {
64+
// Update collection view height for accessibility changes
65+
updateCollectionViewHeight()
66+
// Invalidate layout when trait collection changes (including accessibility changes)
6267
collectionView.collectionViewLayout.invalidateLayout()
6368
collectionView.reloadData()
6469
}
6570
}
71+
72+
/// Updates the collection view height based on current accessibility settings
73+
private func updateCollectionViewHeight() {
74+
let cellSize = ProductImagesHeaderViewModel.cellSize(for: traitCollection.preferredContentSizeCategory)
75+
// Add padding to accommodate the cell size
76+
collectionViewHeightConstraint.constant = cellSize.height + Layout.collectionViewPadding
77+
}
6678
}
6779

6880
// MARK: - Collection View Delegate
@@ -98,7 +110,8 @@ extension ProductImagesHeaderTableViewCell: UICollectionViewDelegateFlowLayout {
98110
case .extendedAddImage:
99111
return frame.size
100112
default:
101-
return ProductImagesHeaderViewModel.defaultCollectionViewCellSize
113+
// Use dynamic sizing based on current accessibility settings
114+
return ProductImagesHeaderViewModel.cellSize(for: traitCollection.preferredContentSizeCategory)
102115
}
103116
}
104117
}
@@ -141,11 +154,23 @@ private extension ProductImagesHeaderTableViewCell {
141154

142155
self.config = config
143156

157+
// Update height for the new configuration
158+
updateCollectionViewHeight()
159+
144160
switch config {
145161
case .extendedAddImages:
146162
collectionView.collectionViewLayout = ProductImagesFlowLayout(itemSize: frame.size, config: config)
147163
default:
148-
collectionView.collectionViewLayout = ProductImagesFlowLayout(itemSize: ProductImagesHeaderViewModel.defaultCollectionViewCellSize, config: config)
164+
// Use dynamic sizing based on current accessibility settings
165+
let dynamicSize = ProductImagesHeaderViewModel.cellSize(for: traitCollection.preferredContentSizeCategory)
166+
collectionView.collectionViewLayout = ProductImagesFlowLayout(itemSize: dynamicSize, config: config)
149167
}
150168
}
151169
}
170+
171+
private extension ProductImagesHeaderTableViewCell {
172+
enum Layout {
173+
/// Padding around the collection view (16pt top and bottom)
174+
static let collectionViewPadding: CGFloat = 32
175+
}
176+
}

WooCommerce/Classes/ViewRelated/Products/Cells/Product Images/ProductImagesHeaderTableViewCell.xib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
4343
<connections>
4444
<outlet property="collectionView" destination="WFL-te-HOK" id="6lI-qf-ou5"/>
45+
<outlet property="collectionViewHeightConstraint" destination="o7N-sD-4mr" id="height-constraint-outlet"/>
4546
</connections>
4647
<point key="canvasLocation" x="131.15942028985509" y="122.54464285714285"/>
4748
</tableViewCell>

WooCommerce/Classes/ViewRelated/Products/Cells/Product Images/ProductImagesHeaderViewModel.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,24 @@ final class ProductImagesHeaderViewModel {
1111
/// Whether we should scroll to the beginning of the collection view.
1212
let shouldScrollToStart: Bool
1313

14-
// Fixed width/height of collection view cell
15-
static let defaultCollectionViewCellSize = CGSize(width: 128.0, height: 128.0)
14+
// Base size for accessibility scaling
15+
private static let baseCellSize: CGFloat = 128.0
16+
17+
/// Returns the appropriate cell size based on the content size category for accessibility
18+
static func cellSize(for contentSizeCategory: UIContentSizeCategory) -> CGSize {
19+
let scaledSize = scaledValue(baseCellSize, contentSizeCategory: contentSizeCategory, maximumContentSizeCategory: .accessibilityExtraExtraExtraLarge)
20+
return CGSize(width: scaledSize, height: scaledSize)
21+
}
22+
23+
/// Returns a scaled value using native iOS scaling, with a maximum cap for accessibility
24+
private static func scaledValue(_ value: CGFloat, contentSizeCategory: UIContentSizeCategory, maximumContentSizeCategory: UIContentSizeCategory) -> CGFloat {
25+
let metrics = UIFontMetrics.default
26+
let scaledValue = metrics.scaledValue(for: value, compatibleWith: .init(preferredContentSizeCategory: contentSizeCategory))
27+
28+
let maximumScaledValue = metrics.scaledValue(for: value, compatibleWith: .init(preferredContentSizeCategory: maximumContentSizeCategory))
29+
30+
return min(scaledValue, maximumScaledValue)
31+
}
1632

1733
private(set) var items: [ProductImagesItem] = []
1834

0 commit comments

Comments
 (0)