1
Fork 0
This repository has been archived on 2025-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
mobilefort/MobileFort/Common/PostView.swift

58 lines
1.8 KiB
Swift
Raw Normal View History

2020-06-03 22:33:04 -04:00
import SwiftUI
import URLImage
2020-06-03 22:33:04 -04:00
extension String {
func encodeUrl() -> String? {
return self.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
}
}
struct PostView: View {
let post: ParsedPostContainer
2020-06-03 22:33:04 -04:00
var body: some View {
VStack {
2020-06-03 23:17:23 -04:00
HStack {
URLImage(url: URL(string: post.post.avatarUrl.encodeUrl()!)!) { image in
2020-06-03 23:17:23 -04:00
image
.resizable()
.aspectRatio(contentMode: .fit)
}.frame(width: 50.0, height: 50.0).padding(.leading)
2020-06-03 23:17:23 -04:00
VStack(alignment: .leading) {
if post.post.isReblogged() {
Text(post.post.username + " reblogged from " + post.post.originalUsername!).foregroundColor(.gray)
2020-06-03 23:17:23 -04:00
}
if post.post.getTitle() != nil {
Text(post.post.getTitle()!)
2020-06-03 23:17:23 -04:00
}
}
Spacer()
}.frame(maxWidth: .infinity)
2020-06-03 22:33:04 -04:00
VStack {
ForEach(post.post.media) { media in
if !media.url.isEmpty {
VStack {
URLImage(url: URL(string: media.url.encodeUrl()!)!) { image in
image
.aspectRatio(contentMode: .fit)
}
}
2020-06-03 22:33:04 -04:00
}
}
}
AttributedText(post.contentAttributed)
2020-06-03 23:17:23 -04:00
}.frame(maxWidth: .infinity)
2020-06-03 22:33:04 -04:00
}
}
struct PostView_Previews: PreviewProvider {
static var previews: some View {
return PostView(post: ParsedPostContainer(post: fooPost, contentAttributed: NSMutableAttributedString()))
2020-06-03 22:33:04 -04:00
}
}