Skip to content

Post rendering

Emee Miano edited this page Mar 21, 2022 · 2 revisions

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 blocks. This allows reusability of block components such as header or footer which can be shared by different kinds of posts.

Text post structure

This is an example of an image post which contains three tableview cells. Top cell represents the header, middle cell contains content and bottom cell is footer cell.

📝 For now, we only export footer from UIKit - AmityPostEngagementBar.

Creating UI for custom posts

First, you need to create your custom renderer.

import { AmityPostContainer, AmityPostEngagementBar } from '@amityco/ui-kit';

function CustomPostRenderer({ className, post }) {
  return (
    <AmityPostContainer className={className}>
      ...

      <AmityPostEngagementBar postId={post.postId} />
    </AmityPostContainer>
  );
}

Then, you need to pass your renderer into AmityUiKitProvider

function MyApp() {
  return (
    <AmityUiKitProvider
      postRenderers={{
        customPostDataType: CustomPostRenderer,
        image: CustomImagePostRenderer,
      }}
    >
      ...
    </AmityUiKitProvider>
  );
}
Clone this wiki locally