Created
March 24, 2022 15:34
-
-
Save ospfranco/b260368c1da4e96f223eb7f2ced0f484 to your computer and use it in GitHub Desktop.
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
import Cocoa | |
class _FileIcon: NSView { | |
let image = NSImageView() | |
@objc var url: NSString = "" { | |
didSet { | |
self.setupView() | |
} | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
} | |
private func setupView() { | |
let icon = NSWorkspace.shared.icon(forFile: self.url as String) | |
self.image.image = icon | |
image.autoresizingMask = [.height, .width] | |
self.addSubview(image) | |
} | |
} | |
@objc (FileIconManager) | |
class FileIconManager: RCTViewManager { | |
override static func requiresMainQueueSetup() -> Bool { | |
return true | |
} | |
override func view() -> NSView! { | |
return _FileIcon() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment