Skip to content

Commit

Permalink
ref HeroTransitions#623 - improve initializer of SwiftUIMatchExampleV…
Browse files Browse the repository at this point in the history
…iewController and readability of tuple
  • Loading branch information
Menno Lovink committed Nov 18, 2019
1 parent 544a2a7 commit 84adbd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions Examples/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CollectionKit

class MainViewController: UIViewController {

typealias SourceData = (UIViewController.Type, String)
typealias SourceData = (makeViewController: ()->(UIViewController), exampleTitle:String)

let collectionView = CollectionView()

Expand All @@ -22,18 +22,18 @@ class MainViewController: UIViewController {

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"),
({ BuiltInTransitionExampleViewController1() }, "Built In Animations"),
({ MatchExampleViewController1() }, "Match Animation"),
({ MatchInCollectionExampleViewController1() }, "Match Cell in Collection"),
({ AppStoreViewController1() }, "App Store Transition"),
])

if #available(iOS 13.0, *) {
dataSource.data.insert((SwiftUIMatchExampleViewController.self, "Match SwiftUI"), at: 2)
dataSource.data.insert(({ SwiftUIMatchExampleViewController() }, "Match SwiftUI"), at: 2)
}

let viewSource = ClosureViewSource { (label: UILabel, data: SourceData, index) in
label.text = "\(index + 1). \(data.1)"
label.text = "\(index + 1). \(data.exampleTitle)"
label.textAlignment = .center
if #available(iOS 13.0, *) {
label.textColor = .label
Expand All @@ -57,7 +57,7 @@ class MainViewController: UIViewController {
sizeSource: sizeSource,
layout: FlowLayout(lineSpacing: 10))
{ (context) in
let vc = context.data.0.init()
let vc = context.data.makeViewController()
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
}
Expand Down
6 changes: 3 additions & 3 deletions Examples/SwiftUIMatchExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import SwiftUI
@available(iOS 13.0, *)
class SwiftUIMatchExampleViewController: UIHostingController<ImagesTableView> {

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
required init() {
super.init(rootView: ImagesTableView())

rootView.onTapRow = { image in

let destinationViewController = UIHostingController(rootView: ImageViewWrapper(name: image.name, heroID: image.name)
.onTapGesture { [weak self] in
self?.presentedViewController?.dismiss(animated: true, completion: nil)
.onTapGesture { [weak self] in
self?.presentedViewController?.dismiss(animated: true, completion: nil)
})

destinationViewController.isHeroEnabled = true
Expand Down

0 comments on commit 84adbd5

Please sign in to comment.