Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref #623 - add SwiftUI example #635

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Examples/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class MainViewController: UIViewController {
(AppStoreViewController1.self, "App Store Transition"),
])

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

let viewSource = ClosureViewSource { (label: UILabel, data: SourceData, index) in
label.text = "\(index + 1). \(data.1)"
label.textAlignment = .center
Expand All @@ -54,6 +58,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.
90 changes: 90 additions & 0 deletions Examples/SwiftUIMatchExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import UIKit
import SwiftUI
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you wrap this while class in,

#if canImport(SwiftUI)
...
#endif

So that persons using older versions of XCode don't receive build errors.

You may need to wrap other code in the same block if they reference these classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do that tomorrow 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done what you suggested, however the checks related to that are still failing. I have no clue why that is. Hope you do.

I will still attempt to fix this one:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that last check is fixed now. Clueless on how to improve this code now. Looking forward to hearing an update from you @JoeMatt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoeMatt do you have any updates for me on how we can get this merged?



@available(iOS 13.0, *)
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
}

@available(iOS 13.0, *)
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)
}
}
}
}

@available(iOS 13.0, *)
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 (Will only work when target of HeroExamples is set to iOS 13 +)

#if DEBUG

@available(iOS 13.0, *)
struct ImagesTableView_Previews: PreviewProvider {
static var previews: some View {
ImagesTableView(onTapRow: nil)
}
}

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

#endif
4 changes: 4 additions & 0 deletions Hero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
4D307DF520E3C6DC00DD9F65 /* HeroModifier+Advanced.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D307DF320E3C6DC00DD9F65 /* HeroModifier+Advanced.swift */; };
5C5442AA2004092500E1E326 /* HeroCompatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C69728F2002CDBD001A5051 /* HeroCompatible.swift */; };
5C6972902002CDBD001A5051 /* HeroCompatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C69728F2002CDBD001A5051 /* HeroCompatible.swift */; };
62EFDDAC236F4FC200F3E85E /* SwiftUIMatchExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62EFDDAB236F4FC200F3E85E /* SwiftUIMatchExample.swift */; };
83043017B73BC66DBB920D5C /* Pods_HeroExamples.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEE340F89FF0A49DD23A5A6E /* Pods_HeroExamples.framework */; };
A306D3B61E1C7A2E00B6C23A /* Hero.h in Headers */ = {isa = PBXBuildFile; fileRef = A306D3B41E1C7A2E00B6C23A /* Hero.h */; settings = {ATTRIBUTES = (Public, ); }; };
A306D3B91E1C7A2E00B6C23A /* Hero.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A306D3B21E1C7A2E00B6C23A /* Hero.framework */; };
Expand Down Expand Up @@ -186,6 +187,7 @@
5C69728F2002CDBD001A5051 /* HeroCompatible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeroCompatible.swift; sourceTree = "<group>"; };
5CD4F09A588E81DA75C2BE38 /* Pods-HeroExamples.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HeroExamples.debug.xcconfig"; path = "Pods/Target Support Files/Pods-HeroExamples/Pods-HeroExamples.debug.xcconfig"; sourceTree = "<group>"; };
5CEC69C9A9A60129002FD931 /* Pods-HeroTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HeroTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-HeroTests/Pods-HeroTests.release.xcconfig"; sourceTree = "<group>"; };
62EFDDAB236F4FC200F3E85E /* SwiftUIMatchExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIMatchExample.swift; sourceTree = "<group>"; };
841FFA357ACB279D3F74CDEE /* Pods_HeroTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HeroTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
86C87C73D89E75C8443B5071 /* Pods-HeroTvOSExamples.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HeroTvOSExamples.debug.xcconfig"; path = "Pods/Target Support Files/Pods-HeroTvOSExamples/Pods-HeroTvOSExamples.debug.xcconfig"; sourceTree = "<group>"; };
A304BF831DF2717900A03345 /* ImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -565,6 +567,7 @@
A3D060C120833B4E00E48927 /* ExampleBaseViewController.swift */,
A3D060BF20833B0700E48927 /* BuiltInTransitionExample.swift */,
A3D060C320833D0400E48927 /* MatchExample.swift */,
62EFDDAB236F4FC200F3E85E /* SwiftUIMatchExample.swift */,
A3D060C5208348CB00E48927 /* MatchInCollectionExample.swift */,
A3D060C720834FF100E48927 /* AppStoreCardExample.swift */,
A33E60C21DE76CEF0065CBD8 /* Resources */,
Expand Down Expand Up @@ -1098,6 +1101,7 @@
files = (
F482F0BE235D7808002E97ED /* UIColor+HexString.swift in Sources */,
A33E60BD1DE7621C0065CBD8 /* UIKit+HeroExamples.swift in Sources */,
62EFDDAC236F4FC200F3E85E /* SwiftUIMatchExample.swift in Sources */,
A3D060C820834FF100E48927 /* AppStoreCardExample.swift in Sources */,
A3D060C420833D0400E48927 /* MatchExample.swift in Sources */,
A3D060C020833B0800E48927 /* BuiltInTransitionExample.swift in Sources */,
Expand Down