[doc] add examples of headerNode/footerNode usage to readme
Opened this issue · 1 comments
dodikk commented
[doc] add examples of headerNode/footerNode usage to readme
dodikk commented
Here is a snippet for adding an avatar and user name to the headerView
of the MessageNode
internal static func addAvatar(
withUrl strAvatarUrl: String?,
userName: String,
toCell result: MessageNode,
isIncoming isIncomingMessage: Bool,
parentVC: ChatRoomView,
imageLoader: ASImageDownloaderProtocol,
imageCache: ASImageCacheProtocol)
{
let isMessageHasAvatar = (nil != strAvatarUrl)
let maybeAvatarUrl = strAvatarUrl.flatMap(URL.init(string:))
let isShowingIcon =
isMessageHasAvatar &&
(isIncomingMessage || self._shouldShowMyAvatar) // HPV-2455 - do not show My Avatar in a chat
guard isShowingIcon
else
{
return
}
// ==
//
let avatarAndUserNameBuilder: ASDisplayNodeViewBlock =
{
() -> UIView in
let nib =
UINib(
nibName: "VHChatMessageHeaderView",
bundle: Bundle.main)
let nibObjects =
nib.instantiate(
withOwner: nil,
options: nil)
let userInfoView = nibObjects.first as! VHChatMessageHeaderView
// inject data
//
userInfoView.avatarView?.image = nil
if let avatarUrl = maybeAvatarUrl
{
userInfoView.avatarView?.setImage(mediaURL: avatarUrl)
}
userInfoView.usernameLabel?.text = userName
return userInfoView
}
let avatarAndUserName = ASDisplayNode(viewBlock: avatarAndUserNameBuilder)
avatarAndUserName.style.preferredSize = CGSize(width: 375, height: 24)
result.headerNode = avatarAndUserName
}
P.S. I could not make it render unless avatarAndUserName.style.preferredSize
was specified