<commit_before>//
//  ViewController.swift
//  CPCollectionViewStackLayoutTransitionDemo
//
//  Created by Parsifal on 2017/2/18.
//  Copyright © 2017年 Parsifal. All rights reserved.
//

import UIKit
import CPCollectionViewKit

enum LayoutType {
    case flowLayout
    case stageLayout
}

class ViewController: UIViewController {
    
    @IBOutlet weak var collectionView: UICollectionView!
    let cellIdentifier = "CPCollectionViewCell"
    var dataArray = [(index: Int, color: UIColor)]()
    var flowLayout: UICollectionViewFlowLayout!
    var stageLayout: CPCollectionViewStageLayout!
    var circleLayout: CPCollectionViewCircleLayout!
    var currentLayoutType: LayoutType = .flowLayout
    var transitionManager: TransitionManager!
    var flowCellSize: CGSize!
    var fromContentOffset = CGPoint(x: 0, y: 0)
    var toContentOffset = CGPoint(x: 0, y: 0)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //Data Array
        for index in 0...19 {
            dataArray.append((index, randomColor()))
        }
        
        flowCellSize = CGSize(width: view.bounds.width/3,
                              height: view.bounds.width/3)
        
        //UI
        flowLayout = UICollectionViewFlowLayout()
        flowLayout.scrollDirection = .vertical
        flowLayout.itemSize = flowCellSize
        flowLayout.minimumLineSpacing = 0
        flowLayout.minimumInteritemSpacing = 0
        collectionView.setCollectionViewLayout(flowLayout, animated: false)
        
        let circleConfiguration = CPCircleLayoutConfiguration(withCellSize: CGSize(width: 50, height: 50))
        circleLayout = CPCollectionViewCircleLayout.init(withConfiguration: circleConfiguration)
        
        let stageConfiguration = CPStageLayoutConfiguration.init(withCellSize: CGSize(width: 50, height: 50))
        stageLayout = CPCollectionViewStageLayout(withConfiguration: stageConfiguration)
    }
    
    func randomColor() -> UIColor {
        return UIColor(red: CGFloat(Double(arc4random_uniform(256))/255.0),
                       green: CGFloat(Double(arc4random_uniform(256))/255.0),
                       blue: CGFloat(Double(arc4random_uniform(256))/255.0),
                       alpha: 1)
    }

}

extension ViewController: UICollectionViewDataSource {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath)
        
        cell.backgroundColor = dataArray[indexPath.item].color
        
        return cell
    }
    
}

extension ViewController: UICollectionViewDelegate {
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        var layout: UICollectionViewLayout = stageLayout
        var layoutType = LayoutType.stageLayout
        toContentOffset = stageLayout.contentOffsetFor(indexPath: indexPath)
        fromContentOffset = collectionView.contentOffset
        
        if currentLayoutType == .stageLayout {
            layout = flowLayout
            layoutType = .flowLayout
            let y = floor(CGFloat(indexPath.item) / 3.0) * flowCellSize.height
            toContentOffset = CGPoint(x: 0, y: min(flowLayout.collectionViewContentSize.height-collectionView.bounds.height, y))
        }

        transitionManager = TransitionManager(duration: 1, collectionView: collectionView, toLayout: layout)
        
        transitionManager.startInteractiveTransition {
            self.collectionView.contentOffset = self.toContentOffset
            self.currentLayoutType = layoutType
        }
    }
    
    func collectionView(_ collectionView: UICollectionView, transitionLayoutForOldLayout fromLayout: UICollectionViewLayout, newLayout toLayout: UICollectionViewLayout) -> UICollectionViewTransitionLayout {
        let customTransitionLayout = CPCollectionViewTransitionLayout(currentLayout: fromLayout, nextLayout: toLayout)
        customTransitionLayout.fromContentOffset = fromContentOffset
        customTransitionLayout.toContentOffset = toContentOffset
        return customTransitionLayout
    }
    
}
<commit_msg>remove unused codes.<commit_after>//
//  ViewController.swift
//  CPCollectionViewStackLayoutTransitionDemo
//
//  Created by Parsifal on 2017/2/18.
//  Copyright © 2017年 Parsifal. All rights reserved.
//

import UIKit
import CPCollectionViewKit

enum LayoutType {
    case flowLayout
    case stageLayout
}

class ViewController: UIViewController {
    
    @IBOutlet weak var collectionView: UICollectionView!
    let cellIdentifier = "CPCollectionViewCell"
    var dataArray = [(index: Int, color: UIColor)]()
    var flowLayout: UICollectionViewFlowLayout!
    var stageLayout: CPCollectionViewStageLayout!
    var circleLayout: CPCollectionViewCircleLayout!
    var currentLayoutType: LayoutType = .flowLayout
    var transitionManager: TransitionManager!
    var flowCellSize: CGSize!
    var fromContentOffset = CGPoint(x: 0, y: 0)
    var toContentOffset = CGPoint(x: 0, y: 0)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //Data Array
        for index in 0...19 {
            dataArray.append((index, randomColor()))
        }
        
        flowCellSize = CGSize(width: view.bounds.width/3,
                              height: view.bounds.width/3)
        
        //UI
        flowLayout = UICollectionViewFlowLayout()
        flowLayout.scrollDirection = .vertical
        flowLayout.itemSize = flowCellSize
        flowLayout.minimumLineSpacing = 0
        flowLayout.minimumInteritemSpacing = 0
        collectionView.setCollectionViewLayout(flowLayout, animated: false)
        
        let stageConfiguration = CPStageLayoutConfiguration.init(withCellSize: CGSize(width: 50, height: 50))
        stageLayout = CPCollectionViewStageLayout(withConfiguration: stageConfiguration)
    }
    
    func randomColor() -> UIColor {
        return UIColor(red: CGFloat(Double(arc4random_uniform(256))/255.0),
                       green: CGFloat(Double(arc4random_uniform(256))/255.0),
                       blue: CGFloat(Double(arc4random_uniform(256))/255.0),
                       alpha: 1)
    }

}

extension ViewController: UICollectionViewDataSource {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath)
        
        cell.backgroundColor = dataArray[indexPath.item].color
        
        return cell
    }
    
}

extension ViewController: UICollectionViewDelegate {
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        var layout: UICollectionViewLayout = stageLayout
        var layoutType = LayoutType.stageLayout
        toContentOffset = stageLayout.contentOffsetFor(indexPath: indexPath)
        fromContentOffset = collectionView.contentOffset
        
        if currentLayoutType == .stageLayout {
            layout = flowLayout
            layoutType = .flowLayout
            let y = floor(CGFloat(indexPath.item) / 3.0) * flowCellSize.height
            toContentOffset = CGPoint(x: 0, y: min(flowLayout.collectionViewContentSize.height-collectionView.bounds.height, y))
        }

        transitionManager = TransitionManager(duration: 1, collectionView: collectionView, toLayout: layout)
        
        transitionManager.startInteractiveTransition {
            self.collectionView.contentOffset = self.toContentOffset
            self.currentLayoutType = layoutType
        }
    }
    
    func collectionView(_ collectionView: UICollectionView, transitionLayoutForOldLayout fromLayout: UICollectionViewLayout, newLayout toLayout: UICollectionViewLayout) -> UICollectionViewTransitionLayout {
        let customTransitionLayout = CPCollectionViewTransitionLayout(currentLayout: fromLayout, nextLayout: toLayout)
        customTransitionLayout.fromContentOffset = fromContentOffset
        customTransitionLayout.toContentOffset = toContentOffset
        return customTransitionLayout
    }
    
}

{'fraction_non_alphanumeric': 0.07239766081871345, 'fraction_numerical': 0.013333333333333334, 'mean_word_length': 3.007029053420806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5112766', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2214, 'n_words': 476}