-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 태그 복사 메뉴 추가 #800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+168
−2
Merged
feat: 태그 복사 메뉴 추가 #800
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
120 changes: 120 additions & 0 deletions
120
Application/Presentation/PresentationShared/Sources/Common/Component/TagCopyMenuView.swift
This file contains hidden or 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,120 @@ | ||
| // | ||
| // TagCopyMenuView.swift | ||
| // PresentationShared | ||
| // | ||
| // Created by opfic on 8/9/26. | ||
| // | ||
|
|
||
| import SwiftUI | ||
| import UIKit | ||
|
|
||
| struct TagCopyMenuView: UIViewRepresentable { | ||
| let tagText: String | ||
|
|
||
| func makeCoordinator() -> TagCopyMenuCoordinator { | ||
| TagCopyMenuCoordinator() | ||
| } | ||
|
|
||
| func makeUIView(context: Context) -> UIView { | ||
| let view = UIView() | ||
| view.backgroundColor = .clear | ||
| view.isAccessibilityElement = false | ||
| context.coordinator.install(on: view) | ||
| context.coordinator.tagText = tagText | ||
| return view | ||
| } | ||
|
|
||
| func updateUIView(_ view: UIView, context: Context) { | ||
| context.coordinator.tagText = tagText | ||
| } | ||
| } | ||
|
|
||
| final class TagCopyMenuCoordinator: NSObject { | ||
| var tagText = "" | ||
| private weak var view: UIView? | ||
| private var editMenuInteraction: UIEditMenuInteraction? | ||
|
|
||
| func install(on view: UIView) { | ||
| self.view = view | ||
|
|
||
| let editMenuInteraction = UIEditMenuInteraction(delegate: self) | ||
| view.addInteraction(editMenuInteraction) | ||
| self.editMenuInteraction = editMenuInteraction | ||
|
|
||
| let longPressGesture = UILongPressGestureRecognizer( | ||
| target: self, | ||
| action: #selector(handleLongPressGesture(_:)) | ||
| ) | ||
| longPressGesture.allowedTouchTypes = [ | ||
| NSNumber(value: UITouch.TouchType.direct.rawValue), | ||
| NSNumber(value: UITouch.TouchType.indirectPointer.rawValue) | ||
| ] | ||
| longPressGesture.cancelsTouchesInView = false | ||
| longPressGesture.delegate = self | ||
| view.addGestureRecognizer(longPressGesture) | ||
|
|
||
| let secondaryClickGesture = UITapGestureRecognizer( | ||
| target: self, | ||
| action: #selector(handleSecondaryClickGesture(_:)) | ||
| ) | ||
| secondaryClickGesture.allowedTouchTypes = [ | ||
| NSNumber(value: UITouch.TouchType.indirectPointer.rawValue) | ||
| ] | ||
| secondaryClickGesture.buttonMaskRequired = .secondary | ||
| secondaryClickGesture.cancelsTouchesInView = false | ||
| secondaryClickGesture.delegate = self | ||
| view.addGestureRecognizer(secondaryClickGesture) | ||
| } | ||
|
|
||
| @objc | ||
| private func handleLongPressGesture(_ gesture: UILongPressGestureRecognizer) { | ||
| guard gesture.state == .began, let view else { return } | ||
|
|
||
| presentEditMenu(at: gesture.location(in: view)) | ||
| } | ||
|
|
||
| @objc | ||
| private func handleSecondaryClickGesture(_ gesture: UITapGestureRecognizer) { | ||
| guard gesture.state == .ended, let view else { return } | ||
|
|
||
| presentEditMenu(at: gesture.location(in: view)) | ||
| } | ||
|
|
||
| private func presentEditMenu(at sourcePoint: CGPoint) { | ||
| let configuration = UIEditMenuConfiguration( | ||
| identifier: nil, | ||
| sourcePoint: sourcePoint | ||
| ) | ||
| editMenuInteraction?.presentEditMenu(with: configuration) | ||
| } | ||
| } | ||
|
|
||
| extension TagCopyMenuCoordinator: UIEditMenuInteractionDelegate { | ||
| func editMenuInteraction( | ||
| _ interaction: UIEditMenuInteraction, | ||
| menuFor configuration: UIEditMenuConfiguration, | ||
| suggestedActions: [UIMenuElement] | ||
| ) -> UIMenu? { | ||
| let tagText = tagText | ||
| let copyAction = UIAction(title: String(localized: "common_copy")) { _ in | ||
| UIPasteboard.general.string = tagText | ||
| } | ||
| return UIMenu(children: [copyAction]) | ||
| } | ||
|
|
||
| func editMenuInteraction( | ||
| _ interaction: UIEditMenuInteraction, | ||
| targetRectFor configuration: UIEditMenuConfiguration | ||
| ) -> CGRect { | ||
| view?.bounds ?? .zero | ||
| } | ||
| } | ||
|
|
||
| extension TagCopyMenuCoordinator: UIGestureRecognizerDelegate { | ||
| func gestureRecognizer( | ||
| _ gestureRecognizer: UIGestureRecognizer, | ||
| shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer | ||
| ) -> Bool { | ||
| true | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.