@@ -29,6 +29,16 @@ public enum ListAction {
29
29
30
30
public extension ListAction {
31
31
32
+ var accessibilityLabel : String {
33
+ switch self {
34
+ case . call( let url) : " Call \( url) "
35
+ case . copy( let text) : " Copy \( text. prefix ( 10 ) ) "
36
+ case . copyImage: " Copy Image "
37
+ case . email( let addr) : " Email \( addr) "
38
+ case . openUrl( let url) : " Open \( url) "
39
+ }
40
+ }
41
+
32
42
@ViewBuilder
33
43
var button : some View {
34
44
button {
@@ -41,16 +51,11 @@ public extension ListAction {
41
51
@ViewBuilder content: @escaping ( ) -> Content
42
52
) -> some View {
43
53
switch self {
44
- case . call( let url) :
45
- link ( url: . init( string: " tel: \( url) " ) , content: content)
46
- case . copy( let text) :
47
- button ( action: { copy ( text) } , content: content)
48
- case . copyImage( let image) :
49
- button ( action: { copy ( image) } , content: content)
50
- case . email( let url) :
51
- link ( url: . init( string: " mailto: \( url) " ) , content: content)
52
- case . openUrl( let url) :
53
- link ( url: . init( string: url) , content: content)
54
+ case . call( let url) : link ( for: calllUrl ( for: url) , content)
55
+ case . copy( let text) : button ( { copy ( text) } , content: content)
56
+ case . copyImage( let img) : button ( { copy ( img) } , content: content)
57
+ case . email( let addr) : link ( for: emailUrl ( for: addr) , content)
58
+ case . openUrl( let str) : link ( for: url ( for: str) , content)
54
59
}
55
60
}
56
61
@@ -64,21 +69,37 @@ public extension ListAction {
64
69
}
65
70
}
66
71
72
+ private extension ListAction {
73
+
74
+ func emailUrl( for url: String ) -> URL ? {
75
+ . init( string: " mailto: \( url) " )
76
+ }
77
+
78
+ func calllUrl( for url: String ) -> URL ? {
79
+ . init( string: " tel: \( url) " )
80
+ }
81
+
82
+ func url( for url: String ) -> URL ? {
83
+ . init( string: url)
84
+ }
85
+ }
86
+
67
87
private extension ListAction {
68
88
69
89
func button< Content: View > (
70
- action: @escaping ( ) -> Void ,
90
+ _ action: @escaping ( ) -> Void ,
71
91
@ViewBuilder content: @escaping ( ) -> Content
72
92
) -> some View {
73
93
Button ( action: action) {
74
94
content ( )
75
95
}
96
+ . accessibilityHint ( Text ( accessibilityLabel) )
76
97
}
77
98
78
99
@ViewBuilder
79
100
func link< Content: View > (
80
- url: URL ? ,
81
- @ViewBuilder content: @escaping ( ) -> Content
101
+ for url: URL ? ,
102
+ @ViewBuilder _ content: @escaping ( ) -> Content
82
103
) -> some View {
83
104
if let url {
84
105
Link ( destination: url) {
0 commit comments