Add default placeholder for post UI :)
Closes: #18 Changlog-Added: Added post placeholder text (thanks jcarucci27) Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
60e0031f25
commit
5020ae7e3c
@@ -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: "")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user