Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
add option to showsBorder
Browse files Browse the repository at this point in the history
  • Loading branch information
HarriesChen committed Mar 10, 2016
1 parent 13fecb5 commit 700fb62
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
9 changes: 8 additions & 1 deletion MessageKit/BaseMessageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public protocol MessageModelProtocol: MessageItemProtocol {

var senderId: String { get }
var isIncoming: Bool { get }
var showsBorder: Bool { get }
var date: NSDate { get }
var status: MessageStatus { get set }
var avatarClosure: AvatarClosure? { get }
Expand All @@ -46,6 +47,10 @@ public extension DecoratedMessageModelProtocol {
return self.messageModel.isIncoming
}

var showsBorder: Bool {
return self.messageModel.showsBorder
}

var date: NSDate {
return self.messageModel.date
}
Expand All @@ -68,16 +73,18 @@ public class MessageModel: MessageModelProtocol {
public var uid: String
public var senderId: String
public var type: String
public var showsBorder: Bool
public var isIncoming: Bool
public var date: NSDate
public var status: MessageStatus
public var avatarClosure: AvatarClosure?

public init(uid: String, senderId: String, type: String, isIncoming: Bool, date: NSDate, status: MessageStatus, avatarClosure: AvatarClosure) {
public init(uid: String, senderId: String, type: String, isIncoming: Bool, showsBorder: Bool, date: NSDate, status: MessageStatus, avatarClosure: AvatarClosure) {
self.uid = uid
self.senderId = senderId
self.type = type
self.isIncoming = isIncoming
self.showsBorder = showsBorder
self.date = date
self.status = status
self.avatarClosure = avatarClosure
Expand Down
10 changes: 10 additions & 0 deletions MessageKit/BaseMessageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public protocol MessageViewModelProtocol: class {
var isIncoming: Bool { get }
var showsTail: Bool { get set }
var showsFailedIcon: Bool { get }
var showsBorder: Bool { get }
var date: String { get }
var status: MessageViewModelStatus { get }
var messageModel: MessageModelProtocol { get }
Expand All @@ -53,6 +54,11 @@ extension DecoratedMessageViewModelProtocol {
self.messageViewModel.showsTail = newValue
}
}

public var showsBorder: Bool {
return self.messageViewModel.showsBorder
}

public var date: String {
return self.messageViewModel.date
}
Expand Down Expand Up @@ -105,6 +111,10 @@ public class MessageViewModel: MessageViewModelProtocol {
public var avatarClosure: AvatarClosure? {
return self.messageModel.avatarClosure
}

public var showsBorder: Bool {
return self.messageModel.showsBorder
}
}

public class MessageViewModelDefaultBuilder {
Expand Down
10 changes: 7 additions & 3 deletions MessageKit/FileBubbleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ public final class FileBubbleView: UIView, MaximumLayoutWidthSpecificable, Backg
return
}
let bubbleImage = self.fileMessageStyle.bubbleImage(viewModel: viewModel, isSelected: self.selected)
let borderImage = self.fileMessageStyle.bubbleImageBorder(viewModel: viewModel, isSelected: self.selected)
if self.bubbleImageView.image != bubbleImage { self.bubbleImageView.image = bubbleImage }
if self.borderImageView.image != borderImage { self.borderImageView.image = borderImage }
if self.bubbleImageView.image != bubbleImage { self.bubbleImageView.image = bubbleImage }

if viewModel.showsBorder {
let borderImage = self.fileMessageStyle.bubbleImageBorder(viewModel: viewModel, isSelected: self.selected)
if self.borderImageView.image != borderImage { self.borderImageView.image = borderImage }
}

self.coverImageView.image = self.fileMessageStyle.folderImage(viewModel: viewModel, isSelected: self.selected)
self.titleLabel.text = viewModel.fileName
self.titleLabel.font = fileMessageStyle.titleFont(viewModel: viewModel, isSelected: self.selected)
Expand Down
8 changes: 6 additions & 2 deletions MessageKit/TextBubbleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ public final class TextBubbleView: UIView, MaximumLayoutWidthSpecificable, Backg
let font = style.textFont(viewModel: viewModel, isSelected: self.selected)
let textColor = style.textColor(viewModel: viewModel, isSelected: self.selected)
let bubbleImage = self.style.bubbleImage(viewModel: self.textMessageViewModel, isSelected: self.selected)
let borderImage = self.style.bubbleImageBorder(viewModel: self.textMessageViewModel, isSelected: self.selected)
if viewModel.showsBorder {
let borderImage = self.style.bubbleImageBorder(viewModel: self.textMessageViewModel, isSelected: self.selected)
if self.borderImageView.image != borderImage { self.borderImageView.image = borderImage }
}


if self.textView.font != font { self.textView.font = font}
if self.textView.text != viewModel.text {self.textView.text = viewModel.text}
Expand All @@ -130,7 +134,7 @@ public final class TextBubbleView: UIView, MaximumLayoutWidthSpecificable, Backg
]
}
if self.bubbleImageView.image != bubbleImage { self.bubbleImageView.image = bubbleImage}
if self.borderImageView.image != borderImage { self.borderImageView.image = borderImage }

}

private func bubbleImage() -> UIImage {
Expand Down
4 changes: 2 additions & 2 deletions MessageKitDemo/MessageKitDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ViewController: MessageViewController {
status = .Failed
}

let baseMessageModel = MessageModel(uid: m.uid, senderId: m.senderId, type: m.type.rawValue, isIncoming: m.isIncoming, date: NSDate(), status: status, avatarClosure: { imageView in
let baseMessageModel = MessageModel(uid: m.uid, senderId: m.senderId, type: m.type.rawValue, isIncoming: m.isIncoming, showsBorder: false, date: NSDate(), status: status, avatarClosure: { imageView in
imageView.kf_setImageWithURL(NSURL(string: "https://striker.teambition.net/thumbnail/110771552384086e16cb0e32133ba589cf98/w/200/h/200")!, placeholderImage: nil)
})

Expand Down Expand Up @@ -233,7 +233,7 @@ class ViewController: MessageViewController {

let dataSource = FakeDataSource()
var items = self.messageDataSource?.messageItems
let messageModel = MessageModel(uid: "dsfsdf\(Int(arc4random() % 300))", senderId: "dsfsdf", type: "text-message", isIncoming: true, date: NSDate(), status: .Success, avatarClosure: { imageView in
let messageModel = MessageModel(uid: "dsfsdf\(Int(arc4random() % 300))", senderId: "dsfsdf", type: "text-message", isIncoming: true, showsBorder: false, date: NSDate(), status: .Success, avatarClosure: { imageView in

})
let textMessageModel = TextMessageModel(messageModel: messageModel, text: "dsfsdfsdfsdfsdf\(a[randomNumber])")
Expand Down

0 comments on commit 700fb62

Please sign in to comment.