Skip to content

Commit 5b356e5

Browse files
committed
Update README.md
1 parent 5be0889 commit 5b356e5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,41 @@ ShareLinkButton(item: URL(string: "https://example.com")!, icon: UIImage(systemN
7878
## Customization
7979
The button appearance can be customized via the label closure, allowing integration with the design system of the host application. Additionally, developers can specify custom activities or exclude certain activity types to tailor the sharing experience to the app's needs.
8080

81+
## Customizing the ShareLinkButton with UIActivityItemSource
82+
83+
The `ShareLinkButton` in SwiftUI allows developers to customize the sharing experience by providing their own `UIActivityItemSource`. This interface enables precise control over the data shared and its format, depending on the activity type selected by the user. By integrating a custom `UIActivityItemSource` into the `ShareLinkButton`, developers can tailor the content and presentation of shared data across various platforms.
84+
85+
### Example: Customizing Share Content Based on Activity Type
86+
87+
1. **Define a Custom `UIActivityItemSource`**:
88+
Begin by creating a class that conforms to the `UIActivityItemSource` protocol. This class will specify the data to be shared when the share sheet is activated.
89+
90+
```swift
91+
import UIKit
92+
93+
class CustomItemSource: NSObject, UIActivityItemSource {
94+
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
95+
return "Default text"
96+
}
97+
98+
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
99+
if activityType == .postToTwitter {
100+
return "Check out this cool feature!"
101+
} else {
102+
return "Here is something interesting to share."
103+
}
104+
}
105+
106+
func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String {
107+
return "Custom Subject"
108+
}
109+
}
110+
```
111+
```swift
112+
ShareLinkButton(itemSource: CustomItemSource(), label: {
113+
Text("Share with Custom Source")
114+
})
115+
```
116+
81117
## License
82118
This package is licensed under the MIT license. See the LICENSE file for more details.

0 commit comments

Comments
 (0)