Skip to content

Commit 8d0c2a2

Browse files
committed
Fix for issue #7, update copyright
1 parent a6787e2 commit 8d0c2a2

15 files changed

+1092
-90
lines changed

Diff for: Example/Example.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

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

2426
/* Begin PBXFileReference section */
27+
3821ADD020EF3DE100DE0D1D /* Lorem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lorem.swift; sourceTree = "<group>"; };
28+
3821ADD120EF3DE100DE0D1D /* Random.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Random.swift; sourceTree = "<group>"; };
2529
386FB1AF20C49B71006A93BA /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
2630
386FB1B220C49B71006A93BA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2731
386FB1B420C49B71006A93BA /* ExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = "<group>"; };
@@ -81,6 +85,8 @@
8185
38C2AE8120D48BBF00F8079E /* Style Examples */,
8286
386FB1B920C49B72006A93BA /* Assets.xcassets */,
8387
386FB1BB20C49B72006A93BA /* LaunchScreen.storyboard */,
88+
3821ADD020EF3DE100DE0D1D /* Lorem.swift */,
89+
3821ADD120EF3DE100DE0D1D /* Random.swift */,
8490
386FB1BE20C49B72006A93BA /* Info.plist */,
8591
);
8692
path = Example;
@@ -226,6 +232,7 @@
226232
buildActionMask = 2147483647;
227233
files = (
228234
38C2AE8920D48BCB00F8079E /* FacebookInputBar.swift in Sources */,
235+
3821ADD220EF3DE100DE0D1D /* Lorem.swift in Sources */,
229236
38C2AE8820D48BCB00F8079E /* iMessageInputBar.swift in Sources */,
230237
38C2AE8B20D48C4C00F8079E /* ImageCell.swift in Sources */,
231238
38C2AE8620D48BCB00F8079E /* GitHawkInputBar.swift in Sources */,
@@ -234,6 +241,7 @@
234241
38C2AE7E20D488B700F8079E /* SplitViewController.swift in Sources */,
235242
38C2AE8020D4896E00F8079E /* TableViewController.swift in Sources */,
236243
38C2AE8720D48BCB00F8079E /* SlackInputBar.swift in Sources */,
244+
3821ADD320EF3DE100DE0D1D /* Random.swift in Sources */,
237245
);
238246
runOnlyForDeploymentPostprocessing = 0;
239247
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "3"
4+
version = "2.0">
5+
</Bucket>

Diff for: Example/Example/AppDelegate.swift

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
//
2-
// AppDelegate.swift
3-
// Example
4-
//
5-
// Created by Nathan Tannar on 2018-06-03.
6-
// Copyright © 2018 MessageKit. All rights reserved.
7-
//
8-
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2017-2018 MessageKit
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
924
import UIKit
1025

1126
@UIApplicationMain

Diff for: Example/Example/ExampleViewController.swift

+166-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
//
2-
// ExampleViewController.swift
3-
// Example
4-
//
5-
// Created by Nathan Tannar on 2018-06-03.
6-
// Copyright © 2018 MessageKit. All rights reserved.
7-
//
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2017-2018 MessageKit
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
824

925
import UIKit
1026
import MessageInputBar
@@ -39,6 +55,25 @@ final class ExampleViewController: UITableViewController {
3955
return true
4056
}
4157

58+
/// The object that manages attachments
59+
lazy var attachmentManager: AttachmentManager = { [unowned self] in
60+
let manager = AttachmentManager()
61+
manager.delegate = self
62+
return manager
63+
}()
64+
65+
/// The object that manages autocomplete
66+
lazy var autocompleteManager: AutocompleteManager = { [unowned self] in
67+
let manager = AutocompleteManager(for: self.messageInputBar.inputTextView)
68+
manager.delegate = self
69+
manager.dataSource = self
70+
return manager
71+
}()
72+
73+
let users = ["nathantannar4", "SD10"]
74+
75+
let hastags = ["MessageKit", "MessageInputBar"]
76+
4277
// MARK: - MessageInputBar
4378

4479
private let messageInputBar: MessageInputBar
@@ -59,8 +94,15 @@ final class ExampleViewController: UITableViewController {
5994
override func viewDidLoad() {
6095
super.viewDidLoad()
6196
view.backgroundColor = .white
62-
messageInputBar.delegate = self
6397
tableView.keyboardDismissMode = .interactive
98+
messageInputBar.delegate = self
99+
messageInputBar.plugins = [attachmentManager, autocompleteManager]
100+
101+
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)])
102+
autocompleteManager.register(prefix: "#")
103+
104+
// Want to return custom cells? Set the dataSource
105+
// attachmentManager.dataSource = self
64106
}
65107

66108
}
@@ -83,3 +125,119 @@ extension ExampleViewController: MessageInputBarDelegate {
83125

84126
}
85127

128+
extension ExampleViewController: AttachmentManagerDelegate {
129+
130+
131+
// MARK: - AttachmentManagerDelegate
132+
133+
func attachmentManager(_ manager: AttachmentManager, shouldBecomeVisible: Bool) {
134+
setAttachmentManager(active: shouldBecomeVisible)
135+
}
136+
137+
func attachmentManager(_ manager: AttachmentManager, didReloadTo attachments: [AttachmentManager.Attachment]) {
138+
messageInputBar.sendButton.isEnabled = manager.attachments.count > 0
139+
}
140+
141+
func attachmentManager(_ manager: AttachmentManager, didInsert attachment: AttachmentManager.Attachment, at index: Int) {
142+
messageInputBar.sendButton.isEnabled = manager.attachments.count > 0
143+
}
144+
145+
func attachmentManager(_ manager: AttachmentManager, didRemove attachment: AttachmentManager.Attachment, at index: Int) {
146+
messageInputBar.sendButton.isEnabled = manager.attachments.count > 0
147+
}
148+
149+
func attachmentManager(_ manager: AttachmentManager, didSelectAddAttachmentAt index: Int) {
150+
let imagePicker = UIImagePickerController()
151+
imagePicker.delegate = self
152+
imagePicker.sourceType = .photoLibrary
153+
present(imagePicker, animated: true, completion: nil)
154+
}
155+
156+
// MARK: - AttachmentManagerDelegate Helper
157+
158+
func setAttachmentManager(active: Bool) {
159+
160+
let topStackView = messageInputBar.topStackView
161+
if active && !topStackView.arrangedSubviews.contains(attachmentManager.attachmentView) {
162+
topStackView.insertArrangedSubview(attachmentManager.attachmentView, at: topStackView.arrangedSubviews.count)
163+
topStackView.layoutIfNeeded()
164+
} else if !active && topStackView.arrangedSubviews.contains(attachmentManager.attachmentView) {
165+
topStackView.removeArrangedSubview(attachmentManager.attachmentView)
166+
topStackView.layoutIfNeeded()
167+
}
168+
}
169+
}
170+
171+
extension ExampleViewController: AutocompleteManagerDelegate, AutocompleteManagerDataSource {
172+
173+
// MARK: - AutocompleteManagerDataSource
174+
175+
func autocompleteManager(_ manager: AutocompleteManager, autocompleteSourceFor prefix: String) -> [AutocompleteCompletion] {
176+
if prefix == "@" {
177+
return users.map { AutocompleteCompletion($0) }
178+
} else if prefix == "#" {
179+
return hastags.map { AutocompleteCompletion($0) }
180+
}
181+
return []
182+
}
183+
184+
func autocompleteManager(_ manager: AutocompleteManager, tableView: UITableView, cellForRowAt indexPath: IndexPath, for session: AutocompleteSession) -> UITableViewCell {
185+
186+
guard let cell = tableView.dequeueReusableCell(withIdentifier: AutocompleteCell.reuseIdentifier, for: indexPath) as? AutocompleteCell else {
187+
fatalError("Oops, some unknown error occurred")
188+
}
189+
cell.textLabel?.attributedText = manager.attributedText(matching: session, fontSize: 15)
190+
return cell
191+
}
192+
193+
// MARK: - AutocompleteManagerDelegate
194+
195+
func autocompleteManager(_ manager: AutocompleteManager, shouldBecomeVisible: Bool) {
196+
setAutocompleteManager(active: shouldBecomeVisible)
197+
}
198+
199+
// Optional
200+
func autocompleteManager(_ manager: AutocompleteManager, shouldRegister prefix: String, at range: NSRange) -> Bool {
201+
return true
202+
}
203+
204+
// Optional
205+
func autocompleteManager(_ manager: AutocompleteManager, shouldUnregister prefix: String) -> Bool {
206+
return true
207+
}
208+
209+
// Optional
210+
func autocompleteManager(_ manager: AutocompleteManager, shouldComplete prefix: String, with text: String) -> Bool {
211+
return true
212+
}
213+
214+
// MARK: - AutocompleteManagerDelegate Helper
215+
216+
func setAutocompleteManager(active: Bool) {
217+
218+
let topStackView = messageInputBar.topStackView
219+
if active && !topStackView.arrangedSubviews.contains(autocompleteManager.tableView) {
220+
topStackView.insertArrangedSubview(autocompleteManager.tableView, at: topStackView.arrangedSubviews.count)
221+
topStackView.layoutIfNeeded()
222+
} else if !active && topStackView.arrangedSubviews.contains(autocompleteManager.tableView) {
223+
topStackView.removeArrangedSubview(autocompleteManager.tableView)
224+
topStackView.layoutIfNeeded()
225+
}
226+
}
227+
228+
}
229+
230+
extension ExampleViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
231+
232+
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
233+
234+
dismiss(animated: true, completion: {
235+
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
236+
let handled = self.attachmentManager.handleInput(of: pickedImage)
237+
if !handled {
238+
// throw error
239+
}
240+
}
241+
})
242+
}
243+
}

Diff for: Example/Example/ImageCell.swift

+23-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
//
2-
// ImageCell.swift
3-
// Example
4-
//
5-
// Copyright © 2017-2018 Nathan Tannar.
6-
//
7-
// Permission is hereby granted, free of charge, to any person obtaining a copy
8-
// of this software and associated documentation files (the "Software"), to deal
9-
// in the Software without restriction, including without limitation the rights
10-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
// copies of the Software, and to permit persons to whom the Software is
12-
// furnished to do so, subject to the following conditions:
13-
//
14-
// The above copyright notice and this permission notice shall be included in all
15-
// copies or substantial portions of the Software.
16-
//
17-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
// SOFTWARE.
24-
//
25-
// Created by Nathan Tannar on 1/29/18.
26-
//
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2017-2018 MessageKit
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
2724

2825
import UIKit
2926

0 commit comments

Comments
 (0)