Define How To Render Each Element

Use the ChatFeedViewBuilder protocol to define how to render each chat feed element.

  1. none renders an empty view.
  2. existing renders our default view.
  3. replace renders the view you provide. For the elements that you set to replace, you must provide a view to render instead of the default view.
Define how to render each element
1struct MyEntryViewBuilder: ChatFeedViewBuilder {
2
3    var renderMode: RenderModeClosure? {
4        return { model in
5            guard let entryModel = model as? ConversationEntryModel else { return .existing }
6            switch entryModel.entry.type {
7            case .participantChanged:
8                if let changed = entryModel.entry.payload as? ParticipantChanged {
9                    if changed.operations.first?.type == .add { return .existing }
10                    else { return .none }
11                } else {
12                    return .existing
13                }
14
15            default: return .replace
16            }
17        }
18    }
19
20    var completeView: CompleteViewClosure? {
21        return { model, client in
22            guard let entryModel = model as? ConversationEntryModel else { return Color.red }
23            switch entryModel.entry.format {
24            case .textMessage: return Color.green
25            case .listPicker: return Color.yellow
26            default: return Color.blue
27            }
28        }
29    }
30}

The preceding example shows how you can use logic on the participantChanged event to set different render modes. It also shows how you can replace the text messages with a green bar and the list pickers with a yellow bar. Similarly, you can define your unique views or our default views for each chat element.