Skip to content

Commit

Permalink
Add LocationMessageCell
Browse files Browse the repository at this point in the history
  • Loading branch information
SD10 committed Sep 18, 2017
1 parent 4caea44 commit e15f9f4
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 60 deletions.
8 changes: 8 additions & 0 deletions MessageKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
989BBFFE1F6682FD0068D79A /* bubble_outlined_tail_v2.png in Resources */ = {isa = PBXBuildFile; fileRef = 989BBFEC1F6682FD0068D79A /* bubble_outlined_tail_v2.png */; };
989BBFFF1F6682FD0068D79A /* bubble_outlined_tail_v2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 989BBFED1F6682FD0068D79A /* bubble_outlined_tail_v2@2x.png */; };
989BC0001F6682FD0068D79A /* bubble_outlined_tail_v2@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 989BBFEE1F6682FD0068D79A /* bubble_outlined_tail_v2@3x.png */; };
B01049101F6F8684008DBA58 /* PlayButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B010490F1F6F8684008DBA58 /* PlayButtonView.swift */; };
B01049121F6F86E8008DBA58 /* LocationMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B01049111F6F86E8008DBA58 /* LocationMessageCell.swift */; };
B01280F31F4E8798004BCD3E /* MessageLabelDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B01280F21F4E8798004BCD3E /* MessageLabelDelegate.swift */; };
B0147C831F5BE9220035B36E /* Bundle+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0147C821F5BE9220035B36E /* Bundle+Extensions.swift */; };
B0147C901F5ED0810035B36E /* MessageDateHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0147C8F1F5ED0810035B36E /* MessageDateHeaderView.swift */; };
Expand Down Expand Up @@ -121,6 +123,8 @@
989BBFEC1F6682FD0068D79A /* bubble_outlined_tail_v2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bubble_outlined_tail_v2.png; sourceTree = "<group>"; };
989BBFED1F6682FD0068D79A /* bubble_outlined_tail_v2@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bubble_outlined_tail_v2@2x.png"; sourceTree = "<group>"; };
989BBFEE1F6682FD0068D79A /* bubble_outlined_tail_v2@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bubble_outlined_tail_v2@3x.png"; sourceTree = "<group>"; };
B010490F1F6F8684008DBA58 /* PlayButtonView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayButtonView.swift; sourceTree = "<group>"; };
B01049111F6F86E8008DBA58 /* LocationMessageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationMessageCell.swift; sourceTree = "<group>"; };
B01280F21F4E8798004BCD3E /* MessageLabelDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageLabelDelegate.swift; sourceTree = "<group>"; };
B0147C821F5BE9220035B36E /* Bundle+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+Extensions.swift"; sourceTree = "<group>"; };
B0147C8F1F5ED0810035B36E /* MessageDateHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageDateHeaderView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -305,6 +309,8 @@
B0147C8F1F5ED0810035B36E /* MessageDateHeaderView.swift */,
B0291DA81F6DBB9F00BEDF03 /* TextMessageCell.swift */,
B0D943BD1F6DC9AB008B7BFD /* MediaMessageCell.swift */,
B010490F1F6F8684008DBA58 /* PlayButtonView.swift */,
B01049111F6F86E8008DBA58 /* LocationMessageCell.swift */,
);
name = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -497,6 +503,7 @@
171D5AB91F36712B0053DF69 /* InputTextView.swift in Sources */,
B0147C901F5ED0810035B36E /* MessageDateHeaderView.swift in Sources */,
38C8679E1F50EA4A00811974 /* InputBarItem.swift in Sources */,
B01049121F6F86E8008DBA58 /* LocationMessageCell.swift in Sources */,
B074EE971F355FBC00ABB8C8 /* MessagesLayoutDelegate.swift in Sources */,
38C8679A1F50EA1000811974 /* NSConstraintLayoutSet.swift in Sources */,
882D75841DE507320033F95F /* MessagesDataSource.swift in Sources */,
Expand All @@ -506,6 +513,7 @@
B0655A4F1F245C5A00542A83 /* MessagesCollectionViewFlowLayout.swift in Sources */,
B0655A2C1F23D81600542A83 /* MessageData.swift in Sources */,
B0E1756F1F655A1600F0DEF6 /* AvatarHorizontalAlignment.swift in Sources */,
B01049101F6F8684008DBA58 /* PlayButtonView.swift in Sources */,
B09643861F286C9E004D0129 /* String+Extensions.swift in Sources */,
B015E81F1F259D8E007EDFB6 /* MessageInputBarDelegate.swift in Sources */,
B01280F31F4E8798004BCD3E /* MessageLabelDelegate.swift in Sources */,
Expand Down
30 changes: 30 additions & 0 deletions Sources/LocationMessageCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
MIT License

Copyright (c) 2017 MessageKit

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import UIKit
import MapKit

open class LocationMessageCell: MessageCollectionViewCell<MKMapView> {

}
66 changes: 6 additions & 60 deletions Sources/MediaMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,77 +24,24 @@

import UIKit

open class PlayButtonView: UIView {

override open var frame: CGRect {
didSet {
commonSetup()
}
}

let triangleView: UIView = {
let triangleView = UIView()
triangleView.layer.masksToBounds = true
triangleView.clipsToBounds = true
return triangleView
}()

func triangleMask(for frame: CGRect) -> CAShapeLayer {
let shapeLayer = CAShapeLayer()
let trianglePath = UIBezierPath()
let point1 = CGPoint(x: frame.minX, y: frame.minY)
let point2 = CGPoint(x: frame.maxX, y: frame.maxY/2)
let point3 = CGPoint(x: frame.minX, y: frame.maxY)
trianglePath .move(to: point1)
trianglePath .addLine(to: point2)
trianglePath .addLine(to: point3)
trianglePath .close()
shapeLayer.path = trianglePath.cgPath
return shapeLayer
}

override public init(frame: CGRect) {
super.init(frame: frame)
setupSubviews()
commonSetup()
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func setupSubviews() {
addSubview(triangleView)
}

func commonSetup() {

let size = CGSize(width: frame.width/2, height: frame.height/2)
triangleView.bounds.size = size
triangleView.layer.mask = triangleMask(for: triangleView.bounds)

let centerOffset = triangleView.bounds.width/8
triangleView.center = CGPoint(x: center.x + centerOffset, y: center.y)

layer.cornerRadius = frame.width / 2
layer.masksToBounds = true
}

}

open class MediaMessageCell: MessageCollectionViewCell<UIImageView> {

open lazy var playButtonView: PlayButtonView = {
let playButtonView = PlayButtonView()
playButtonView.triangleView.backgroundColor = .black
playButtonView.backgroundColor = .playButtonLightGray
playButtonView.frame = CGRect(origin: .zero, size: CGSize(width: 35, height: 35))
playButtonView.frame.size = CGSize(width: 35, height: 35)
return playButtonView
}()

override func setupSubviews() {
super.setupSubviews()
messageContentView.addSubview(playButtonView)
playButtonView.translatesAutoresizingMaskIntoConstraints = false
playButtonView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
playButtonView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
playButtonView.widthAnchor.constraint(equalToConstant: 35).isActive = true
playButtonView.heightAnchor.constraint(equalToConstant: 35).isActive = true
}

override open func configure(with message: MessageType, at indexPath: IndexPath, and messagesCollectionView: MessagesCollectionView) {
Expand All @@ -106,7 +53,6 @@ open class MediaMessageCell: MessageCollectionViewCell<UIImageView> {
case .video(_, let image):
messageContentView.image = image
playButtonView.isHidden = false
playButtonView.center = messageContentView.center
default:
break
}
Expand Down
89 changes: 89 additions & 0 deletions Sources/PlayButtonView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
MIT License

Copyright (c) 2017 MessageKit

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import UIKit

open class PlayButtonView: UIView {

override open var frame: CGRect {
didSet {
commonSetup()
}
}

override open var bounds: CGRect {
didSet {
commonSetup()
}
}

open let triangleView: UIView = {
let triangleView = UIView()
triangleView.layer.masksToBounds = true
triangleView.clipsToBounds = true
return triangleView
}()

private func triangleMask(for frame: CGRect) -> CAShapeLayer {
let shapeLayer = CAShapeLayer()
let trianglePath = UIBezierPath()
let point1 = CGPoint(x: frame.minX, y: frame.minY)
let point2 = CGPoint(x: frame.maxX, y: frame.maxY/2)
let point3 = CGPoint(x: frame.minX, y: frame.maxY)
trianglePath .move(to: point1)
trianglePath .addLine(to: point2)
trianglePath .addLine(to: point3)
trianglePath .close()
shapeLayer.path = trianglePath.cgPath
return shapeLayer
}

override public init(frame: CGRect) {
super.init(frame: frame)
setupSubviews()
commonSetup()
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupSubviews() {
addSubview(triangleView)
}

private func commonSetup() {

let size = CGSize(width: frame.width/2, height: frame.height/2)
triangleView.bounds.size = size
triangleView.layer.mask = triangleMask(for: triangleView.bounds)

let centerOffset = triangleView.bounds.width/8
triangleView.center = CGPoint(x: center.x + centerOffset, y: center.y)

layer.cornerRadius = frame.width / 2
layer.masksToBounds = true
}

}

0 comments on commit e15f9f4

Please sign in to comment.