<commit_before>//
//  TKMapButtonView.swift
//  TripKitUI
//
//  Created by <NAME> on 7/11/17.
//

import UIKit

@objc public class TKMapButtonView: UIView {
  
  public enum Alignment {
    case leading
    case trailing
  }
  
  private weak var stackView: UIStackView!
  
  public var singleItemAlignment = Alignment.trailing {
    didSet {
      guard items.count == 1 else { return }
      
      cleanUp()
      
      switch singleItemAlignment {
      case .leading:
        stackView.addArrangedSubview(items[0])
        stackView.addArrangedSubview(stretchingView())
      case .trailing:
        stackView.addArrangedSubview(stretchingView())
        stackView.addArrangedSubview(items[0])
      }
    }
  }
  
  @objc public var items: [UIView] = [] {
    didSet {
      guard stackView != nil else { preconditionFailure() }
      
      cleanUp()
      
      items.forEach {
        $0.setContentHuggingPriority(.required, for: .horizontal)
        $0.translatesAutoresizingMaskIntoConstraints = false
        stackView.addArrangedSubview($0)
      }

      if items.count == 1 {
        switch singleItemAlignment {
        case .leading:
          stackView.insertArrangedSubview(stretchingView(), at: 1)
        case .trailing:
          stackView.insertArrangedSubview(stretchingView(), at: 0)
        }
      }
    }
  }
  
  private func stretchingView() -> UIView {
    let stretchingView = UIView()
    stretchingView.setContentHuggingPriority(.defaultLow, for: .horizontal)
    stretchingView.backgroundColor = .blue
    stretchingView.translatesAutoresizingMaskIntoConstraints = false
    return stretchingView
  }
  
  override init(frame: CGRect) {
    super.init(frame: frame)
    prepareWrapper()
  }
  
  public required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    prepareWrapper()
  }
  
  private func prepareWrapper() {
    let wrapper = UIStackView()
    wrapper.axis = .horizontal
    wrapper.alignment = .center
    wrapper.distribution = .equalSpacing
    addSubview(wrapper)
    stackView = wrapper
    
    wrapper.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
        wrapper.topAnchor.constraint(equalTo: topAnchor),
        wrapper.leadingAnchor.constraint(equalTo: leadingAnchor),
        bottomAnchor.constraint(equalTo: wrapper.bottomAnchor),
        trailingAnchor.constraint(equalTo: wrapper.trailingAnchor)
      ])
  }
  
  private func cleanUp() {
    stackView.arrangedSubviews.forEach {
      stackView.removeArrangedSubview($0)
      $0.removeFromSuperview()
    }
  }

}
<commit_msg>Fixed TKMapButtonView blocks touch event<commit_after>//
//  TKMapButtonView.swift
//  TripKitUI
//
//  Created by <NAME> on 7/11/17.
//

import UIKit

/// This is a subclass of UIStackView that allows touch events to be
/// ignored if they were originating from one of its subviews.
class TKPassthroughStackView: UIStackView {
  
  // We return true if the given point is within one of the stackview's
  // subviews. This allows the subview to receive touch event.
  override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    for subview in subviews {
      if subview.point(inside: convert(point, to: subview), with: event) {
        return true
      }
    }
    return false
  }
  
}

@objc public class TKMapButtonView: UIView {
  
  public enum Alignment {
    case leading
    case trailing
  }
  
  private weak var stackView: UIStackView!
  
  public var singleItemAlignment = Alignment.trailing {
    didSet {
      guard items.count == 1 else { return }
      
      cleanUp()
      
      switch singleItemAlignment {
      case .leading:
        stackView.addArrangedSubview(items[0])
        stackView.addArrangedSubview(stretchingView())
      case .trailing:
        stackView.addArrangedSubview(stretchingView())
        stackView.addArrangedSubview(items[0])
      }
    }
  }
  
  @objc public var items: [UIView] = [] {
    didSet {
      guard stackView != nil else { preconditionFailure() }
      
      cleanUp()
      
      items.forEach {
        $0.setContentHuggingPriority(.required, for: .horizontal)
        $0.translatesAutoresizingMaskIntoConstraints = false
        stackView.addArrangedSubview($0)
      }

      if items.count == 1 {
        switch singleItemAlignment {
        case .leading:
          stackView.insertArrangedSubview(stretchingView(), at: 1)
        case .trailing:
          stackView.insertArrangedSubview(stretchingView(), at: 0)
        }
      }
    }
  }
  
  private func stretchingView() -> UIView {
    let stretchingView = UIView()
    stretchingView.setContentHuggingPriority(.defaultLow, for: .horizontal)
    stretchingView.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
    stretchingView.translatesAutoresizingMaskIntoConstraints = false
    return stretchingView
  }
  
  override init(frame: CGRect) {
    super.init(frame: frame)
    prepareWrapper()
  }
  
  public required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    prepareWrapper()
  }
  
  private func prepareWrapper() {
    let wrapper = TKPassthroughStackView()
    wrapper.axis = .horizontal
    wrapper.alignment = .center
    wrapper.distribution = .equalSpacing
    addSubview(wrapper)
    stackView = wrapper
    
    wrapper.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
        wrapper.topAnchor.constraint(equalTo: topAnchor),
        wrapper.leadingAnchor.constraint(equalTo: leadingAnchor),
        bottomAnchor.constraint(equalTo: wrapper.bottomAnchor),
        trailingAnchor.constraint(equalTo: wrapper.trailingAnchor)
      ])
  }
  
  private func cleanUp() {
    stackView.arrangedSubviews.forEach {
      stackView.removeArrangedSubview($0)
      $0.removeFromSuperview()
    }
  }
  
  public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    for subview in subviews {
      if subview.point(inside: convert(point, to: subview), with: event) {
        return true
      }
    }
    return false
  }
  
}

{'fraction_non_alphanumeric': 0.09068627450980392, 'fraction_numerical': 0.010784313725490196, 'mean_word_length': 2.752912323727774, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '7306960', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1816, 'n_words': 395}