Skip to content

Commit 5f6e068

Browse files
committed
Add new list action
1 parent 546c0ef commit 5f6e068

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

RELEASE_NOTES.md

+9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ SwiftUIKit makes its best effort to honor semver, but breaking changes can occur
44

55

66

7+
## 5.1.2
8+
9+
### ✨ Features
10+
11+
* `ListAction` has a new `copyImage` action.
12+
13+
14+
715
## 5.1.1
816

917
### ✨ Features
1018

1119
* `StandardButtonType` adds even more standard button shortcuts.
1220

1321

22+
1423
## 5.1
1524

1625
### ✨ Features

Sources/SwiftUIKit/Lists/ListAction.swift

+29-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
//
2-
// FormQuickAction.swift
2+
// ListAction.swift
33
// SwiftUIKit
44
//
55
// Created by Daniel Saidi on 2023-11-21.
66
//
77

88
import SwiftUI
99

10-
/**
11-
This enum defines quick list actions, that can be triggered
12-
within a form or list.
13-
14-
Use the various view builders like ``button(content:)`` and
15-
``button`` to get a view that triggers the action.
16-
*/
10+
/// This enum defines actions that can be triggered within a
11+
/// form or a list.
1712
public enum ListAction {
1813

19-
/// Call a certain phone number.
14+
/// Call a phone number.
2015
case call(phoneNumber: String)
2116

22-
/// Copy a certain value.
17+
/// Copy a text.
2318
case copy(String)
2419

25-
/// Email a certain address.
20+
/// Copy an image.
21+
case copyImage(ImageRepresentable)
22+
23+
/// Send an e-mail.
2624
case email(address: String)
2725

2826
/// Open a certain URL.
29-
case open(url: String)
27+
case openUrl(_ url: String)
3028
}
3129

3230
public extension ListAction {
@@ -47,19 +45,21 @@ public extension ListAction {
4745
link(url: .init(string: "tel:\(url)"), content: content)
4846
case .copy(let text):
4947
button(action: { copy(text) }, content: content)
48+
case .copyImage(let image):
49+
button(action: { copy(image) }, content: content)
5050
case .email(let url):
5151
link(url: .init(string: "mailto:\(url)"), content: content)
52-
case .open(let url):
52+
case .openUrl(let url):
5353
link(url: .init(string: url), content: content)
5454
}
5555
}
5656

5757
var icon: Image {
5858
switch self {
5959
case .call: .init(systemName: "phone")
60-
case .copy: .init(systemName: "doc.on.doc")
60+
case .copy, .copyImage: .init(systemName: "doc.on.doc")
6161
case .email: .init(systemName: "envelope")
62-
case .open: .init(systemName: "safari")
62+
case .openUrl: .init(systemName: "safari")
6363
}
6464
}
6565
}
@@ -91,12 +91,23 @@ private extension ListAction {
9191
private extension ListAction {
9292

9393
func copy(_ value: String) {
94-
#if os(macOS) || os(iOS)
94+
#if os(macOS) || os(iOS) || os(visionOS)
9595
Pasteboard.general.copy(value)
9696
#else
9797
print("Unsupported platform")
9898
#endif
9999
}
100+
101+
func copy(_ image: ImageRepresentable) {
102+
#if os(iOS) || os(visionOS)
103+
Pasteboard.general.image = image
104+
#elseif os(macOS)
105+
Pasteboard.general.clearContents()
106+
Pasteboard.general.writeObjects([image])
107+
#else
108+
print("Unsupported platform")
109+
#endif
110+
}
100111
}
101112

102113
#Preview {
@@ -107,10 +118,10 @@ private extension ListAction {
107118

108119
return List {
109120
view(for: .call(phoneNumber: "abc123"))
110-
#if os(macOS) || os(iOS)
121+
#if os(macOS) || os(iOS) || os(visionOS)
111122
view(for: .copy("abc123"))
112123
#endif
113124
view(for: .email(address: "abc123"))
114-
view(for: .open(url: "https://danielsaidi.com"))
125+
view(for: .openUrl("https://danielsaidi.com"))
115126
}
116127
}

Sources/SwiftUIKit/Lists/ListActionRow.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// FormText.swift
2+
// ListActionRow.swift
33
// SwiftUIKit
44
//
55
// Created by Daniel Saidi on 2021-08-03.

Sources/SwiftUIKit/Lists/ListButtonGroup.swift

-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ public struct ListButtonGroup<Content: View>: View {
6262

6363
Section {
6464
Text("Preview.Row")
65-
Text("Preview.Row")
66-
Text("Preview.Row")
67-
Text("Preview.Row")
6865
}
6966
}
7067
}

0 commit comments

Comments
 (0)