commit 90f025564ae25992c693d489ee554e4df1147cf1
parent 54700e944c03908493d5e843ed3dfd69721ae32c
Author: aki-mizu <zh0521@gmail.com>
Date: Tue, 20 Dec 2022 20:22:23 +0900
Fix issues with the post placeholder
Changelog-Fixed: Fixed issues with the post placeholder
Diffstat:
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift
@@ -15,8 +15,7 @@ enum NostrPostResult {
let POST_PLACEHOLDER = "Type your post here..."
struct PostView: View {
- @State var post: String = POST_PLACEHOLDER
- @State var new: Bool = true
+ @State var post: String = ""
let replying_to: NostrEvent?
@FocusState var focus: Bool
@@ -50,7 +49,7 @@ struct PostView: View {
}
var is_post_empty: Bool {
- return post == POST_PLACEHOLDER || post.allSatisfy { $0.isWhitespace }
+ return post.allSatisfy { $0.isWhitespace }
}
var body: some View {
@@ -71,18 +70,17 @@ struct PostView: View {
}
.padding([.top, .bottom], 4)
-
- TextEditor(text: $post)
- .foregroundColor(self.post == POST_PLACEHOLDER ? .gray : .primary)
- .focused($focus)
- .textInputAutocapitalization(.sentences)
- .onTapGesture {
- handle_post_placeholder()
- }
- .onChange(of: post) { value in
- handle_post_placeholder()
+ ZStack(alignment: .topLeading) {
+ TextEditor(text: $post)
+ .focused($focus)
+ .textInputAutocapitalization(.sentences)
+ if post.isEmpty {
+ Text(POST_PLACEHOLDER)
+ .padding(.top, 8)
+ .padding(.leading, 10)
+ .foregroundColor(Color(uiColor: .placeholderText))
}
-
+ }
}
.onAppear() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
@@ -91,14 +89,5 @@ struct PostView: View {
}
.padding()
}
-
- func handle_post_placeholder() {
- guard new else {
- return
- }
-
- new = false
- post = post.replacingOccurrences(of: POST_PLACEHOLDER, with: "")
- }
}