Foto-Vorschau
This commit is contained in:
parent
893829d0e5
commit
0dce6e3988
21
YAPS/YAPS/Assets.xcassets/file_jpg.imageset/Contents.json
vendored
Normal file
21
YAPS/YAPS/Assets.xcassets/file_jpg.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "file_jpg.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
BIN
YAPS/YAPS/Assets.xcassets/file_jpg.imageset/file_jpg.png
vendored
Normal file
BIN
YAPS/YAPS/Assets.xcassets/file_jpg.imageset/file_jpg.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
21
YAPS/YAPS/Assets.xcassets/placeholder-image.imageset/Contents.json
vendored
Normal file
21
YAPS/YAPS/Assets.xcassets/placeholder-image.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "placeholder-image.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
BIN
YAPS/YAPS/Assets.xcassets/placeholder-image.imageset/placeholder-image.png
vendored
Normal file
BIN
YAPS/YAPS/Assets.xcassets/placeholder-image.imageset/placeholder-image.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
@ -11,14 +11,16 @@ import SwiftUI
|
||||
struct ContentView: View {
|
||||
|
||||
@State var fileList = [YapsFile]()
|
||||
@State var previewImg = Image("placeholder-image")
|
||||
|
||||
var finderHelper: FinderHelper
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
VStack {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Button(action: {
|
||||
self.fileList.removeAll()
|
||||
self.fileList.append(contentsOf: self.finderHelper.selectFolder())
|
||||
}) {
|
||||
Text("Select Folder")
|
||||
@ -28,21 +30,29 @@ struct ContentView: View {
|
||||
List {
|
||||
ForEach(self.fileList, id: \.self) { yapsFile in
|
||||
HStack {
|
||||
Image("file_raw").resizable().frame(width: 20, height: 20)
|
||||
self.finderHelper.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20)
|
||||
Text(yapsFile.name)
|
||||
}
|
||||
.onTapGesture(perform: {
|
||||
let selectedImageURL: URL = yapsFile.file
|
||||
|
||||
print("pressed \(yapsFile.name)")
|
||||
|
||||
self.previewImg = self.finderHelper.getImageByURL(source: selectedImageURL)
|
||||
.resizable()
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Text("THUMBNAIL")
|
||||
.focusable()
|
||||
}
|
||||
.frame(width: 150.0)
|
||||
|
||||
Text("Hello, World!")
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
GeometryReader { geo in
|
||||
self.previewImg.self
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: geo.size.width)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ class FinderHelper {
|
||||
var fileList = [YapsFile]()
|
||||
|
||||
do {
|
||||
let items = try fm.contentsOfDirectory(at: path, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
|
||||
let items = try fm.contentsOfDirectory(at: path, includingPropertiesForKeys: nil, options: .skipsHiddenFiles).filter{ $0.pathExtension == "jpg" || $0.pathExtension == "jpeg" }
|
||||
|
||||
for item in items {
|
||||
let yapsFile: YapsFile = YapsFile(name: item.lastPathComponent, file: item)
|
||||
@ -54,4 +54,27 @@ class FinderHelper {
|
||||
|
||||
return fileList
|
||||
}
|
||||
|
||||
func getImageByFiletype(file: URL) -> Image {
|
||||
let fileExtension = file.pathExtension
|
||||
var image = Image("file")
|
||||
|
||||
switch fileExtension {
|
||||
case "jpg":
|
||||
image = Image("file_jpg")
|
||||
case "raw":
|
||||
image = Image("file_raw")
|
||||
default:
|
||||
print("No image found for extenstion \(fileExtension)")
|
||||
}
|
||||
|
||||
return image
|
||||
}
|
||||
|
||||
func getImageByURL(source: URL) -> Image {
|
||||
let imageData:NSData = NSData(contentsOf: source)!
|
||||
let image = NSImage(data: imageData as Data)!
|
||||
|
||||
return Image(nsImage: image)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user