-
Notifications
You must be signed in to change notification settings - Fork 0
[#375] Todo를 LongPressGesture 시 호버로 해당 뷰를 뜨게 한다 #806
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
Merged
Changes from all commits
Commits
Show all changes
3 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
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
155 changes: 155 additions & 0 deletions
155
...ation/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPreviewModifier.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,155 @@ | ||
| // | ||
| // TodoDetailPreviewModifier.swift | ||
| // PresentationShared | ||
| // | ||
| // Created by opfic on 8/11/26. | ||
| // | ||
|
|
||
| import SwiftUI | ||
| import ComposableArchitecture | ||
| import Core | ||
| import Domain | ||
|
|
||
| public extension View { | ||
| func todoDetailPreview(todoId: String) -> some View { | ||
| modifier(TodoDetailPreviewModifier(todoId: todoId)) | ||
| } | ||
| } | ||
|
|
||
| private struct TodoDetailPreviewModifier: ViewModifier { | ||
| @Environment(\.diContainer) private var container | ||
| let todoId: String | ||
|
|
||
| func body(content: Content) -> some View { | ||
| content.overlay { | ||
| TodoDetailPreviewInteractionView( | ||
| todoId: todoId, | ||
| makePreview: makePreviewViewController | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private func makePreviewViewController() -> UIViewController { | ||
| let store = Store( | ||
| initialState: TodoDetailFeature.State( | ||
| todoId: todoId, | ||
| showEditButton: false | ||
| ) | ||
| ) { | ||
| TodoDetailFeature() | ||
| } withDependencies: { | ||
| $0.fetchTodoByIdUseCase = container.resolve(FetchTodoByIdUseCase.self) | ||
| $0.fetchReferenceItemsUseCase = container.resolve(FetchReferenceItemsUseCase.self) | ||
| } | ||
| return UIHostingController(rootView: TodoDetailPreviewView(store: store)) | ||
| } | ||
| } | ||
|
|
||
| private struct TodoDetailPreviewInteractionView: UIViewRepresentable { | ||
| let todoId: String | ||
| let makePreview: () -> UIViewController | ||
|
|
||
| func makeCoordinator() -> TodoDetailPreviewInteractionCoordinator { | ||
| TodoDetailPreviewInteractionCoordinator() | ||
| } | ||
|
|
||
| func makeUIView(context: Context) -> UIView { | ||
| let view = UIView() | ||
| view.backgroundColor = .clear | ||
| view.isAccessibilityElement = false | ||
| context.coordinator.update(todoId: todoId, makePreview: makePreview) | ||
| context.coordinator.install(on: view) | ||
| return view | ||
| } | ||
|
|
||
| func updateUIView(_ view: UIView, context: Context) { | ||
| context.coordinator.update(todoId: todoId, makePreview: makePreview) | ||
| } | ||
| } | ||
|
|
||
| private final class TodoDetailPreviewInteractionCoordinator: NSObject { | ||
| private weak var view: UIView? | ||
| private var contextMenuInteraction: UIContextMenuInteraction? | ||
| private var todoId = "" | ||
| private var makePreview: (() -> UIViewController)? | ||
|
|
||
| func update( | ||
| todoId: String, | ||
| makePreview: @escaping () -> UIViewController | ||
| ) { | ||
| self.todoId = todoId | ||
| self.makePreview = makePreview | ||
| } | ||
|
|
||
| func install(on view: UIView) { | ||
| guard self.view !== view else { return } | ||
|
|
||
| if let contextMenuInteraction { | ||
| self.view?.removeInteraction(contextMenuInteraction) | ||
| } | ||
|
|
||
| let contextMenuInteraction = UIContextMenuInteraction(delegate: self) | ||
| view.addInteraction(contextMenuInteraction) | ||
| self.view = view | ||
| self.contextMenuInteraction = contextMenuInteraction | ||
| } | ||
| } | ||
|
|
||
| extension TodoDetailPreviewInteractionCoordinator: UIContextMenuInteractionDelegate { | ||
| func contextMenuInteraction( | ||
| _ interaction: UIContextMenuInteraction, | ||
| configurationForMenuAtLocation location: CGPoint | ||
| ) -> UIContextMenuConfiguration? { | ||
| guard let makePreview else { return nil } | ||
|
|
||
| let preferredContentSize = preferredContentSize(for: interaction.view) | ||
| return UIContextMenuConfiguration( | ||
| identifier: todoId as NSString, | ||
| previewProvider: { | ||
| let viewController = makePreview() | ||
| viewController.preferredContentSize = preferredContentSize | ||
| return viewController | ||
| }, | ||
| actionProvider: nil | ||
| ) | ||
| } | ||
|
|
||
| // 미리보기가 표시될 때 원본 행에 기본 배경색이 적용되는 현상 방지 | ||
| func contextMenuInteraction( | ||
| _ interaction: UIContextMenuInteraction, | ||
| configuration: UIContextMenuConfiguration, | ||
| highlightPreviewForItemWithIdentifier identifier: any NSCopying | ||
| ) -> UITargetedPreview? { | ||
| targetedPreview() | ||
| } | ||
|
|
||
| // 미리보기가 닫힐 때 원본 행에 기본 배경색이 적용되는 현상 방지 | ||
| func contextMenuInteraction( | ||
| _ interaction: UIContextMenuInteraction, | ||
| configuration: UIContextMenuConfiguration, | ||
| dismissalPreviewForItemWithIdentifier identifier: any NSCopying | ||
| ) -> UITargetedPreview? { | ||
| targetedPreview() | ||
| } | ||
|
|
||
| // iOS 18 이하에서 투명한 원본 뷰의 기본 전환 배경이 흰색으로 표시되는 현상 방지 | ||
| private func targetedPreview() -> UITargetedPreview? { | ||
| guard let view else { return nil } | ||
|
|
||
| let parameters = UIPreviewParameters() | ||
| parameters.backgroundColor = .clear | ||
| parameters.shadowPath = UIBezierPath() | ||
|
|
||
| return UITargetedPreview( | ||
| view: view, | ||
| parameters: parameters | ||
| ) | ||
| } | ||
|
|
||
| private func preferredContentSize(for view: UIView?) -> CGSize { | ||
| let bounds = view?.window?.bounds ?? view?.bounds ?? .zero | ||
| let width = min(420, max(280, bounds.width - 32)) | ||
| let height = min(640, max(320, bounds.height * 0.7)) | ||
| return CGSize(width: width, height: height) | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
Application/Presentation/PresentationShared/Sources/Todo/Detail/TodoDetailPreviewView.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,40 @@ | ||
| // | ||
| // TodoDetailPreviewView.swift | ||
| // PresentationShared | ||
| // | ||
| // Created by opfic on 8/11/26. | ||
| // | ||
|
|
||
| import SwiftUI | ||
| import ComposableArchitecture | ||
|
|
||
| struct TodoDetailPreviewView: View { | ||
| @State var store: StoreOf<TodoDetailFeature> | ||
|
|
||
| var body: some View { | ||
| ZStack { | ||
| Color(.systemGroupedBackground).ignoresSafeArea() | ||
| if let todo = store.todo { | ||
| TodoDetailContentView( | ||
| title: todo.title, | ||
| content: todo.content, | ||
| referenceItems: store.referenceItems, | ||
| number: todo.number, | ||
| onOpenTodoID: nil | ||
| ) | ||
| } else if store.alert != nil { | ||
| ContentUnavailableView { | ||
| Label( | ||
| String(localized: "common_error_title"), | ||
| systemImage: "exclamationmark.triangle" | ||
| ) | ||
| } description: { | ||
| Text(String(localized: "common_error_message")) | ||
| } | ||
| } else { | ||
| LoadingView() | ||
| } | ||
| } | ||
| .onAppear { store.send(.onAppear) } | ||
| } | ||
| } |
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
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.