This setting allows you to control where a post can be shared to based on the post origin.
There are five possible targets that a post can be shared to
My feed - The post can be shared to my feed. This option will enable "Share to my timeline" menu when user clicks share button.
Public community - The post can be shared to any public community. This option will enable "Share to group" menu when user clicks share button.
Privatecommunity - The post can be shared to any private community. This option will enable "Share to group" menu when user clicks share button.
External - The post can be shared externally. This option will enable "More options" menu when user clicks share button.
Origin - The post can be shared within the community feed that it was created. If the post was created in either public or private community, this option will enable "Share to group" menu when user clicks share button.
There are four possible origins
My feed post - Posts that were created on my feed. By default, possible sharing targets are My feed, Public community, and Private community.
User feed post - Posts that were created on any other users' feed. By default, possible sharing targets are My feed, Public community, and Private community.
Public community feed post - Posts that were created on any public community. By default, possible sharing targets are My feed, Public community, and Private community.
Private community feed post - Posts that were created on any private community. By default, possible sharing target is Origin.
Usage
You can select a set of targets for each post origin.
// In your AppDelegate class
// Ensure post created in private community cannot be shared elsewhere
let privateCommunityShringTargets: Set<AmityPostSharingTarget> = [.originFeed]
// Allow post created by any other user to be shared anywhere
let publicCommunityShringTargets: Set<AmityPostSharingTarget> = [.myFeed, .originFeed, .publicCommunity, .external]
// Allow post created by logged-in user to be shared anywhere
let myFeedShringTargets: Set<AmityPostSharingTarget> = [.myFeed, .originFeed, .external]
let sharingSettings = AmityPostSharingSettings(privateCommunity: privateCommunityShringTargets, publicCommunity: publicCommunityShringTargets, myFeed: myFeedShringTargets)
AmityUIKitManager.feedUISettings.setPostSharingSettings(settings: sharingSettings)
Post Sharing Events
Based on Post sharing settings, there are up to three post sharing events that can be emitted by UIKit.
Share to my timeline - an event emitted when a user clicks on "Share to my timeline" button.
Share to group - an event emitted when a user clicks on "Share to group" button.
Share externally - an event emitted when a user clicks "More options" button.
Usage
You can choose to intercept one or all of the events and apply your custom behavior.
// In your AppDelegate class
// Create custom event handler class
class CustomFeedEventHandler: AmityFeedEventHandler {
// Event handler for more options
override func sharePostDidTap(from source: AmityViewController, postId: String) {
// generate a link
let urlString = "https://amity.co/posts/\(postId)"
guard let url = URL(string: urlString) else { return }
// create AmityActivityController to share generated link
let viewController = AmityActivityController.make(activityItems: [url])
source.present(viewController, animated: true, completion: nil)
}
// Event handler for share post to group
override func sharePostToGroupDidTap(from source: AmityViewController, postId: String) {
// Handle event here
}
// Event handler for share to my timeline
override func sharePostToMyTimelineDidTap(from source: AmityViewController, postId: String) {
// Handle event here
}
}
...
AmityUIKitManager.feedUISettings.eventHandler = CustomFeedEventHandler()
Post Rendering
Custom Post Rendering
UIKit provides default renderers for the core data types: text, image, and file. It also provides a way to render your own UI for your custom post.
Post Structure:
A single post UI is composed of 1 or more UITableViewCell. This allows reusability of cell components such as header or footer which can be shared by different kinds of posts.
Text Post Structure
This is an example of simple text post which contains 3 tableview cell. Top cell represents the header, middle cell contains text content and bottom cell is footer cell.
Creating UI for custom posts :
There are 3 steps involved in creating custom post renderer.
Step 1: Create your UI using UITableView cells.
class MyPostHeaderCell: UITableViewCell {
// ...
}
class MyPostContentCell: UITableViewCell {
// ...
}
Step 2: Compose a post UI component. For this create a component which conforms to AmityPostComposable protocol.
struct MyCustomPostComponent: AmityPostComposable {
var post: AmityPostModel
// Post data model which you can use to render ui.
init(post: AmityPostModel) {
self.post = post
}
func getComponentCount(for index: Int) -> Int {
return 2
}
func getComponentCell(_ tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
switch indexPath.row {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "my-cell-identifier", for: indexPath) as! MyPostHeaderCell
// ... populate cell data here
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "my-cell-identifier", for: indexPath) as! MyPostContentCell
// ... populate cell data here
return cell
default:
fatalError("indexPath is out of bound")
}
}
// Height for each cell component
func getComponentHeight(indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
}
You can also use our default header cell AmityPostHeaderTableViewCell & default footer cell AmityPostFooterTableViewCell in your custom post component.
Step 3: Register your custom cell & implement datasource.
class YourViewController: UIViewController {
func showFeed() {
// 1.
// Register your cell here. You can register both
// nib as well as class itself.
AmityFeedUISettings.shared.register(UINib(nibName: "PostThumbsupTableViewCell", bundle: nil), forCellReuseIdentifier: "PostThumbsupTableViewCell")
AmityFeedUISettings.shared.dataSource = self
// Showing our feed UI
let feedViewController = AmityGlobalFeedViewController.make()
navigationController?.pushViewController(feedViewController, animated: true)
}
}
extension YourViewController: AmityFeedDataSource {
// 2.
// Provide your rendering component for custom post.
func getUIComponentForPost(post: AmityPostModel, at index: Int) -> AmityPostComposable? {
switch post.dataType {
case "your-data-type":
return MyCustomPostComponent(post: post)
default:
return nil
}
}
}