Skip to content

Commit 728b87b

Browse files
committed
update
1 parent c5ac142 commit 728b87b

File tree

7 files changed

+52
-22
lines changed

7 files changed

+52
-22
lines changed

Sources/sharelink-for-swiftui/ShareLinkButton.swift

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1-
import UIKit
1+
//
2+
// ShareLinkButton.swift
3+
//
4+
//
5+
// Created by Igor on 29.10.2023.
6+
//
7+
28
import SwiftUI
3-
import LinkPresentation
4-
import CoreLocation
5-
import Contacts
69

10+
/// A SwiftUI view that provides a button to share data using `UIActivityViewController`.
11+
@available(iOS 14.0, *)
712
public struct ShareLinkButton<Label: View>: View {
813

14+
/// State to control the presentation of the share sheet.
915
@State private var isPresented: Bool = false
1016

17+
/// The data to be shared. It can include items like text, images, URLs, etc.
1118
private let data: [Any]
1219

20+
/// A closure that provides the label for the button.
1321
private let label: () -> Label
1422

23+
/// Optional custom activities to include in the share sheet.
1524
private let applicationActivities: [UIActivity]?
1625

26+
/// Optional activity types to exclude from the share sheet.
1727
private let excludedActivityTypes: [UIActivity.ActivityType]?
1828

19-
// Initializer for Transportable items using the builder internally
29+
/// Initializer for `Transportable` items using the builder internally.
30+
///
31+
/// - Parameters:
32+
/// - item: The item to be shared, conforming to the `Transportable` protocol.
33+
/// - icon: An optional icon for the item.
34+
/// - title: An optional title for the item.
35+
/// - printAction: A flag to determine if the print action should be included.
36+
/// - applicationActivities: Optional custom activities to include in the share sheet.
37+
/// - excludedActivityTypes: Optional activity types to exclude from the share sheet.
38+
/// - label: A closure that provides the label for the button.
2039
public init<T: Transportable>(
2140
item: T,
2241
icon: UIImage? = nil,
@@ -37,7 +56,13 @@ public struct ShareLinkButton<Label: View>: View {
3756
self.label = label
3857
}
3958

40-
// Initializer for UIActivityItemSource items
59+
/// Initializer for `UIActivityItemSource` items.
60+
///
61+
/// - Parameters:
62+
/// - itemSource: The item source to be shared.
63+
/// - applicationActivities: Optional custom activities to include in the share sheet.
64+
/// - excludedActivityTypes: Optional activity types to exclude from the share sheet.
65+
/// - label: A closure that provides the label for the button.
4166
public init(
4267
itemSource: UIActivityItemSource,
4368
applicationActivities: [UIActivity]? = nil,
@@ -50,6 +75,7 @@ public struct ShareLinkButton<Label: View>: View {
5075
self.label = label
5176
}
5277

78+
/// The content and behavior of the view.
5379
public var body: some View {
5480
Button(action: {
5581
isPresented = true

Sources/sharelink-for-swiftui/error/ShareLinkError.swift

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

Sources/sharelink-for-swiftui/protocol/Transportable.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@ import UIKit
88
import CoreLocation
99

1010
/// Protocol `Transportable` inherits `CustomStringConvertible` for providing textual descriptions of objects.
11+
/// This protocol and its extensions are available only on iOS and available since iOS 14.
12+
@available(iOS 14.0, *)
1113
public protocol Transportable: CustomStringConvertible {}
1214

15+
@available(iOS 14.0, *)
1316
extension String: Transportable {
1417
/// The description of a string is the string itself.
1518
public var description: String { self }
1619
}
1720

21+
@available(iOS 14.0, *)
1822
extension URL: Transportable {
1923
/// The description of a URL is its absolute string representation.
2024
public var description: String { self.absoluteString }
2125
}
2226

27+
@available(iOS 14.0, *)
2328
extension UIImage: Transportable {
2429
/// Property to extract the named parameter from the image description.
2530
var namedParameter: String? {
@@ -39,13 +44,16 @@ extension UIImage: Transportable {
3944
}
4045
}
4146

47+
@available(iOS 14.0, *)
4248
extension Data: Transportable {
4349
/// The description of data is its string representation, or "Data object" if conversion fails.
4450
public var description: String {
4551
return String(data: self, encoding: .utf8) ?? "Data object"
4652
}
4753
}
4854

55+
@available(iOS 14.0, *)
4956
extension NSAttributedString: Transportable {}
5057

58+
@available(iOS 14.0, *)
5159
extension CLLocation: Transportable {}

Sources/sharelink-for-swiftui/uikit/ActivitySheetController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import UIKit
99

1010
/// A custom `UIActivityViewController` subclass that customizes the presentation of the activity sheet.
11-
class ActivitySheetController: UIActivityViewController {
11+
final class ActivitySheetController: UIActivityViewController {
1212

1313
deinit {
1414
#if DEBUG

Sources/sharelink-for-swiftui/uikit/TransportableItem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class TransportableItem<T: Transportable>: NSObject, UIActivityItemSource
3434
///
3535
/// - Parameter activityViewController: The `UIActivityViewController` requesting the placeholder item.
3636
/// - Returns: The item to be shared.
37-
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
37+
public func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
3838
return item
3939
}
4040

@@ -44,15 +44,15 @@ final class TransportableItem<T: Transportable>: NSObject, UIActivityItemSource
4444
/// - activityViewController: The `UIActivityViewController` requesting the item.
4545
/// - activityType: The type of activity requesting the item.
4646
/// - Returns: The item to be shared.
47-
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
47+
public func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
4848
return item
4949
}
5050

5151
/// Provides metadata for the link being shared.
5252
///
5353
/// - Parameter activityViewController: The `UIActivityViewController` requesting the metadata.
5454
/// - Returns: The `LPLinkMetadata` object containing metadata about the item.
55-
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
55+
public func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
5656
let metadata = LPLinkMetadata()
5757

5858
// Set icon if available

Sources/sharelink-for-swiftui/utils/AttributedStringBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import UIKit
99

1010
/// Builder class for creating `NSAttributedString` with custom attributes.
11-
class AttributedStringBuilder {
11+
final class AttributedStringBuilder {
1212

13-
// Private variables for attributes
13+
/// Private variables for attributes
1414
private var font: UIFont = UIFont.systemFont(ofSize: 12)
1515
private var foregroundColor: UIColor = .black
1616

Sources/sharelink-for-swiftui/utils/TransportableItemBuilder.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ final class TransportableItemBuilder<T: Transportable> {
3030
self.item = item
3131
}
3232

33+
// MARK: - API
34+
3335
/// Sets the title for the item.
3436
///
3537
/// - Parameter title: An optional title for the item.
@@ -65,6 +67,8 @@ final class TransportableItemBuilder<T: Transportable> {
6567
+ createPrintFormatterIfNeeded()
6668
}
6769

70+
// MARK: - Private
71+
6872
/// Creates the transportable item based on its type.
6973
///
7074
/// - Returns: An array containing the transportable item.
@@ -108,6 +112,8 @@ final class TransportableItemBuilder<T: Transportable> {
108112
}
109113
}
110114

115+
// MARK: - Fileprivate
116+
111117
/// Resolves the title for the item if it is not provided.
112118
///
113119
/// - Parameters:

0 commit comments

Comments
 (0)