Skip to content

Commit

Permalink
Fix for issue #7, update copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantannar4 committed Jul 6, 2018
1 parent a6787e2 commit 8d0c2a2
Show file tree
Hide file tree
Showing 15 changed files with 1,092 additions and 90 deletions.
8 changes: 8 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
3821ADD220EF3DE100DE0D1D /* Lorem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3821ADD020EF3DE100DE0D1D /* Lorem.swift */; };
3821ADD320EF3DE100DE0D1D /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3821ADD120EF3DE100DE0D1D /* Random.swift */; };
386FB1B320C49B71006A93BA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 386FB1B220C49B71006A93BA /* AppDelegate.swift */; };
386FB1B520C49B71006A93BA /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 386FB1B420C49B71006A93BA /* ExampleViewController.swift */; };
386FB1BA20C49B72006A93BA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 386FB1B920C49B72006A93BA /* Assets.xcassets */; };
Expand All @@ -22,6 +24,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3821ADD020EF3DE100DE0D1D /* Lorem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lorem.swift; sourceTree = "<group>"; };
3821ADD120EF3DE100DE0D1D /* Random.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Random.swift; sourceTree = "<group>"; };
386FB1AF20C49B71006A93BA /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
386FB1B220C49B71006A93BA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
386FB1B420C49B71006A93BA /* ExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,6 +85,8 @@
38C2AE8120D48BBF00F8079E /* Style Examples */,
386FB1B920C49B72006A93BA /* Assets.xcassets */,
386FB1BB20C49B72006A93BA /* LaunchScreen.storyboard */,
3821ADD020EF3DE100DE0D1D /* Lorem.swift */,
3821ADD120EF3DE100DE0D1D /* Random.swift */,
386FB1BE20C49B72006A93BA /* Info.plist */,
);
path = Example;
Expand Down Expand Up @@ -226,6 +232,7 @@
buildActionMask = 2147483647;
files = (
38C2AE8920D48BCB00F8079E /* FacebookInputBar.swift in Sources */,
3821ADD220EF3DE100DE0D1D /* Lorem.swift in Sources */,
38C2AE8820D48BCB00F8079E /* iMessageInputBar.swift in Sources */,
38C2AE8B20D48C4C00F8079E /* ImageCell.swift in Sources */,
38C2AE8620D48BCB00F8079E /* GitHawkInputBar.swift in Sources */,
Expand All @@ -234,6 +241,7 @@
38C2AE7E20D488B700F8079E /* SplitViewController.swift in Sources */,
38C2AE8020D4896E00F8079E /* TableViewController.swift in Sources */,
38C2AE8720D48BCB00F8079E /* SlackInputBar.swift in Sources */,
3821ADD320EF3DE100DE0D1D /* Random.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "3"
version = "2.0">
</Bucket>
31 changes: 23 additions & 8 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
//
// AppDelegate.swift
// Example
//
// Created by Nathan Tannar on 2018-06-03.
// Copyright © 2018 MessageKit. All rights reserved.
//

/*
MIT License
Copyright (c) 2017-2018 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

@UIApplicationMain
Expand Down
174 changes: 166 additions & 8 deletions Example/Example/ExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//
// ExampleViewController.swift
// Example
//
// Created by Nathan Tannar on 2018-06-03.
// Copyright © 2018 MessageKit. All rights reserved.
//
/*
MIT License
Copyright (c) 2017-2018 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 MessageInputBar
Expand Down Expand Up @@ -39,6 +55,25 @@ final class ExampleViewController: UITableViewController {
return true
}

/// The object that manages attachments
lazy var attachmentManager: AttachmentManager = { [unowned self] in
let manager = AttachmentManager()
manager.delegate = self
return manager
}()

/// The object that manages autocomplete
lazy var autocompleteManager: AutocompleteManager = { [unowned self] in
let manager = AutocompleteManager(for: self.messageInputBar.inputTextView)
manager.delegate = self
manager.dataSource = self
return manager
}()

let users = ["nathantannar4", "SD10"]

let hastags = ["MessageKit", "MessageInputBar"]

// MARK: - MessageInputBar

private let messageInputBar: MessageInputBar
Expand All @@ -59,8 +94,15 @@ final class ExampleViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
messageInputBar.delegate = self
tableView.keyboardDismissMode = .interactive
messageInputBar.delegate = self
messageInputBar.plugins = [attachmentManager, autocompleteManager]

autocompleteManager.register(prefix: "@", with: [.font: UIFont.preferredFont(forTextStyle: .body),.foregroundColor: UIColor(red: 0, green: 122/255, blue: 1, alpha: 1),.backgroundColor: UIColor(red: 0, green: 122/255, blue: 1, alpha: 0.1)])
autocompleteManager.register(prefix: "#")

// Want to return custom cells? Set the dataSource
// attachmentManager.dataSource = self
}

}
Expand All @@ -83,3 +125,119 @@ extension ExampleViewController: MessageInputBarDelegate {

}

extension ExampleViewController: AttachmentManagerDelegate {


// MARK: - AttachmentManagerDelegate

func attachmentManager(_ manager: AttachmentManager, shouldBecomeVisible: Bool) {
setAttachmentManager(active: shouldBecomeVisible)
}

func attachmentManager(_ manager: AttachmentManager, didReloadTo attachments: [AttachmentManager.Attachment]) {
messageInputBar.sendButton.isEnabled = manager.attachments.count > 0
}

func attachmentManager(_ manager: AttachmentManager, didInsert attachment: AttachmentManager.Attachment, at index: Int) {
messageInputBar.sendButton.isEnabled = manager.attachments.count > 0
}

func attachmentManager(_ manager: AttachmentManager, didRemove attachment: AttachmentManager.Attachment, at index: Int) {
messageInputBar.sendButton.isEnabled = manager.attachments.count > 0
}

func attachmentManager(_ manager: AttachmentManager, didSelectAddAttachmentAt index: Int) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true, completion: nil)
}

// MARK: - AttachmentManagerDelegate Helper

func setAttachmentManager(active: Bool) {

let topStackView = messageInputBar.topStackView
if active && !topStackView.arrangedSubviews.contains(attachmentManager.attachmentView) {
topStackView.insertArrangedSubview(attachmentManager.attachmentView, at: topStackView.arrangedSubviews.count)
topStackView.layoutIfNeeded()
} else if !active && topStackView.arrangedSubviews.contains(attachmentManager.attachmentView) {
topStackView.removeArrangedSubview(attachmentManager.attachmentView)
topStackView.layoutIfNeeded()
}
}
}

extension ExampleViewController: AutocompleteManagerDelegate, AutocompleteManagerDataSource {

// MARK: - AutocompleteManagerDataSource

func autocompleteManager(_ manager: AutocompleteManager, autocompleteSourceFor prefix: String) -> [AutocompleteCompletion] {
if prefix == "@" {
return users.map { AutocompleteCompletion($0) }
} else if prefix == "#" {
return hastags.map { AutocompleteCompletion($0) }
}
return []
}

func autocompleteManager(_ manager: AutocompleteManager, tableView: UITableView, cellForRowAt indexPath: IndexPath, for session: AutocompleteSession) -> UITableViewCell {

guard let cell = tableView.dequeueReusableCell(withIdentifier: AutocompleteCell.reuseIdentifier, for: indexPath) as? AutocompleteCell else {
fatalError("Oops, some unknown error occurred")
}
cell.textLabel?.attributedText = manager.attributedText(matching: session, fontSize: 15)
return cell
}

// MARK: - AutocompleteManagerDelegate

func autocompleteManager(_ manager: AutocompleteManager, shouldBecomeVisible: Bool) {
setAutocompleteManager(active: shouldBecomeVisible)
}

// Optional
func autocompleteManager(_ manager: AutocompleteManager, shouldRegister prefix: String, at range: NSRange) -> Bool {
return true
}

// Optional
func autocompleteManager(_ manager: AutocompleteManager, shouldUnregister prefix: String) -> Bool {
return true
}

// Optional
func autocompleteManager(_ manager: AutocompleteManager, shouldComplete prefix: String, with text: String) -> Bool {
return true
}

// MARK: - AutocompleteManagerDelegate Helper

func setAutocompleteManager(active: Bool) {

let topStackView = messageInputBar.topStackView
if active && !topStackView.arrangedSubviews.contains(autocompleteManager.tableView) {
topStackView.insertArrangedSubview(autocompleteManager.tableView, at: topStackView.arrangedSubviews.count)
topStackView.layoutIfNeeded()
} else if !active && topStackView.arrangedSubviews.contains(autocompleteManager.tableView) {
topStackView.removeArrangedSubview(autocompleteManager.tableView)
topStackView.layoutIfNeeded()
}
}

}

extension ExampleViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

dismiss(animated: true, completion: {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
let handled = self.attachmentManager.handleInput(of: pickedImage)
if !handled {
// throw error
}
}
})
}
}
49 changes: 23 additions & 26 deletions Example/Example/ImageCell.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
//
// ImageCell.swift
// Example
//
// Copyright © 2017-2018 Nathan Tannar.
//
// 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.
//
// Created by Nathan Tannar on 1/29/18.
//
/*
MIT License
Copyright (c) 2017-2018 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

Expand Down
Loading

0 comments on commit 8d0c2a2

Please sign in to comment.