-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial implementation for context menu interaction delegate
- Loading branch information
1 parent
4b6fc6f
commit 02f6fe9
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
Sources/XCoordinator/CoordinatorContextMenuInteractionDelegate.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,81 @@ | ||
// | ||
// CoordinatorContextMenuInteractionDelegate.swift | ||
// XCoordinator | ||
// | ||
// Created by Paul Kraft on 13.02.20. | ||
// | ||
|
||
import UIKit | ||
|
||
@available(iOS 13.0, *) | ||
internal class CoordinatorContextMenuInteractionDelegate<TransitionType: TransitionProtocol>: NSObject, UIContextMenuInteractionDelegate { | ||
|
||
// MARK: Stored properties | ||
|
||
private let identifier: NSCopying? | ||
private let transition: () -> TransitionType | ||
private let menu: UIMenu? | ||
|
||
private let rootViewController: TransitionType.RootViewController | ||
private let completion: PresentationHandler? | ||
|
||
// MARK: Initialization | ||
|
||
internal init( | ||
identifier: NSCopying?, | ||
transition: @escaping () -> TransitionType, | ||
rootViewController: TransitionType.RootViewController, | ||
menu: UIMenu?, | ||
completion: PresentationHandler? | ||
) { | ||
self.identifier = identifier | ||
self.transition = transition | ||
self.menu = menu | ||
self.rootViewController = rootViewController | ||
self.completion = completion | ||
} | ||
|
||
// MARK: Methods | ||
|
||
internal func contextMenuInteraction( | ||
_ interaction: UIContextMenuInteraction, | ||
configurationForMenuAtLocation location: CGPoint | ||
) -> UIContextMenuConfiguration? { | ||
UIContextMenuConfiguration( | ||
identifier: identifier, | ||
previewProvider: { [weak self] in | ||
self?.transition().presentables.last?.viewController | ||
}, | ||
actionProvider: { [weak self] _ in | ||
self?.menu | ||
} | ||
) | ||
} | ||
|
||
internal func contextMenuInteraction( | ||
_ interaction: UIContextMenuInteraction, | ||
willDisplayMenuFor configuration: UIContextMenuConfiguration, | ||
animator: UIContextMenuInteractionAnimating? | ||
) { | ||
print(#function) | ||
} | ||
|
||
internal func contextMenuInteraction( | ||
_ interaction: UIContextMenuInteraction, | ||
willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, | ||
animator: UIContextMenuInteractionCommitAnimating | ||
) { | ||
transition().perform(on: rootViewController, | ||
with: .default, | ||
completion: completion) | ||
} | ||
|
||
internal func contextMenuInteraction( | ||
_ interaction: UIContextMenuInteraction, | ||
willEndFor configuration: UIContextMenuConfiguration, | ||
animator: UIContextMenuInteractionAnimating? | ||
) { | ||
completion?() | ||
} | ||
|
||
} |
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