<commit_before>//
//  ViewController.swift
//  Messages
//
//  Created by NIX on 15/7/25.
//  Copyright (c) 2015年 nixWork. All rights reserved.
//

import UIKit
import KeyboardMan

class ViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!

    @IBOutlet weak var toolBar: UIView!
    @IBOutlet weak var toolBarBottomConstraint: NSLayoutConstraint!

    @IBOutlet weak var textField: UITextField!

    var messages: [String] = [
        "How do you do?",
    ]

    let cellID = "cell"

    let keyboardMan = KeyboardMan()

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.rowHeight = 60
        tableView.contentInset.bottom = toolBar.frame.height
        tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellID)
        tableView.tableFooterView = UIView()

        keyboardMan.postKeyboardInfo = { [weak self] keyboardInfo in

            if let strongSelf = self {

                let animationDuration = keyboardInfo.animationDuration
                let animationCurve = keyboardInfo.animationCurve

                switch keyboardInfo.action {

                case .Show:

                    print("show \(keyboardInfo.height), \(keyboardInfo.heightIncrement)\n")

                    UIView.animateWithDuration(animationDuration, delay: 0, options: UIViewAnimationOptions(animationCurve << 16), animations: {

                        strongSelf.tableView.contentOffset.y += keyboardInfo.heightIncrement
                        strongSelf.tableView.contentInset.bottom = keyboardInfo.height + strongSelf.toolBar.frame.height

                        strongSelf.toolBarBottomConstraint.constant = keyboardInfo.height
                        strongSelf.view.layoutIfNeeded()

                    }, completion: nil)

                case .Hide:

                    print("hide \(keyboardInfo.height), \(keyboardInfo.heightIncrement)\n")

                    UIView.animateWithDuration(animationDuration, delay: 0, options: UIViewAnimationOptions(animationCurve << 16), animations: {

                        strongSelf.tableView.contentOffset.y -= keyboardInfo.height - keyboardInfo.heightIncrement
                        strongSelf.tableView.contentInset.bottom = strongSelf.toolBar.frame.height

                        strongSelf.toolBarBottomConstraint.constant = 0
                        strongSelf.view.layoutIfNeeded()

                    }, completion: nil)
                }
            }
        }
    }

    // MARK: - Actions

    func sendMessage(textField: UITextField) {

        let text = textField.text

        if text.isEmpty {
            return
        }

        // update data source

        let message = text
        messages.append(message)

        // insert new row
<commit_msg>animation BeginFromCurrentState<commit_after>//
//  ViewController.swift
//  Messages
//
//  Created by NIX on 15/7/25.
//  Copyright (c) 2015年 nixWork. All rights reserved.
//

import UIKit
import KeyboardMan

class ViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!

    @IBOutlet weak var toolBar: UIView!
    @IBOutlet weak var toolBarBottomConstraint: NSLayoutConstraint!

    @IBOutlet weak var textField: UITextField!

    var messages: [String] = [
        "How do you do?",
    ]

    let cellID = "cell"

    let keyboardMan = KeyboardMan()

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.rowHeight = 60
        tableView.contentInset.bottom = toolBar.frame.height
        tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellID)
        tableView.tableFooterView = UIView()

        keyboardMan.postKeyboardInfo = { [weak self] keyboardInfo in

            if let strongSelf = self {

                let duration = keyboardInfo.animationDuration
                let curve = keyboardInfo.animationCurve
                let options = UIViewAnimationOptions(curve << 16 | UIViewAnimationOptions.BeginFromCurrentState.rawValue)

                switch keyboardInfo.action {

                case .Show:

                    print("show \(keyboardInfo.height), \(keyboardInfo.heightIncrement)\n")

                    UIView.animateWithDuration(duration, delay: 0, options: options, animations: {

                        strongSelf.tableView.contentOffset.y += keyboardInfo.heightIncrement
                        strongSelf.tableView.contentInset.bottom = keyboardInfo.height + strongSelf.toolBar.frame.height

                        strongSelf.toolBarBottomConstraint.constant = keyboardInfo.height
                        strongSelf.view.layoutIfNeeded()

                    }, completion: nil)

                case .Hide:

                    print("hide \(keyboardInfo.height), \(keyboardInfo.heightIncrement)\n")

                    UIView.animateWithDuration(duration, delay: 0, options: options, animations: {

                        strongSelf.tableView.contentOffset.y -= keyboardInfo.height
                        strongSelf.tableView.contentInset.bottom = strongSelf.toolBar.frame.height

                        strongSelf.toolBarBottomConstraint.constant = 0
                        strongSelf.view.layoutIfNeeded()

                    }, completion: nil)
                }
            }
        }
    }

    // MARK: - Actions

    func sendMessage(textField: UITextField) {

        let text = textField.text

        if text.isEmpty {
            return
        }

        // update data source

        let message = text
        messages.append(message)

        // insert new row

{'fraction_non_alphanumeric': 0.08064228367528992, 'fraction_numerical': 0.0060660124888492414, 'mean_word_length': 1.9536354056902, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '749330', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1355, 'n_words': 303}