Skip to content

Commit

Permalink
Merge pull request #313 from filletofish/improvement/peek-pop-feature
Browse files Browse the repository at this point in the history
Support Peek & Pop
  • Loading branch information
Kirillzzy authored Nov 13, 2017
2 parents f90e4b9 + 1e0df4b commit f41fd2d
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CHMeetupApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
32DD63021EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DD63001EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.swift */; };
32DD63031EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 32DD63011EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.xib */; };
32DD63051EA8CED0005B565E /* ChooseProfilePhotoTableViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DD63041EA8CED0005B565E /* ChooseProfilePhotoTableViewModel.swift */; };
3630B8E41FAF272E00DF3F31 /* Previewing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3630B8E31FAF272E00DF3F31 /* Previewing.swift */; };
4C18F5F21F4257360062CCA2 /* UIViewController+HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C18F5F11F4257360062CCA2 /* UIViewController+HUD.swift */; };
4D0E6B561E86E11100C44DC0 /* ActionCellConfigurationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D0E6B551E86E11100C44DC0 /* ActionCellConfigurationController.swift */; };
4D8851021E9F8FC400A49ADD /* PushNotificationsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D8851011E9F8FC400A49ADD /* PushNotificationsController.swift */; };
Expand Down Expand Up @@ -402,6 +403,7 @@
32DD63001EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChooseProfilePhotoTableViewCell.swift; sourceTree = "<group>"; };
32DD63011EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ChooseProfilePhotoTableViewCell.xib; sourceTree = "<group>"; };
32DD63041EA8CED0005B565E /* ChooseProfilePhotoTableViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChooseProfilePhotoTableViewModel.swift; sourceTree = "<group>"; };
3630B8E31FAF272E00DF3F31 /* Previewing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Previewing.swift; sourceTree = "<group>"; };
4C18F5F11F4257360062CCA2 /* UIViewController+HUD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+HUD.swift"; sourceTree = "<group>"; };
4D0E6B551E86E11100C44DC0 /* ActionCellConfigurationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ActionCellConfigurationController.swift; path = ActionCellConfigurationController/ActionCellConfigurationController.swift; sourceTree = "<group>"; };
4D8851011E9F8FC400A49ADD /* PushNotificationsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PushNotificationsController.swift; path = PushNotification/PushNotificationsController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -952,6 +954,7 @@
22323F1B1E70C0E500522E5C /* Utility */,
22323F1D1E70C0E500522E5C /* WebService */,
8AB256971E78680500B319AA /* Share */,
3630B8E21FAF270000DF3F31 /* Previewing */,
9F487A6C1E73EE710016CE0B /* Swizzling */,
);
path = Helpers;
Expand Down Expand Up @@ -1410,6 +1413,14 @@
name = ChooseProfilePhotoCell;
sourceTree = "<group>";
};
3630B8E21FAF270000DF3F31 /* Previewing */ = {
isa = PBXGroup;
children = (
3630B8E31FAF272E00DF3F31 /* Previewing.swift */,
);
path = Previewing;
sourceTree = "<group>";
};
4D0E6B541E86E0D100C44DC0 /* ActionCellConfigurationController */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2512,6 +2523,7 @@
8A6A84481E99AA8A00C3A9E7 /* EventFetching.swift in Sources */,
32AA9BBE1E7A91C000140413 /* PhotosPresentationView.swift in Sources */,
22323F301E70C0E500522E5C /* RequestContentParser.swift in Sources */,
3630B8E41FAF272E00DF3F31 /* Previewing.swift in Sources */,
22323F941E70C2BE00522E5C /* PastEventsViewController.swift in Sources */,
B744FA581FB07B2A00F92D4B /* AlertHeaderTableViewCell.swift in Sources */,
22323F561E70C18700522E5C /* UserPlainObject+Requests.swift in Sources */,
Expand Down
48 changes: 48 additions & 0 deletions CHMeetupApp/Sources/Common/Helpers/Previewing/Previewing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Previewing.swift
// CHMeetupApp
//
// Created by Filipp Fediakov on 05.11.17.
// Copyright © 2017 CocoaHeads Community. All rights reserved.
//

import UIKit

extension UIViewControllerPreviewingDelegate where Self: UIViewController {
@discardableResult
func registerForPreviewing() -> Bool {
if traitCollection.forceTouchCapability == .available {
registerForPreviewing(with: self, sourceView: view)
return true
} else {
return false
}
}
}

protocol PreviewingContentProvider {
func commitPreview(_ : UIViewController)
func preview(at: IndexPath) -> UIViewController?
}

extension UIViewControllerPreviewingDelegate where Self: UIViewControllerWithTableView {
func previewingContextProvided(by contentProvider: PreviewingContentProvider,
at location: CGPoint,
previewingContext: UIViewControllerPreviewing) -> UIViewController? {
guard let indexPath = tableView.indexPathForRow(at: location),
let viewController = contentProvider.preview(at: indexPath) else {
return nil
}

let sourceRect = tableView.rectForRow(at: indexPath)
previewingContext.sourceRect = sourceRect
return viewController
}
}

extension UIViewControllerPreviewingDelegate {
func commitPreview(by contentProvider: PreviewingContentProvider,
viewController: UIViewController) {
contentProvider.commitPreview(viewController)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class MainViewController: UIViewController, DisplayCollectionWithTableViewDelega
setCurrentState()
fetchEvents()
title = "CocoaHeads Russia".localized

PermissionsManager.requireAccess(from: self, to: .notifications) { _ in }
registerForPreviewing()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -99,3 +99,17 @@ fileprivate extension MainViewController {
}

extension MainViewController: ProfileHierarhyViewControllerType { }

extension MainViewController: UIViewControllerPreviewingDelegate {
func previewingContext(_ previewingContext: UIViewControllerPreviewing,
commit viewControllerToCommit: UIViewController) {
self.commitPreview(by: displayCollection, viewController: viewControllerToCommit)
}

func previewingContext(_ previewingContext: UIViewControllerPreviewing,
viewControllerForLocation location: CGPoint) -> UIViewController? {
return self.previewingContextProvided(by: displayCollection,
at: location,
previewingContext: previewingContext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class MainViewDisplayCollection: DisplayCollection, DisplayCollectionAction {
return [EventPreviewTableViewCellModel.self, ActionTableViewCellModel.self]
}

private enum `Type` {
fileprivate enum `Type` {
case events
case actionButtons
case collectionIsEmpty
}

weak var delegate: DisplayCollectionWithTableViewDelegate?

private var sections: [Type] = [.events, .actionButtons, .collectionIsEmpty]
fileprivate var sections: [Type] = [.events, .actionButtons, .collectionIsEmpty]
private var actionPlainObjects: [ActionPlainObject] = []

let groupImageLoader = GroupImageLoader.standard
Expand Down Expand Up @@ -111,3 +111,23 @@ extension MainViewDisplayCollection: EventPreviewTableViewCellDelegate {
delegate?.push(viewController: viewController)
}
}

extension MainViewDisplayCollection: PreviewingContentProvider {
func preview(at indexPath: IndexPath) -> UIViewController? {
switch sections[indexPath.section] {
case .events:
if modelCollection[indexPath.row].isTemplate {
return nil
}
let eventPreviewViewController = Storyboards.EventPreview.instantiateEventPreviewViewController()
eventPreviewViewController.selectedEventId = modelCollection[indexPath.row].id
return eventPreviewViewController
case .actionButtons, .collectionIsEmpty:
return nil
}
}

func commitPreview(_ viewControllerToCommit: UIViewController) {
delegate?.push(viewController: viewControllerToCommit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,18 @@ extension PastEventsDisplayCollection: EventPreviewTableViewCellDelegate {
delegate?.push(viewController: viewController)
}
}

extension PastEventsDisplayCollection: PreviewingContentProvider {
func preview(at indexPath: IndexPath) -> UIViewController? {
if modelCollection[indexPath.row].isTemplate {
return nil
}
let eventPreviewViewController = Storyboards.EventPreview.instantiateEventPreviewViewController()
eventPreviewViewController.selectedEventId = modelCollection[indexPath.row].id
return eventPreviewViewController
}

func commitPreview(_ viewControllerToCommit: UIViewController) {
delegate?.push(viewController: viewControllerToCommit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class PastEventsViewController: UIViewController, DisplayCollectionWithTableView
displayCollection.delegate = self
tableView.registerNibs(from: displayCollection)
title = "Прошедшие встречи".localized

registerForPreviewing()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -76,3 +78,17 @@ fileprivate extension PastEventsViewController {
})
}
}

extension PastEventsViewController: UIViewControllerPreviewingDelegate {
func previewingContext(_ previewingContext: UIViewControllerPreviewing,
commit viewControllerToCommit: UIViewController) {
self.commitPreview(by: displayCollection, viewController: viewControllerToCommit)
}

func previewingContext(_ previewingContext: UIViewControllerPreviewing,
viewControllerForLocation location: CGPoint) -> UIViewController? {
return self.previewingContextProvided(by: displayCollection,
at: location,
previewingContext: previewingContext)
}
}

0 comments on commit f41fd2d

Please sign in to comment.