Skip to content

Commit

Permalink
Reset to iOS 14
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhamsing committed Jul 14, 2020
1 parent df7ecf3 commit 5411ff3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions xcode/listapp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = listapp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -292,7 +292,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = listapp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
27 changes: 11 additions & 16 deletions xcode/listapp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

title = "Diffable Data Source - iOS 13"
title = "UICollectionViewComp..Layout - List - iOS 14"

// Setup collection view
let cv = UICollectionView(frame: .zero, collectionViewLayout: makeLayout())
cv.backgroundColor = .white
cv.register(ShowCell.self, forCellWithReuseIdentifier: ShowCell.reuseIdentifier)

let ds = makeDataSource(cv: cv)
self.dataSource = ds
Expand Down Expand Up @@ -53,27 +52,23 @@ class ViewController: UIViewController {
}

func makeDataSource(cv: UICollectionView) -> UICollectionViewDiffableDataSource<Section, Show> {
return UICollectionViewDiffableDataSource<Section, Show>(collectionView: cv) { (cview, indexPath, show) -> UICollectionViewCell? in
guard let cell = cv.dequeueReusableCell(withReuseIdentifier: ShowCell.reuseIdentifier, for: indexPath) as? ShowCell else { fatalError("Cannot create new cell") }

let cellRegistration: UICollectionView.CellRegistration<ShowCell, Show> = UICollectionView.CellRegistration { cell, indexPath, show in
cell.titleLabel.text = show.name
cell.subtitleLabel.text = show.subtitle
}

return cell
return UICollectionViewDiffableDataSource<Section, Show>(collectionView: cv) { (cv, indexPath, show) -> UICollectionViewCell? in
cv.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: show)
}
}

func makeLayout() -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(210/2))
let item = NSCollectionLayoutItem(layoutSize: itemSize)

let group = NSCollectionLayoutGroup.horizontal(layoutSize: itemSize, subitem: item, count: 1)
return UICollectionViewCompositionalLayout { (sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
let configuration = UICollectionLayoutListConfiguration(appearance: .plain)
let section = NSCollectionLayoutSection.list(using: configuration, layoutEnvironment: layoutEnvironment)

let section = NSCollectionLayoutSection(group: group)

let layout = UICollectionViewCompositionalLayout(section: section)
return layout
return section
}
}
}

Expand Down Expand Up @@ -107,7 +102,7 @@ class ShowCell: UICollectionViewCell {

let inset: CGFloat = 20
NSLayoutConstraint.activate([
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0),
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5),
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: inset),
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -inset),

Expand Down

0 comments on commit 5411ff3

Please sign in to comment.