Verified Commit ee9e2026 authored by Geoff Pado's avatar Geoff Pado

Push photo editing view controller when photo is selected

parent 4ee4a75f
......@@ -30,6 +30,8 @@
041EFF72225C3DC00058D8EE /* PhotoLibraryDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041EFF71225C3DC00058D8EE /* PhotoLibraryDataSource.swift */; };
041EFF74225C3DD20058D8EE /* PhotoLibraryViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041EFF73225C3DD20058D8EE /* PhotoLibraryViewCell.swift */; };
041EFF76225C3DF10058D8EE /* PhotoLibraryViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041EFF75225C3DF10058D8EE /* PhotoLibraryViewLayout.swift */; };
048909F2226571AB0048E203 /* PhotoEditingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048909F1226571AB0048E203 /* PhotoEditingViewController.swift */; };
048909F4226573750048E203 /* PhotoEditorPresenting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048909F3226573750048E203 /* PhotoEditorPresenting.swift */; };
04D68BC5225EE2C000D09BBD /* GeometryExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D68BC4225EE2C000D09BBD /* GeometryExtensions.swift */; };
04D68BC7225EE2FD00D09BBD /* PhotoLibraryViewCellImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D68BC6225EE2FD00D09BBD /* PhotoLibraryViewCellImageView.swift */; };
04D68BC92262B0C400D09BBD /* PhotoPermissionsRequester.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D68BC82262B0C400D09BBD /* PhotoPermissionsRequester.swift */; };
......@@ -76,6 +78,8 @@
041EFF71225C3DC00058D8EE /* PhotoLibraryDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoLibraryDataSource.swift; sourceTree = "<group>"; };
041EFF73225C3DD20058D8EE /* PhotoLibraryViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoLibraryViewCell.swift; sourceTree = "<group>"; };
041EFF75225C3DF10058D8EE /* PhotoLibraryViewLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoLibraryViewLayout.swift; sourceTree = "<group>"; };
048909F1226571AB0048E203 /* PhotoEditingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoEditingViewController.swift; sourceTree = "<group>"; };
048909F3226573750048E203 /* PhotoEditorPresenting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoEditorPresenting.swift; sourceTree = "<group>"; };
04D68BC4225EE2C000D09BBD /* GeometryExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeometryExtensions.swift; sourceTree = "<group>"; };
04D68BC6225EE2FD00D09BBD /* PhotoLibraryViewCellImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoLibraryViewCellImageView.swift; sourceTree = "<group>"; };
04D68BC82262B0C400D09BBD /* PhotoPermissionsRequester.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoPermissionsRequester.swift; sourceTree = "<group>"; };
......@@ -123,14 +127,12 @@
041EFEF72251A9F30058D8EE /* Highlighter */ = {
isa = PBXGroup;
children = (
041EFF042251A9F50058D8EE /* Info.plist */,
041EFF4A225300030058D8EE /* Localizable.strings */,
041EFEFF2251A9F50058D8EE /* Assets.xcassets */,
04D68BCF2262C41300D09BBD /* Application */,
04D68BC3225EE2A500D09BBD /* Extensions */,
041EFF012251A9F50058D8EE /* LaunchScreen.storyboard */,
048909EF2265716B0048E203 /* Photo Editing */,
041EFF6C225C38600058D8EE /* Photo Selection */,
041EFF532255A0930058D8EE /* Style */,
048909F0226571830048E203 /* Supporting Files */,
);
path = Highlighter;
sourceTree = "<group>";
......@@ -191,6 +193,26 @@
path = "Photo Selection";
sourceTree = "<group>";
};
048909EF2265716B0048E203 /* Photo Editing */ = {
isa = PBXGroup;
children = (
048909F1226571AB0048E203 /* PhotoEditingViewController.swift */,
048909F3226573750048E203 /* PhotoEditorPresenting.swift */,
);
path = "Photo Editing";
sourceTree = "<group>";
};
048909F0226571830048E203 /* Supporting Files */ = {
isa = PBXGroup;
children = (
041EFF042251A9F50058D8EE /* Info.plist */,
041EFF4A225300030058D8EE /* Localizable.strings */,
041EFEFF2251A9F50058D8EE /* Assets.xcassets */,
041EFF012251A9F50058D8EE /* LaunchScreen.storyboard */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
04D68BC3225EE2A500D09BBD /* Extensions */ = {
isa = PBXGroup;
children = (
......@@ -352,8 +374,10 @@
041EFF492252FAF50058D8EE /* IntroViewController.swift in Sources */,
041EFF6B225C36350058D8EE /* PhotoLibraryViewController.swift in Sources */,
041EFF70225C3D830058D8EE /* PhotoLibraryView.swift in Sources */,
048909F2226571AB0048E203 /* PhotoEditingViewController.swift in Sources */,
041EFF552255A0B00058D8EE /* Colors.swift in Sources */,
041EFF72225C3DC00058D8EE /* PhotoLibraryDataSource.swift in Sources */,
048909F4226573750048E203 /* PhotoEditorPresenting.swift in Sources */,
041EFEFB2251A9F30058D8EE /* AppViewController.swift in Sources */,
041EFF6E225C38800058D8EE /* PhotoSelectionViewController.swift in Sources */,
04D68BCC2262B35700D09BBD /* PhotoPermissionsDeniedAlertController.swift in Sources */,
......
// Created by Geoff Pado on 3/31/19.
// Copyright © 2019 Cocoatype, LLC. All rights reserved.
import Photos
import UIKit
class AppViewController: UIViewController {
class AppViewController: UIViewController, PhotoEditorPresenting {
init() {
super.init(nibName: nil, bundle: nil)
......@@ -13,10 +14,22 @@ class AppViewController: UIViewController {
embed(navigationController)
}
func presentPhotoEditingViewController(for asset: PHAsset) {
let navigationController = NavigationController(rootViewController: PhotoEditingViewController(asset: asset))
present(navigationController, animated: true)
}
@objc func dismissPhotoEditingViewController() {
if let presentedNavigationController = (presentedViewController as? NavigationController),
let rootViewController = presentedNavigationController.viewControllers.first,
rootViewController is PhotoEditingViewController {
dismiss(animated: true)
}
}
// MARK: Status Bar
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
override var childForStatusBarStyle: UIViewController? { return nil }
override var childForStatusBarStyle: UIViewController? { return children.first }
// MARK: Boilerplate
......
......@@ -14,8 +14,19 @@ class NavigationController: UINavigationController {
.font: UIFont.appFont(forTextStyle: .headline),
.foregroundColor: UIColor.white
]
let appearance = UIBarButtonItem.appearance()
appearance.setTitleTextAttributes([
.font: UIFont.appFont(forTextStyle: .subheadline),
.foregroundColor: UIColor.white
], for: .normal)
}
// MARK: Status Bar
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
override var childForStatusBarStyle: UIViewController? { return nil }
// MARK: Boilerplate
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
......
// Created by Geoff Pado on 4/15/19.
// Copyright © 2019 Cocoatype, LLC. All rights reserved.
import Photos
import UIKit
class PhotoEditingViewController: UIViewController {
init(asset: PHAsset) {
self.asset = asset
super.init(nibName: nil, bundle: nil)
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: #selector(AppViewController.dismissPhotoEditingViewController))
}
override func loadView() {
view = PhotoEditingView()
}
// MARK: Boilerplate
private let asset: PHAsset
@available(*, unavailable)
required init(coder: NSCoder) {
let className = String(describing: type(of: self))
fatalError("\(className) does not implement init(coder:)")
}
}
class PhotoEditingView: UIView {
init() {
super.init(frame: .zero)
backgroundColor = .primary
}
// MARK: Boilerplate
@available(*, unavailable)
required init(coder: NSCoder) {
let className = String(describing: type(of: self))
fatalError("\(className) does not implement init(coder:)")
}
}
// Created by Geoff Pado on 4/15/19.
// Copyright © 2019 Cocoatype, LLC. All rights reserved.
import Photos
import UIKit
protocol PhotoEditorPresenting {
func presentPhotoEditingViewController(for asset: PHAsset)
}
extension UIResponder {
var photoEditorPresenter: PhotoEditorPresenting? {
if let presenter = (self as? PhotoEditorPresenting) {
return presenter
}
return next?.photoEditorPresenter
}
}
......@@ -22,8 +22,12 @@ class PhotoLibraryDataSource: NSObject, UICollectionViewDataSource {
// MARK: Photos
lazy var allPhotos: PHFetchResult<PHAsset> = {
private lazy var allPhotos: PHFetchResult<PHAsset> = {
let fetchOptions = PHFetchOptions()
return PHAsset.fetchAssets(with: fetchOptions)
}()
func photo(at indexPath: IndexPath) -> PHAsset {
return allPhotos[indexPath.item]
}
}
......@@ -3,7 +3,7 @@
import UIKit
class PhotoLibraryViewController: UIViewController {
class PhotoLibraryViewController: UIViewController, UICollectionViewDelegate {
init() {
super.init(nibName: nil, bundle: nil)
}
......@@ -11,9 +11,17 @@ class PhotoLibraryViewController: UIViewController {
override func loadView() {
let libraryView = PhotoLibraryView()
libraryView.dataSource = dataSource
libraryView.delegate = self
view = libraryView
}
// MARK: UICollectionViewDelegate
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let asset = dataSource.photo(at: indexPath)
photoEditorPresenter?.presentPhotoEditingViewController(for: asset)
}
// MARK: Boilerplate
private let dataSource = PhotoLibraryDataSource()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment