Fix issues with the post placeholder
Changelog-Fixed: Fixed issues with the post placeholder
This commit is contained in:
committed by
William Casarin
parent
54700e944c
commit
90f025564a
@@ -15,8 +15,7 @@ enum NostrPostResult {
|
|||||||
let POST_PLACEHOLDER = "Type your post here..."
|
let POST_PLACEHOLDER = "Type your post here..."
|
||||||
|
|
||||||
struct PostView: View {
|
struct PostView: View {
|
||||||
@State var post: String = POST_PLACEHOLDER
|
@State var post: String = ""
|
||||||
@State var new: Bool = true
|
|
||||||
|
|
||||||
let replying_to: NostrEvent?
|
let replying_to: NostrEvent?
|
||||||
@FocusState var focus: Bool
|
@FocusState var focus: Bool
|
||||||
@@ -50,7 +49,7 @@ struct PostView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var is_post_empty: Bool {
|
var is_post_empty: Bool {
|
||||||
return post == POST_PLACEHOLDER || post.allSatisfy { $0.isWhitespace }
|
return post.allSatisfy { $0.isWhitespace }
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -71,18 +70,17 @@ struct PostView: View {
|
|||||||
}
|
}
|
||||||
.padding([.top, .bottom], 4)
|
.padding([.top, .bottom], 4)
|
||||||
|
|
||||||
|
ZStack(alignment: .topLeading) {
|
||||||
TextEditor(text: $post)
|
TextEditor(text: $post)
|
||||||
.foregroundColor(self.post == POST_PLACEHOLDER ? .gray : .primary)
|
.focused($focus)
|
||||||
.focused($focus)
|
.textInputAutocapitalization(.sentences)
|
||||||
.textInputAutocapitalization(.sentences)
|
if post.isEmpty {
|
||||||
.onTapGesture {
|
Text(POST_PLACEHOLDER)
|
||||||
handle_post_placeholder()
|
.padding(.top, 8)
|
||||||
|
.padding(.leading, 10)
|
||||||
|
.foregroundColor(Color(uiColor: .placeholderText))
|
||||||
}
|
}
|
||||||
.onChange(of: post) { value in
|
}
|
||||||
handle_post_placeholder()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
.onAppear() {
|
.onAppear() {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
@@ -91,14 +89,5 @@ struct PostView: View {
|
|||||||
}
|
}
|
||||||
.padding()
|
.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