<commit_before>//
//  CollectionStackViewController.swift
//  NavigationStackDemo
//
//  Created by <NAME>. on 24/02/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

// MARK: CollectionStackViewController

protocol CollectionStackViewControllerDelegate {
  func controllerDidSelected(index index: Int)
}


class CollectionStackViewController: UICollectionViewController {

  private var screens: [UIImage]
  private let overlay: Float
  
  let delegate: CollectionStackViewControllerDelegate
  
  init(images: [UIImage], delegate: CollectionStackViewControllerDelegate, overlay: Float = 0.6) {
    self.screens  = images
    self.delegate = delegate
    self.overlay  = overlay
    super.init(collectionViewLayout: CollectionViewStackFlowLayout(itemsCount: images.count, overlay: overlay))
  }

  required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
  
  override func viewDidLoad() {
    configureCollectionView()
    scrolltoIndex(screens.count - 1, animated: false, position: .Left) // move to end
  }
  
  override func viewDidAppear(animated: Bool) {
    
    guard let collectionViewLayout = self.collectionViewLayout as? CollectionViewStackFlowLayout else {
      fatalError("wrong collection layout")
    }
    
    collectionViewLayout.openAnimating = true
    scrolltoIndex(0, animated: true, position: .Left) // open animation
  }
}

// MARK: configure

extension CollectionStackViewController {
  
  private func configureCollectionView() {
    guard let collectionViewLayout = self.collectionViewLayout as? UICollectionViewFlowLayout else {
      fatalError("wrong collection layout")
    }
    
    collectionViewLayout.scrollDirection = .Horizontal
    collectionView?.showsHorizontalScrollIndicator = false
    collectionView?.registerClass(CollectionViewStackCell.self, forCellWithReuseIdentifier: String(CollectionViewStackCell))
  }

}

// MARK: CollectionViewDataSource

extension CollectionStackViewController {
  
  override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return screens.count
  }
  
  override func collectionView(collectionView: UICollectionView,
                         willDisplayCell cell: UICollectionViewCell,
                  forItemAtIndexPath indexPath: NSIndexPath) {
    
    if let cell = cell as? CollectionViewStackCell {
      cell.imageView?.image = screens[indexPath.row]
    }
  }
  
  override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(String(CollectionViewStackCell),
                              forIndexPath: indexPath)
    return cell
  }
  
  override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    delegate.controllerDidSelected(index: indexPath.row)
    dismissViewControllerAnimated(true, completion: nil)
  }
}

// MARK: UICollectionViewDelegateFlowLayout

extension CollectionStackViewController: UICollectionViewDelegateFlowLayout {
  
  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    return view.bounds.size
  }
  
  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: NSInteger) -> CGFloat {
    return -collectionView.bounds.size.width * CGFloat(overlay)
  }
}
<commit_msg>close animation prototype<commit_after>//
//  CollectionStackViewController.swift
//  NavigationStackDemo
//
//  Created by <NAME>. on 24/02/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

// MARK: CollectionStackViewController

protocol CollectionStackViewControllerDelegate {
  func controllerDidSelected(index index: Int)
}


class CollectionStackViewController: UICollectionViewController {

  private var screens: [UIImage]
  private let overlay: Float
  
  let delegate: CollectionStackViewControllerDelegate
  
  init(images: [UIImage], delegate: CollectionStackViewControllerDelegate, overlay: Float = 0.6) {
    self.screens  = images
    self.delegate = delegate
    self.overlay  = overlay
    super.init(collectionViewLayout: CollectionViewStackFlowLayout(itemsCount: images.count, overlay: overlay))
  }

  required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
  
  override func viewDidLoad() {
    configureCollectionView()
    scrolltoIndex(screens.count - 1, animated: false, position: .Left) // move to end
  }
  
  override func viewDidAppear(animated: Bool) {
    
    guard let collectionViewLayout = self.collectionViewLayout as? CollectionViewStackFlowLayout else {
      fatalError("wrong collection layout")
    }
    
    collectionViewLayout.openAnimating = true
    scrolltoIndex(0, animated: true, position: .Left) // open animation
  }
}

// MARK: configure

extension CollectionStackViewController {
  
  private func configureCollectionView() {
    guard let collectionViewLayout = self.collectionViewLayout as? UICollectionViewFlowLayout else {
      fatalError("wrong collection layout")
    }
    
    collectionViewLayout.scrollDirection = .Horizontal
    collectionView?.showsHorizontalScrollIndicator = false
    collectionView?.registerClass(CollectionViewStackCell.self, forCellWithReuseIdentifier: String(CollectionViewStackCell))
  }

}

// MARK: CollectionViewDataSource

extension CollectionStackViewController {
  
  override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return screens.count
  }
  
  override func collectionView(collectionView: UICollectionView,
                         willDisplayCell cell: UICollectionViewCell,
                  forItemAtIndexPath indexPath: NSIndexPath) {
    
    if let cell = cell as? CollectionViewStackCell {
      cell.imageView?.image = screens[indexPath.row]
    }
  }
  
  override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(String(CollectionViewStackCell),
                              forIndexPath: indexPath)
    return cell
  }
  
  override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    delegate.controllerDidSelected(index: indexPath.row)
    
    let currentCell = collectionView.cellForItemAtIndexPath(indexPath)
    
    UIView.animateWithDuration(0.3, animations: { () -> Void in
      let scale = CGAffineTransformMakeScale(1, 1)
      let offset = collectionView.contentOffset.x - (self.view.bounds.size.width - collectionView.bounds.size.width * CGFloat(self.overlay)) * CGFloat(indexPath.row)
      let move = CGAffineTransformMakeTranslation(offset , 0)
      currentCell?.transform = CGAffineTransformConcat(scale, move)
      
      for  cell in self.collectionView!.visibleCells() where cell != currentCell {
        cell.transform = CGAffineTransformMakeTranslation(self.view.bounds.size.width , 0)
      }
      
    }) { (success) -> Void in
      self.dismissViewControllerAnimated(false, completion: nil)
    }
  }
}

// MARK: UICollectionViewDelegateFlowLayout

extension CollectionStackViewController: UICollectionViewDelegateFlowLayout {
  
  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    return view.bounds.size
  }
  
  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: NSInteger) -> CGFloat {
    return -collectionView.bounds.size.width * CGFloat(overlay)
  }
}

{'fraction_non_alphanumeric': 0.07656641604010025, 'fraction_numerical': 0.004260651629072682, 'mean_word_length': 4.267986798679868, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '933610', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2102, 'n_words': 470}