mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Restored files from old Mac, force pushing
This commit is contained in:
parent
5dd95228b8
commit
5040381840
126 changed files with 10431 additions and 67 deletions
79
DynamicIsland/components/Shelf/DropItemView.swift
Normal file
79
DynamicIsland/components/Shelf/DropItemView.swift
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// TrayDrop+DropItemView.swift
|
||||
// NotchDrop
|
||||
//
|
||||
// Created by 秋星桥 on 2024/7/8.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct DropItemView: View {
|
||||
let item: TrayDrop.DropItem
|
||||
@EnvironmentObject var vm: DynamicIslandViewModel
|
||||
@ObservedObject var coordinator = DynamicIslandViewCoordinator.shared
|
||||
@StateObject var tvm = TrayDrop.shared
|
||||
|
||||
@State var hover = false
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .topTrailing) {
|
||||
VStack {
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.fill(.clear)
|
||||
.background {
|
||||
Image(nsImage: item.workspacePreviewImage)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
|
||||
Text(item.fileName)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(hover ? .white : .gray)
|
||||
.lineLimit(2)
|
||||
.allowsTightening(true)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onDrag {
|
||||
handleOnDrag(for: item)
|
||||
}
|
||||
.frame(width: 64, height: 64)
|
||||
|
||||
if hover {
|
||||
Circle()
|
||||
.fill(.white)
|
||||
.overlay(Image(systemName: "xmark").foregroundStyle(.black).font(.system(size: 7)).fontWeight(.semibold))
|
||||
.frame(width: spacing, height: spacing)
|
||||
.opacity(hover ? 1 : 0) // TODO: Use option key pressed to show delete
|
||||
.scaleEffect(coordinator.optionKeyPressed ? 1 : 0.5)
|
||||
.transition(.blurReplace.combined(with: .scale))
|
||||
.offset(x: spacing / 2, y: -spacing / 2)
|
||||
.onTapGesture { tvm.delete(item.id) }
|
||||
.shadow(color: .black, radius: 3)
|
||||
}
|
||||
}
|
||||
.onHover { hovering in
|
||||
withAnimation(.smooth) {
|
||||
if hovering {
|
||||
hover.toggle()
|
||||
} else {
|
||||
hover.toggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleOnDrag(for item: TrayDrop.DropItem) -> NSItemProvider {
|
||||
guard let itemProvider = NSItemProvider(contentsOf: item.storageURL) else {
|
||||
return NSItemProvider()
|
||||
}
|
||||
|
||||
let nameWithoutExtension = (item.fileName as NSString).deletingPathExtension
|
||||
itemProvider.suggestedName = nameWithoutExtension
|
||||
|
||||
return itemProvider
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue