damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 5020ae7e3c0b154f0a68ac2bb386786a15acd3d5
parent 60e0031f2586b6f5ffcc0366fa242a3315b77687
Author: James Carucci <jim.carucci@northstarbis.com>
Date:   Mon,  8 Aug 2022 08:53:23 -0400

Add default placeholder for post UI :)

Closes: #18
Changlog-Added: Added post placeholder text (thanks jcarucci27)
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Views/PostView.swift | 30++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift @@ -12,11 +12,15 @@ enum NostrPostResult { case cancel } +let POST_PLACEHOLDER = "Type your post here..." + struct PostView: View { - @State var post: String = "" + @State var post: String = POST_PLACEHOLDER + @State var new: Bool = true + @FocusState var focus: Bool let references: [ReferencedId] - + @Environment(\.presentationMode) var presentationMode enum FocusField: Hashable { @@ -27,7 +31,7 @@ struct PostView: View { NotificationCenter.default.post(name: .post, object: NostrPostResult.cancel) dismiss() } - + func dismiss() { self.presentationMode.wrappedValue.dismiss() } @@ -37,7 +41,7 @@ struct PostView: View { NotificationCenter.default.post(name: .post, object: NostrPostResult.post(new_post)) dismiss() } - + var is_post_empty: Bool { return post.allSatisfy { $0.isWhitespace } } @@ -60,8 +64,17 @@ struct PostView: View { } .padding([.top, .bottom], 4) + TextEditor(text: $post) + .foregroundColor(self.post == POST_PLACEHOLDER ? .gray : .primary) .focused($focus) + .onTapGesture { + handle_post_placeholder() + } + .onChange(of: post) { value in + handle_post_placeholder() + } + } .onAppear() { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { @@ -70,5 +83,14 @@ struct PostView: View { } .padding() } + + func handle_post_placeholder() { + guard new else { + return + } + + new = false + post = post.replacingOccurrences(of: POST_PLACEHOLDER, with: "") + } }