-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: onTap conflict with onMove in service tab
- Loading branch information
Showing
4 changed files
with
64 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// TapHandlerView.swift | ||
// Easydict | ||
// | ||
// Created by phlpsong on 2024/1/10. | ||
// Copyright © 2024 izual. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
// Ref: https://stackoverflow.com/a/64194868/8378840 | ||
// Fix conflicts between onTap and onMove modifier | ||
class TapHandlerView: NSView { | ||
var tapAction: () -> Void | ||
|
||
init(_ block: @escaping () -> Void) { | ||
tapAction = block | ||
super.init(frame: .zero) | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func mouseDown(with event: NSEvent) { | ||
print("event: \(event)") | ||
super.mouseDown(with: event) | ||
tapAction() | ||
} | ||
} | ||
|
||
struct TapHandler: NSViewRepresentable { | ||
let tapAction: () -> Void | ||
|
||
func makeNSView(context _: Context) -> TapHandlerView { | ||
TapHandlerView(tapAction) | ||
} | ||
|
||
func updateNSView(_ nsView: TapHandlerView, context _: Context) { | ||
nsView.tapAction = tapAction | ||
} | ||
} |