Skip to content

Commit

Permalink
ref #623 - add SwiftUI example
Browse files Browse the repository at this point in the history
  • Loading branch information
Menno Lovink authored and JoeMatt committed Dec 12, 2019
1 parent da41ced commit 44fbb6e
Show file tree
Hide file tree
Showing 25 changed files with 326 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Examples/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MainViewController: UIViewController {
let dataSource = ArrayDataSource<SourceData>(data: [
(BuiltInTransitionExampleViewController1.self, "Built In Animations"),
(MatchExampleViewController1.self, "Match Animation"),
(SwiftUIMatchExampleViewController.self, "Match SwiftUI"),
(MatchInCollectionExampleViewController1.self, "Match Cell in Collection"),
(AppStoreViewController1.self, "App Store Transition"),
])
Expand Down Expand Up @@ -54,6 +55,7 @@ class MainViewController: UIViewController {
layout: FlowLayout(lineSpacing: 10))
{ (context) in
let vc = context.data.0.init()
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
}
// TODO: Migrate the example to CollectionKit 2.2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash0_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash10_cell.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash1_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash2_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash3_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash4_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash5_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash6_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash7_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash8_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Unsplash9_cell.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions Examples/SwiftUIMatchExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import UIKit
import SwiftUI

class SwiftUIMatchExampleViewController: UIHostingController<ImagesTableView> {

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
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)
})

destinationViewController.isHeroEnabled = true

self.present(destinationViewController, animated: true, completion: nil)
}
}

@objc required dynamic init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

struct ImageInfo: Identifiable {

let id: Int
let name: String
}

struct ImagesTableView: View {

var onTapRow: ((ImageInfo)->())?

@State var images = (0...9).map{ ImageInfo(id: $0, name: "Unsplash\($0)") }

var body: some View {
List(images) { image in

HStack {
ImageViewWrapper(name: "\(image.name)_cell", heroID: image.name)
Spacer()
Text("Image number \(image.id)").padding()
}.onTapGesture {
self.onTapRow?(image)
}
}
}
}

#if DEBUG
#endif

struct ImageViewWrapper: View, UIViewRepresentable {

let name: String
let heroID: String?

func makeUIView(context: UIViewRepresentableContext<ImageViewWrapper>) -> UIImageView {
UIImageView(frame: .zero)
}

func updateUIView(_ uiView: UIImageView, context: UIViewRepresentableContext<ImageViewWrapper>) {
uiView.image = UIImage(named: name)
uiView.hero.id = heroID
}
}

//MARK: - Previews

#if DEBUG

struct ImagesTableView_Previews: PreviewProvider {
static var previews: some View {
ImagesTableView(onTapRow: nil)
}
}

struct ImageViewWrapper_Previews: PreviewProvider {
static var previews: some View {
ImageViewWrapper(name: "Unsplash0", heroID: nil)
}
}

#endif
Loading

0 comments on commit 44fbb6e

Please sign in to comment.