-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from filletofish/improvement/peek-pop-feature
Support Peek & Pop
- Loading branch information
Showing
6 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
48 changes: 48 additions & 0 deletions
48
CHMeetupApp/Sources/Common/Helpers/Previewing/Previewing.swift
This file contains 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
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) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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