Skip to content

Commit 95522d0

Browse files
authored
Merge pull request #308 from cocoatype/305-fix-photo-library-button-accessibility-labels
Fix photo library button accessibility label
2 parents e294bb9 + 78f4729 commit 95522d0

File tree

7 files changed

+122
-73
lines changed

7 files changed

+122
-73
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// The accessibility label for the photo library button
2+
"PhotoLibraryToolbarItem.accessibilityLabel" = "Photo Library";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Created by Geoff Pado on 5/29/25.
2+
// Copyright © 2025 Cocoatype, LLC. All rights reserved.
3+
4+
import SwiftUI
5+
6+
struct PhotoLibraryAlertButton: View {
7+
@Binding private var isShowingPurchaseAlert: Bool
8+
init(isShowingPurchaseAlert: Binding<Bool>) {
9+
_isShowingPurchaseAlert = isShowingPurchaseAlert
10+
}
11+
12+
var body: some View {
13+
Button {
14+
Task { isShowingPurchaseAlert = true }
15+
} label: {
16+
Image(systemName: "photo.on.rectangle")
17+
.imageScale(.medium)
18+
}
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Created by Geoff Pado on 5/29/25.
2+
// Copyright © 2025 Cocoatype, LLC. All rights reserved.
3+
4+
import SwiftUI
5+
6+
struct PhotoLibraryDisabledButton: View {
7+
var body: some View {
8+
Button {} label: {
9+
Image(systemName: PhotoLibraryToolbarItem.systemImage)
10+
.imageScale(.medium)
11+
}
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Created by Geoff Pado on 5/29/25.
2+
// Copyright © 2025 Cocoatype, LLC. All rights reserved.
3+
4+
import SwiftUI
5+
6+
import BarcPhotoLibrary
7+
8+
struct PhotoLibraryPresentingButton: View {
9+
var body: some View {
10+
PhotoLibraryButton {
11+
Image(systemName: PhotoLibraryToolbarItem.systemImage)
12+
.imageScale(.medium)
13+
}
14+
}
15+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Created by Geoff Pado on 3/11/25.
2+
// Copyright © 2025 Cocoatype, LLC. All rights reserved.
3+
4+
import SwiftUI
5+
6+
import FactoryKit
7+
8+
import BarcErrorHandling
9+
import BarcPersistence
10+
import BarcPhotoLibrary
11+
import BarcPurchasing
12+
import BarcRouting
13+
import BarcUnpurchased
14+
15+
struct PhotoLibraryToolbarItem: View {
16+
nonisolated static let systemImage = "photo.on.rectangle"
17+
18+
@Binding private var sheetRoute: Route?
19+
init(
20+
value: Binding<Route?>
21+
) {
22+
_sheetRoute = value
23+
}
24+
25+
@State private var isShowingPurchaseAlert = false
26+
@State private var purchaseState = PurchaseState.undetermined
27+
@Injected(\.guardLetNotIsScrollingDoesNotEqual) private var barcodeRepository
28+
@Injected(\.replaceBacktickWithBacktick) private var purchaseRepository
29+
@Injected(\.errorHandler) private var errorHandler
30+
var body: some View {
31+
currentButton
32+
.accessibilityLabel(Strings.PhotoLibraryToolbarItem.accessibilityLabel)
33+
.task { await updatePurchaseState() }
34+
.unpurchasedAlert(
35+
for: .unlimitedBarcodes,
36+
isPresented: $isShowingPurchaseAlert
37+
)
38+
}
39+
40+
@ViewBuilder private var currentButton: some View {
41+
switch purchaseState {
42+
case .undetermined:
43+
PhotoLibraryDisabledButton()
44+
case .purchased:
45+
PhotoLibraryPresentingButton()
46+
case .unpurchased:
47+
PhotoLibraryAlertButton(isShowingPurchaseAlert: $isShowingPurchaseAlert)
48+
}
49+
}
50+
51+
private func updatePurchaseState() async {
52+
do {
53+
let hasUserBeenUnleashed = try await purchaseRepository.hasUserBeenUnleashed
54+
let codesCount = try barcodeRepository.codes.count
55+
if hasUserBeenUnleashed || codesCount < Purchasing.maxBarcodesCount {
56+
purchaseState = .purchased
57+
} else {
58+
purchaseState = .unpurchased
59+
}
60+
} catch {
61+
errorHandler.log(error, module: "Root", type: "PhotoLibraryToolbarItem")
62+
purchaseState = .purchased
63+
}
64+
}
65+
66+
enum PurchaseState {
67+
case undetermined
68+
case purchased
69+
case unpurchased
70+
}
71+
}

Modules/Root/Sources/Toolbar Items/PhotoLibraryToolbarItem.swift

Lines changed: 0 additions & 73 deletions
This file was deleted.

Tuist/ProjectDescriptionHelpers/Targets/Modules/Root.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ProjectDescription
33
public enum Root {
44
public static let target = Target.moduleTarget(
55
name: "Root",
6+
hasResources: true,
67
dependencies: [
78
.target(Barcodes.target),
89
.target(BarcodeDetails.target),

0 commit comments

Comments
 (0)