<commit_before>//
//  KeyboardConstraintAdjuster.swift
//  SwiftPlusPlus
//
//  Created by <NAME> on 11/6/15.
//  Copyright © 2015 Drewag LLC. All rights reserved.
//

import Foundation

public class KeyboardConstraintAdjuster: NSObject {
    @IBOutlet public var constraint: NSLayoutConstraint!
    @IBOutlet public var view: UIView!

    @IBInspectable public var offset: CGFloat = 0

    public var onKeyboardIsBeingShown: (() -> ())?
    public var onKeyboardWasShown: (() -> ())?

    override public func awakeFromNib() {
        super.awakeFromNib()

        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)
    }

    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
    }

    // MARK: Notifications

    func keyboardWillShow(notification: NSNotification) {
        let frame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey]?.CGRectValue
        let options = UIViewAnimationOptions(rawValue: UInt((notification.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).integerValue << 16))
        let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue
        if frame != nil && duration != nil {
            self.onKeyboardIsBeingShown?()
            UIView.animateWithDuration(
                duration!,
                delay: 0,
                options: options,
                animations: { () -> Void in
                    self.constraint.constant = frame!.size.height + self.offset
                    self.view.layoutIfNeeded()
                },
                completion: { _ in
                    self.onKeyboardWasShown?()
                }
            )
        }
    }

    func keyboardWillHide(notification: NSNotification) {
        let frame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey]?.CGRectValue
        let options = UIViewAnimationOptions(rawValue: UInt((notification.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).integerValue << 16))
        let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue
        if frame != nil && duration != nil {
            UIView.animateWithDuration(duration!, delay: 0, options: options, animations: { () -> Void in
                self.constraint.constant = self.offset
                self.view.layoutIfNeeded()
            }, completion: nil)
        }
    }
}<commit_msg>[FC] Added KeyboardConstraintAdjuster tie-ins for keyboard hiding<commit_after>//
//  KeyboardConstraintAdjuster.swift
//  SwiftPlusPlus
//
//  Created by <NAME> on 11/6/15.
//  Copyright © 2015 Drewag LLC. All rights reserved.
//

import Foundation

public class KeyboardConstraintAdjuster: NSObject {
    @IBOutlet public var constraint: NSLayoutConstraint!
    @IBOutlet public var view: UIView!

    @IBInspectable public var offset: CGFloat = 0

    public var onKeyboardIsBeingShown: (() -> ())?
    public var onKeyboardWasShown: (() -> ())?
    public var onKeyboardIsBeingHidden: (() -> ())?
    public var onKeyboardWasHidden: (() -> ())?

    override public func awakeFromNib() {
        super.awakeFromNib()

        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)
    }

    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
    }

    // MARK: Notifications

    func keyboardWillShow(notification: NSNotification) {
        let frame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey]?.CGRectValue
        let options = UIViewAnimationOptions(rawValue: UInt((notification.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).integerValue << 16))
        let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue
        if frame != nil && duration != nil {
            UIView.animateWithDuration(
                duration!,
                delay: 0,
                options: options,
                animations: { () -> Void in
                    self.onKeyboardIsBeingShown?()
                    self.constraint.constant = frame!.size.height + self.offset
                    self.view.layoutIfNeeded()
                },
                completion: { _ in
                    self.onKeyboardWasShown?()
                }
            )
        }
    }

    func keyboardWillHide(notification: NSNotification) {
        let frame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey]?.CGRectValue
        let options = UIViewAnimationOptions(rawValue: UInt((notification.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).integerValue << 16))
        let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue
        if frame != nil && duration != nil {
            UIView.animateWithDuration(
                duration!,
                delay: 0,
                options: options,
                animations: {
                    self.onKeyboardIsBeingHidden?()
                    self.constraint.constant = self.offset
                    self.view.layoutIfNeeded()
                },
                completion: { _ in
                    self.onKeyboardWasHidden?()
                }
            )
        }
    }
}
{'fraction_non_alphanumeric': 0.09771170870218808, 'fraction_numerical': 0.00534491398029063, 'mean_word_length': 2.6423357664233578, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '129132', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1522, 'n_words': 309}