Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
SD10 committed Sep 21, 2017
1 parent 603a938 commit c3277f7
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions Sources/MessagesViewController.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
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
Expand All @@ -25,44 +25,44 @@
import UIKit

open class MessagesViewController: UIViewController {

// MARK: - Properties

open var messagesCollectionView = MessagesCollectionView(frame: .zero, collectionViewLayout: MessagesCollectionViewFlowLayout())
// MARK: - Properties

open var messagesCollectionView = MessagesCollectionView(frame: .zero, collectionViewLayout: MessagesCollectionViewFlowLayout())

open var messageInputBar = MessageInputBar()

private var messageInputBarCopy: MessageInputBar?

private var isFirstLayout: Bool = true

override open var canBecomeFirstResponder: Bool {
return true
}

override open var inputAccessoryView: UIView? {
override open var canBecomeFirstResponder: Bool {
return true
}

override open var inputAccessoryView: UIView? {
return messageInputBar
}
}

open override var shouldAutorotate: Bool {
return false
}

// MARK: - View Life Cycle
// MARK: - View Life Cycle

open override func viewDidLoad() {
super.viewDidLoad()
open override func viewDidLoad() {
super.viewDidLoad()

automaticallyAdjustsScrollViewInsets = false
automaticallyAdjustsScrollViewInsets = false
view.backgroundColor = .white
messagesCollectionView.keyboardDismissMode = .interactive

setupSubviews()
setupConstraints()
setupSubviews()
setupConstraints()
registerReusableViews()
setupDelegates()
setupDelegates()

}
}

open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
Expand Down Expand Up @@ -91,12 +91,12 @@ open class MessagesViewController: UIViewController {
removeKeyboardObservers()
}

// MARK: - Methods
// MARK: - Methods

private func setupDelegates() {
messagesCollectionView.delegate = self
messagesCollectionView.dataSource = self
}
private func setupDelegates() {
messagesCollectionView.delegate = self
messagesCollectionView.dataSource = self
}

private func registerReusableViews() {

Expand All @@ -123,20 +123,20 @@ open class MessagesViewController: UIViewController {

}

private func setupSubviews() {
view.addSubview(messagesCollectionView)
}
private func setupSubviews() {
view.addSubview(messagesCollectionView)
}

private func setupConstraints() {
messagesCollectionView.translatesAutoresizingMaskIntoConstraints = fals
private func setupConstraints() {
messagesCollectionView.translatesAutoresizingMaskIntoConstraints = false

let top = messagesCollectionView.topAnchor.constraint(equalTo: view.topAnchor, constant: topLayoutGuide.length)
let leading = messagesCollectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor)
let trailing = messagesCollectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
let bottom = messagesCollectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
let top = messagesCollectionView.topAnchor.constraint(equalTo: view.topAnchor, constant: topLayoutGuide.length)
let leading = messagesCollectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor)
let trailing = messagesCollectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
let bottom = messagesCollectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor)

NSLayoutConstraint.activate([top, bottom, trailing, leading])
}
NSLayoutConstraint.activate([top, bottom, trailing, leading])
}

// MARK: - MessageInputBar
// Fixes bug where MessageInputBar text renders after viewDidAppear
Expand All @@ -158,34 +158,34 @@ open class MessagesViewController: UIViewController {

extension MessagesViewController: UICollectionViewDelegateFlowLayout {

public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
guard let messagesFlowLayout = collectionViewLayout as? MessagesCollectionViewFlowLayout else { return .zero }
return messagesFlowLayout.sizeForItem(at: indexPath)
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
guard let messagesFlowLayout = collectionViewLayout as? MessagesCollectionViewFlowLayout else { return .zero }
return messagesFlowLayout.sizeForItem(at: indexPath)
}

}

// MARK: - UICollectionViewDataSource Conformance

extension MessagesViewController: UICollectionViewDataSource {

public func numberOfSections(in collectionView: UICollectionView) -> Int {
guard let collectionView = collectionView as? MessagesCollectionView else { return 0 }
public func numberOfSections(in collectionView: UICollectionView) -> Int {
guard let collectionView = collectionView as? MessagesCollectionView else { return 0 }

// Each message is its own section
return collectionView.messagesDataSource?.numberOfMessages(in: collectionView) ?? 0
}
// Each message is its own section
return collectionView.messagesDataSource?.numberOfMessages(in: collectionView) ?? 0
}

public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
guard let collectionView = collectionView as? MessagesCollectionView else { return 0 }
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
guard let collectionView = collectionView as? MessagesCollectionView else { return 0 }

let messageCount = collectionView.messagesDataSource?.numberOfMessages(in: collectionView) ?? 0
// There will only ever be 1 message per section
return messageCount > 0 ? 1 : 0
let messageCount = collectionView.messagesDataSource?.numberOfMessages(in: collectionView) ?? 0
// There will only ever be 1 message per section
return messageCount > 0 ? 1 : 0

}
}

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

guard let messagesCollectionView = collectionView as? MessagesCollectionView else { return UICollectionViewCell() }
guard let messagesDataSource = messagesCollectionView.messagesDataSource else { fatalError("Please set messagesDataSource") }
Expand Down Expand Up @@ -213,7 +213,7 @@ extension MessagesViewController: UICollectionViewDataSource {
return cell
}

}
}

public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

Expand All @@ -238,7 +238,7 @@ extension MessagesViewController: UICollectionViewDataSource {
guard let messagesCollectionView = collectionView as? MessagesCollectionView else { return .zero }
guard let messagesDataSource = messagesCollectionView.messagesDataSource else { return .zero }
guard let messagesLayoutDelegate = messagesCollectionView.messagesLayoutDelegate else { return .zero }
// Could pose a problem if subclass behaviors allows more than one item per section
// Could pose a problem if subclass behaviors allows more than one item per section
let indexPath = IndexPath(item: 0, section: section)
let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
return messagesLayoutDelegate.headerViewSize(for: message, at: indexPath, in: messagesCollectionView)
Expand All @@ -259,11 +259,11 @@ extension MessagesViewController: UICollectionViewDataSource {
// MARK: - Keyboard Handling

extension MessagesViewController {

fileprivate func addKeyboardObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidChangeState), name: .UIKeyboardWillChangeFrame, object: nil)
}

fileprivate func removeKeyboardObservers() {
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillChangeFrame, object: nil)
}
Expand All @@ -280,7 +280,7 @@ extension MessagesViewController {
let bottomInset = keyboardEndFrame.height > messageInputBar.frame.height ? keyboardEndFrame.height : messageInputBar.frame.height
messagesCollectionView.contentInset.bottom = bottomInset
}

}

}

0 comments on commit c3277f7

Please sign in to comment.