@@ -29,6 +29,16 @@ public enum ListAction {
2929
3030public extension ListAction {
3131
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+
3242 @ViewBuilder
3343 var button : some View {
3444 button {
@@ -41,16 +51,11 @@ public extension ListAction {
4151 @ViewBuilder content: @escaping ( ) -> Content
4252 ) -> some View {
4353 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)
5459 }
5560 }
5661
@@ -64,21 +69,37 @@ public extension ListAction {
6469 }
6570}
6671
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+
6787private extension ListAction {
6888
6989 func button< Content: View > (
70- action: @escaping ( ) -> Void ,
90+ _ action: @escaping ( ) -> Void ,
7191 @ViewBuilder content: @escaping ( ) -> Content
7292 ) -> some View {
7393 Button ( action: action) {
7494 content ( )
7595 }
96+ . accessibilityHint ( Text ( accessibilityLabel) )
7697 }
7798
7899 @ViewBuilder
79100 func link< Content: View > (
80- url: URL ? ,
81- @ViewBuilder content: @escaping ( ) -> Content
101+ for url: URL ? ,
102+ @ViewBuilder _ content: @escaping ( ) -> Content
82103 ) -> some View {
83104 if let url {
84105 Link ( destination: url) {
0 commit comments