Latest | 1.0.8 |
---|---|
Homepage | https://github.com/cyclonesword/parla |
License | MIT |
Platforms | ios 9.0, requires ARC |
Dependencies | SKPhotoBrowser, MobilePlayer |
Frameworks | UIKit, CoreMedia, AVKit, CoreLocation, MapKit, MobileCoreServices |
Authors |
Parla
DOCUMENTATION UNDER CONSTRUCTION
Parla is a modern and user-friendly Chat UI library for iOS. It has been built with flexibility in mind: There are a lot of things that you can change!
It is really easy to use, it requires only little configuration and you are ready to start!
Requirements
- iOS 9.0+
- Swift 5.0
- ARC
Installation
CocoaPods
Just add the ParlaKit dependency to your Podfile:
pod 'ParlaKit'
use_frameworks!
And then in your terminal (positioned in the same directory of your project’s Podfile) run pod install
Carthage
Carthage support will be soon available
Usage
Quick Start Guide
In the view you want to display the Chat UI, set the custom class as ParlaView
:
Don’t forget to bind the ParlaView view with an outlet inside your custom ViewController class.
Then in your ViewController, you need to implement at leat the ParlaViewDatasource
class, but i highly reccomand to bind also the ParlaViewDelegate
to receive notification when the user perform various operations (such us when press the send button, when it is recording a voice message etc.) :
class MyViewController : UIViewController, ParlaViewDataSource, ParlaViewDelegate {
// The main sender. His messages are considered as Outgoing, all the messages of other senders will be considerer as Incoming messages.
var mSender: PSender!
// The array of messages
var messages: [PMessage]!
// The core of the library: The ParlaView class
@IBOutlet var parlaView: ParlaView!
Then in your viewDidLoad add your custom logic, for example:
override func viewDidLoad() {
// The avatars of the senders. If you do not want an avatar pass nil and disable avatar in the config
// class before initializing: Parla.config.avatar.isHidden = true
let domenicoAvatar = PAvatar(withImage: UIImage(named: "domenico.jpeg")!)
let chiaraAvatar = PAvatar(withImage: UIImage(named: "chiara.jpg")!)
// In this example we have 2 message senders
mainSender = Parla.outgoingSender(id: 10, name: "Domenico", avatar: domenicoAvatar)
let chiara = PIncomingSender(id: 11, name: "Chiara", avatar: chiaraAvatar)
let config = Parla.config
config.accessoryButton.preventDefault = false
config.cell.isBottomLabelHidden = false
config.avatar.isHidden = false
// This color will be used if you pass a nil avatar to a sender but do not set the isHidden property to true.
config.avatar.backgroundColor = UIColor.black
// Initialization of ParlaView class
parlaView.initialize(dataSource: self, delegate: self)
// This is a test video taken from the main bundle.
let mondello = Bundle.main.url(forResource: "mondello", withExtension: "mp4")!
// Adding some test messages
self.messages = [
Parla.newTextMessage(id: 1, sender: mainSender, text: "Hi Chiara! How are you? :)"),
Parla.newTextMessage(id: 2, sender: chiara, text: "Hi Domenico, all right! I'm sitting on a deckchiar here in the wonderful beach of Mondello, in Palermo (Italy) :)"),
Parla.newTextMessage(id: 3, sender: mainSender, text: "Waw! Tha's awesome! I can't wait to see a picture of you in this wonderful place!"),
Parla.newImageMessage(id: 4, sender: chiara, image: UIImage(named: "mondello-beach.jpg")!),
Parla.newVideoMessage(id: 5, sender: chiara, videoUrl: mondello),
Parla.newTextMessage(id: 6, sender: mainSender, text: "Amazing, i'm coming right now!"),
]
// Hide the top label every 4 times.
for i in 0 ..< messages.count {
messages[i].isTopLabelActive = (i % 4 == 0)
// messages[i].isTopLabelActive = false
}
Finally, implement the required functions of the ParlaViewDatasource:
func outgoingSender() -> POutgoingSender {
return mainSender
}
func messageForCell(at indexPath: IndexPath, collectionView: UICollectionView) -> PMessage {
return self.messages[indexPath.row]
}
func numberOfMessagesIn(collectionView: UICollectionView) -> Int {
return self.messages.count
}
Optionally, but reccomanded, implement the required functions of the ParlaViewDelegate protocol:
func didTapMessageBubble(at indexPath: IndexPath, message: PMessage, collectionView: UICollectionView) {
// You can choose if the binded action with the tap event should occur.
message.triggerSelection()
print("===>> DID TAP MESSAGE BUBBLE (message.toString) << ===")
}
func didPressSendButton(withMessage message: PMessage, textField: UITextField, collectionView: UICollectionView) {
print("===>> DID PRESS SEND BUTTON (message.toString) << ===")
// ** Example of possible implementation **
self.messages.append(message)
textField.text = ""
collectionView.reloadData()
collectionView.scrollToBottom(animated: true)
// **** //
}
func didPressAccessoryButton(button: UIView, collectionView: UICollectionView) {
print("===>> DID PRESS ACCESSORY BUTTON << ===")
}
Contribution
Contributors are welcome!
Since this is a brand new library, i hope someone will help me with the maintainance of the project and for the future feature releases.
Contact info
If you want to contact me for any information, send me an email at: [email protected]
Latest podspec
{ "name": "ParlaKit", "version": "1.0.8", "summary": "An easy and lightweight chat UI library for iOS", "description": "An easy and lightweight chat UI library for iOS", "homepage": "https://github.com/cyclonesword/parla", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "cyclonesword": "[email protected]" }, "social_media_url": "https://www.linkedin.com/in/domenico-aiello-b044a64a/", "platforms": { "ios": "9.0" }, "source": { "git": "https://github.com/cyclonesword/parla.git", "tag": "1.0.8" }, "source_files": "parla/**/*.{h,m,swift}", "exclude_files": [ "parla/AppDelegate.swift", "parla/Corelib/NewViewController2.swift", "parla/Drawing/TestViewController.swift" ], "resources": [ "parla/Resources/Xib/*.xib", "parla/Resources/*.{xcassets,png,jpg,jpeg}", "parla/Resources/Assets.xcassets" ], "resource_bundles": { "ParlaKit": [ "parla/Resources/Xib/*.xib", "parla/Resources/*.{xcassets,png,jpg,jpeg}", "parla/Resources/Assets.xcassets" ] }, "frameworks": [ "UIKit", "CoreMedia", "AVKit", "CoreLocation", "MapKit", "MobileCoreServices" ], "requires_arc": true, "dependencies": { "SKPhotoBrowser": [ "~> 6.1.0" ], "MobilePlayer": [ "~> 1.3.0" ] }, "pod_target_xcconfig": { "SWIFT_VERSION": "5.0" }, "swift_versions": "5.0", "swift_version": "5.0" }
Sat, 25 May 2019 10:14:05 +0000