From 2d9178ad07bed61b3d7f66bf74b5e056bdcac321 Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Wed, 3 Jun 2020 23:17:23 -0400 Subject: [PATCH] Improve post header appearance --- MobileFort/MobileFort/Common.swift | 11 +++++++--- MobileFort/MobileFort/PostView.swift | 32 +++++++++++++++++++++------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/MobileFort/MobileFort/Common.swift b/MobileFort/MobileFort/Common.swift index ac42a73..3d1720a 100644 --- a/MobileFort/MobileFort/Common.swift +++ b/MobileFort/MobileFort/Common.swift @@ -30,6 +30,7 @@ struct Post: Decodable, Identifiable { let originalUsername: String? let originalPost: OriginalPost? + let avatarUrl: String func isReblogged() -> Bool { return originalUsername != nil @@ -44,8 +45,10 @@ struct Post: Decodable, Identifiable { } } +let mediaURL = "https://homepages.cae.wisc.edu/~ece533/images/airplane.png" + let testMedia = Media(id: 0, - url: "https://homepages.cae.wisc.edu/~ece533/images/airplane.png") + url: mediaURL) let fooPost = Post(id: 0, title: "Foo", @@ -54,7 +57,8 @@ let fooPost = Post(id: 0, media: [testMedia], username: "foobar", originalUsername: nil, - originalPost: nil) + originalPost: nil, + avatarUrl: mediaURL) let fooPostReblog = Post(id: 1, title: nil, @@ -63,4 +67,5 @@ let fooPostReblog = Post(id: 1, media: [testMedia], username: "foobar", originalUsername: "foobar2", - originalPost: nil) + originalPost: nil, + avatarUrl: mediaURL) diff --git a/MobileFort/MobileFort/PostView.swift b/MobileFort/MobileFort/PostView.swift index 84e7c54..7732a6e 100644 --- a/MobileFort/MobileFort/PostView.swift +++ b/MobileFort/MobileFort/PostView.swift @@ -12,13 +12,29 @@ struct PostView: View { var body: some View { VStack { - if post.isReblogged() { - Text("Reblogged from " + post.originalUsername!) - } - - if post.getTitle() != nil { - Text(post.getTitle()!) - } + HStack { + RemoteImage(type: .url(URL(string: post.avatarUrl.encodeUrl()!)!), errorView: { error in + Text(error.localizedDescription) + }, imageView: { image in + image + .resizable() + .aspectRatio(contentMode: .fit) + }, loadingView: { + Text("Loading...") + }).frame(width: 50.0, height: 50.0).padding(.leading) + + VStack(alignment: .leading) { + if post.isReblogged() { + Text("Reblogged from " + post.originalUsername!) + } + + if post.getTitle() != nil { + Text(post.getTitle()!) + } + } + + Spacer() + }.frame(maxWidth: .infinity) VStack { ForEach(post.media) { media in @@ -35,7 +51,7 @@ struct PostView: View { } } } - } + }.frame(maxWidth: .infinity) } }