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,8 +12,12 @@ 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]
|
||||
|
||||
@@ -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