This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2021 Expedia, Inc. | |
// SPDX-License-Identifier: Apache-2.0 | |
import Combine | |
struct Price { | |
let amount: String // "$42" | |
let description: String // "avg/night" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: UICollectionViewDelegate | |
extension CollectionViewExample: UICollectionViewDelegate { | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
let item = items[indexPath.row] | |
let pdp = PropertyDetailsViewController(property: item) | |
pdp.modalPresentationStyle = .formSheet | |
present(pdp, animated: true) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Card | |
protocol CardContent { | |
var id: String { get } | |
var imageName: String { get } | |
var title: String { get } | |
var description: String { get } | |
} | |
struct Card: View { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Card: View { | |
typealias Content = CardContent | |
let content: Content | |
@State var isHearted: Bool = false | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
protocol CardContent { | |
var imageName: String { get } | |
var title: String { get } | |
var description: String { get } | |
} | |
struct Card: View { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
protocol CardContent { | |
var imageName: String { get } | |
var title: String { get } | |
var description: String { get } | |
} | |
struct Card: View { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: UICollectionViewDelegateFlowLayout | |
extension CollectionViewExample: UICollectionViewDelegateFlowLayout { | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
return CGSize(width: 240, height: 320) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
class MyCollectionViewCell: SwiftUICollectionViewCell<Card> { | |
static var reuseIdentifier = "MyCollectionViewCell" | |
typealias Content = Card.Content | |
func configure(with content: Content, parent: UIViewController) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
/// Subclass for embedding a SwiftUI View inside of UICollectionViewCell | |
/// Usage: `class MySwiftUICell: SwiftUICollectionViewCell<Card> { ... }` | |
open class SwiftUICollectionViewCell<Content>: UICollectionViewCell where Content: View { | |
/// Controller to host the SwiftUI View | |
private(set) var host: UIHostingController<Content>? | |