Skip to content

Commit

Permalink
configure ChatLeftTextCellNode
Browse files Browse the repository at this point in the history
  • Loading branch information
nixzhu committed Jul 5, 2016
1 parent 713fef1 commit 6ee31e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Yep/ViewControllers/Chat/CellNodes/ChatBaseCellNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import AsyncDisplayKit

class ChatBaseCellNode: ASCellNode {

var user: User?
var user: User? {
didSet {
if let user = user {
let userAvatar = UserAvatar(userID: user.userID, avatarURLString: user.avatarURLString, avatarStyle: nanoAvatarStyle)
//avatarImageNode.navi_setAvatar(userAvatar, withFadeTransitionDuration: avatarFadeTransitionDuration)
}
}
}
var tapAvatarAction: ((user: User) -> Void)?

lazy var nameNode = ASTextNode()
Expand Down
24 changes: 21 additions & 3 deletions Yep/ViewControllers/Chat/CellNodes/ChatLeftTextCellNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,34 @@ class ChatLeftTextCellNode: ChatBaseCellNode {
textNode.backgroundColor = UIColor.greenColor()
}

func configure(withMessage message: Message, layoutCache: ChatTextCellLayoutCache) {

self.user = message.fromFriend

do {
let text = message.textContent
let attributes = [
NSForegroundColorAttributeName: UIColor.blackColor(),
NSFontAttributeName: UIFont.systemFontOfSize(17)
]
textNode.attributedText = NSAttributedString(string: text, attributes: attributes)
}
}

override func calculateSizeThatFits(constrainedSize: CGSize) -> CGSize {

return CGSize(width: constrainedSize.width, height: 50)
let textMaxWidth = constrainedSize.width - (15 + 40 + 5 + 15)
textNode.measure(CGSize(width: textMaxWidth, height: CGFloat.max))

let height = max(textNode.calculatedSize.height, avatarImageNode.bounds.height)

return CGSize(width: constrainedSize.width, height: height)
}

override func layout() {
super.layout()

avatarImageNode.frame = CGRect(x: 15, y: 0, width: 40, height: 40)
textNode.frame = CGRect(x: 65, y: 0, width: 120, height: 40)
textNode.frame = CGRect(x: 15 + 40 + 5, y: 0, width: textNode.calculatedSize.width, height: textNode.calculatedSize.height)
}
}

0 comments on commit 6ee31e8

Please sign in to comment.