forked from HeroTransitions/Hero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainViewController.swift
74 lines (58 loc) · 2.49 KB
/
MainViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import UIKit
import CollectionKit
class MainViewController: UIViewController {
typealias SourceData = (UIViewController.Type, String)
let collectionView = CollectionView()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
view.addSubview(collectionView)
setupcollection()
}
func setupcollection() {
let dataSource = ArrayDataSource<SourceData>(data: [
(BuiltInTransitionExampleViewController1.self, "Built In Animations"),
(MatchExampleViewController1.self, "Match Animation"),
(MatchInCollectionExampleViewController1.self, "Match Cell in Collection"),
(AppStoreViewController1.self, "App Store Transition"),
])
let viewSource = ClosureViewSource { (label: UILabel, data: SourceData, index) in
label.text = "\(index + 1). \(data.1)"
label.textAlignment = .center
label.layer.borderColor = UIColor.gray.cgColor
label.layer.borderWidth = 0.5
label.layer.cornerRadius = 8
}
let sizeSource = { (i: Int, data: SourceData, size: CGSize) -> CGSize in
return CGSize(width: size.width, height: 64)
}
let examplesProvider = BasicProvider<SourceData, UILabel>(
dataSource: dataSource,
viewSource: viewSource,
sizeSource: sizeSource,
layout: FlowLayout(lineSpacing: 10))
{ (context) in
let vc = context.data.0.init()
self.present(vc, animated: true, completion: nil)
}
// TODO: Migrate the example to CollectionKit 2.2.0
let imageView = UIImageView(image: #imageLiteral(resourceName: "HeroLogo"))
imageView.contentMode = .scaleAspectFit
let imageProvider = SimpleViewProvider(views: [imageView], sizeStrategy: (.fill, .fit))
let legacyButton = UIButton(type: .system)
legacyButton.setTitle("Legacy Examples", for: .normal)
legacyButton.addTarget(self, action: #selector(showLegacy), for: .touchUpInside)
let legacyExamplesProvider = SimpleViewProvider(views: [legacyButton], sizeStrategy: (.fill, .fit))
collectionView.provider = ComposedProvider(
layout: FlowLayout(lineSpacing: 10).inset(by: UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)),
sections: [imageProvider, examplesProvider, legacyExamplesProvider]
)
}
@objc func showLegacy() {
hero.replaceViewController(with: viewController(forStoryboardName: "Main"))
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.frame = view.bounds
}
}