<commit_before>//
//  ElongationDetailViewController.swift
//  ElongationPreview
//
//  Created by <NAME> on 11/02/2017.
//  Copyright © 2017 Ramotion. All rights reserved.
//

import UIKit



open class ElongationDetailViewController: SwipableTableViewController {
  
  var isExpanded = true
  
  open var headerView: ElongationHeader!
  
  fileprivate var config: ElongationConfig {
    return .shared
  }
 
}

// MARK: - Lifecycle 🌎
extension ElongationDetailViewController {
  
  override func gestureRecognizerSwiped(_ gesture: UIPanGestureRecognizer) {
    guard config.isSwipeGesturesEnabled else { return }
    let location = gesture.location(in: tableView)
    
    let point = headerView.convert(location, from: tableView)
    
    guard headerView.point(inside: location, with: nil), let view = headerView.hitTest(point, with: nil) else { return }
    if gesture.state == .began {
      startY = point.y
    }
    
    
    let newY = point.y
    let goingToBottom = startY < newY
    
    let rangeReached = abs(startY - newY) > 30
    
    if rangeReached {
      gesture.isEnabled = false
      gesture.isEnabled = true
    }
    
    switch view {
    case headerView.scalableView where swipedView == headerView.scalableView && rangeReached:
      if goingToBottom {
        guard !isBeingDismissed else { return }
        dismissViewController()
      }
      startY = newY
    case headerView.bottomView where swipedView == headerView.bottomView && rangeReached:
      if goingToBottom {
        
      }
      
      startY = newY
    default: break
    }
    
    swipedView = view
  }
 
  open override func scrollViewDidScroll(_ scrollView: UIScrollView) {
    guard scrollView === tableView, config.isSwipeGesturesEnabled else { return }
    if scrollView.contentOffset.y < 0, swipedView === headerView?.scalableView {
      scrollView.setContentOffset(.zero, animated: false)
    }
  }

}

// MARK: - Actions ⚡
extension ElongationDetailViewController {
  
  func headerViewTapped(_ gesture: UITapGestureRecognizer) {
    let location = gesture.location(in: headerView)
    let point = headerView.convert(location, from: view)
    let action = ElongationConfig.shared.headerTouchAction
    guard let touchedView = headerView.hitTest(point, with: nil) else {
      return
    }
    
    switch action {<commit_msg>restored headerView tap gesture<commit_after>//
//  ElongationDetailViewController.swift
//  ElongationPreview
//
//  Created by <NAME> on 11/02/2017.
//  Copyright © 2017 Ramotion. All rights reserved.
//

import UIKit



open class ElongationDetailViewController: SwipableTableViewController {
  
  var isExpanded = true
  
  open var headerView: ElongationHeader!
  
  fileprivate var config: ElongationConfig {
    return .shared
  }
  
}

// MARK: - Lifecycle 🌎
extension ElongationDetailViewController {
  
  override open func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(headerViewTapped))
    headerView.addGestureRecognizer(tapGesture)
  }
  
  override func gestureRecognizerSwiped(_ gesture: UIPanGestureRecognizer) {
    guard config.isSwipeGesturesEnabled else { return }
    let location = gesture.location(in: tableView)
    
    let point = headerView.convert(location, from: tableView)
    
    guard headerView.point(inside: location, with: nil), let view = headerView.hitTest(point, with: nil) else { return }
    if gesture.state == .began {
      startY = point.y
    }
    
    
    let newY = point.y
    let goingToBottom = startY < newY
    
    let rangeReached = abs(startY - newY) > 30
    
    if rangeReached {
      gesture.isEnabled = false
      gesture.isEnabled = true
    }
    
    switch view {
    case headerView.scalableView where swipedView == headerView.scalableView && rangeReached:
      if goingToBottom {
        guard !isBeingDismissed else { return }
        dismissViewController()
      }
      startY = newY
    case headerView.bottomView where swipedView == headerView.bottomView && rangeReached:
      if goingToBottom {
        
      }
      
      startY = newY
    default: break
    }
    
    swipedView = view
  }
  
  open override func scrollViewDidScroll(_ scrollView: UIScrollView) {
    guard scrollView === tableView, config.isSwipeGesturesEnabled else { return }
    if scrollView.contentOffset.y < 0, swipedView === headerView?.scalableView {
      scrollView.setContentOffset(.zero, animated: false)
    }
  }
  
}

// MARK: - Actions ⚡
extension ElongationDetailViewController {
  
  func headerViewTapped(_ gesture: UITapGestureRecognizer) {
    let location = gesture.location(in: headerView)
    let point = headerView.convert(location, from: view)
    let action = ElongationConfig.shared.headerTouchAction
    guard let touchedView = headerView.hitTest(point, with: nil) else {
      return
    }
    
    switch action {
{'fraction_non_alphanumeric': 0.08149199270220961, 'fraction_numerical': 0.00608149199270221, 'mean_word_length': 2.9662379421221865, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1378793', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1464, 'n_words': 365}