Files: 2c1932822a8e06b5876eb875f19924a15ae91539 / localnative-ios / ln-ios / Views / QRCodeView.swift
1629 bytesRaw
1 | // |
2 | // QRCodeView.swift |
3 | // localnative-ios |
4 | // |
5 | // Created by Yi Wang on 4/17/20. |
6 | // Copyright © 2020 Yi Wang. All rights reserved. |
7 | // |
8 | |
9 | import SwiftUI |
10 | |
11 | struct QRCodeView: View { |
12 | var note: Note |
13 | var image: UIImage |
14 | |
15 | var body: some View { |
16 | VStack(alignment: .leading){ |
17 | HStack{ |
18 | Text(note.created_at.prefix(19)) |
19 | Spacer() |
20 | Text("\(String(note.uuid4.prefix(5))).. \(String(note.id))") |
21 | } |
22 | Text(makeText(note: note)) |
23 | Text(note.url).onTapGesture { |
24 | UIApplication.shared.open(URL(string: self.note.url)!) |
25 | }.foregroundColor(.blue) |
26 | Image(uiImage: image).interpolation(.none) |
27 | .resizable() |
28 | .aspectRatio(contentMode: .fit) |
29 | Spacer() |
30 | }.padding() |
31 | } |
32 | func makeText(note: Note) -> String{ |
33 | return note.title |
34 | + newLineOrEmptyString(str: note.description) |
35 | + newLineOrEmptyString(str: note.annotations) |
36 | } |
37 | func newLineOrEmptyString(str: String) -> String{ |
38 | if(str.trimmingCharacters(in: .whitespacesAndNewlines) == ""){ |
39 | return "" |
40 | }else{ |
41 | return "\n" + str |
42 | } |
43 | } |
44 | } |
45 | |
46 | struct QRCodeView_Previews: PreviewProvider { |
47 | static var previews: some View { |
48 | QRCodeView(note: Note( |
49 | id: 0, |
50 | uuid4: "uuid4", |
51 | title: "title", |
52 | url: "url", |
53 | tags: "tag1,tag2", |
54 | description: "description", |
55 | annotations: "annotations", |
56 | created_at: "2020-04-12" |
57 | ), image: UIImage()) |
58 | } |
59 | } |
60 |
Built with git-ssb-web