Created
April 2, 2020 07:34
-
-
Save wizard1066/1f04ab8aca0aab24e93e0d88e89d7078 to your computer and use it in GitHub Desktop.
abgwtpD
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
struct TheDropDelegate: DropDelegate { | |
@Binding var textID:Int? | |
@Binding var textText:[String] | |
@Binding var rect:[CGRect] | |
@Binding var textColors:[Color] | |
func validateDrop(info: DropInfo) -> Bool { | |
return info.hasItemsConforming(to: ["public.utf8-plain-text"]) | |
} | |
func dropEntered(info: DropInfo) { | |
print("drop entered") | |
} | |
func dropTarget(info: DropInfo) -> Int? { | |
for squareno in 0..<rect.count { | |
if rect[squareno].contains(info.location) { | |
return squareno | |
} | |
} | |
return nil | |
} | |
func performDrop(info: DropInfo) -> Bool { | |
guard let _ = textID else { | |
return false | |
} | |
textID = dropTarget(info: info)! | |
if let item = info.itemProviders(for: ["public.utf8-plain-text"]).first { | |
item.loadItem(forTypeIdentifier: "public.utf8-plain-text", options: nil) { (urlData, error) in | |
DispatchQueue.main.async { | |
if let urlData = urlData as? Data { | |
let text = String(decoding: urlData, as: UTF8.self) | |
self.textText[self.textID!] = text | |
switch text { | |
case " 1 ": self.textColors[self.textID!] = Color.red | |
case " 2 ": self.textColors[self.textID!] = Color.blue | |
case " 3 ": self.textColors[self.textID!] = Color.orange | |
// 4 is the last option | |
default: self.textColors[self.textID!] = Color.green | |
} | |
} | |
} | |
} | |
return true | |
} else { | |
return false | |
} | |
} | |
func dropUpdated(info: DropInfo) -> DropProposal? { | |
print("drop Updated") | |
let item = info.hasItemsConforming(to: ["public.utf8-plain-text"]) | |
let dp = DropProposal(operation: .move) | |
// self.textValue = "" | |
return dp | |
} | |
func dropExited(info: DropInfo) { | |
print("dropExited") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment