Add post attachment bar for images and future things

This commit is contained in:
William Casarin
2023-03-15 15:32:51 -06:00
parent a574dcb27c
commit bc58686016

View File

@@ -69,68 +69,83 @@ struct PostView: View {
return post.string.allSatisfy { $0.isWhitespace } return post.string.allSatisfy { $0.isWhitespace }
} }
var body: some View { var ImageButton: some View {
VStack { Button(action: {
HStack { attach_media = true
Button(NSLocalizedString("Cancel", comment: "Button to cancel out of posting a note.")) { }, label: {
self.cancel() Image(systemName: "photo")
} })
.foregroundColor(.primary) }
Spacer() var AttachmentBar: some View {
.frame(width: 70) HStack(alignment: .center) {
ImageButton
}
}
Button(NSLocalizedString("Attach image", comment: "Button to attach image.")) { var PostButton: some View {
attach_media = true Button(NSLocalizedString("Post", comment: "Button to post a note.")) {
}.foregroundColor(.primary) showPrivateKeyWarning = contentContainsPrivateKey(self.post.string)
Spacer() if !showPrivateKeyWarning {
self.send_post()
if !is_post_empty {
Button(NSLocalizedString("Post", comment: "Button to post a note.")) {
showPrivateKeyWarning = contentContainsPrivateKey(self.post.string)
if !showPrivateKeyWarning {
self.send_post()
}
}
.font(.system(size: 14, weight: .bold))
.frame(width: 80, height: 30)
.foregroundColor(.white)
.background(LINEAR_GRADIENT)
.clipShape(Capsule())
}
} }
.frame(height: 30) }
.padding([.top, .bottom], 4) .font(.system(size: 14, weight: .bold))
.frame(width: 80, height: 30)
.foregroundColor(.white)
.background(LINEAR_GRADIENT)
.clipShape(Capsule())
}
var TextEntry: some View {
ZStack(alignment: .topLeading) {
TextViewWrapper(attributedText: $post)
.focused($focus)
.textInputAutocapitalization(.sentences)
.onChange(of: post) { _ in
if let replying_to {
damus_state.drafts.replies[replying_to] = post
} else {
damus_state.drafts.post = post
}
}
if post.string.isEmpty {
Text(POST_PLACEHOLDER)
.padding(.top, 8)
.padding(.leading, 4)
.foregroundColor(Color(uiColor: .placeholderText))
.allowsHitTesting(false)
}
}
}
var TopBar: some View {
HStack {
Button(NSLocalizedString("Cancel", comment: "Button to cancel out of posting a note.")) {
self.cancel()
}
.foregroundColor(.primary)
Spacer()
if !is_post_empty {
PostButton
}
}
.frame(height: 30)
.padding([.top, .bottom], 4)
}
var body: some View {
VStack(alignment: .leading) {
TopBar
HStack(alignment: .top) { HStack(alignment: .top) {
ProfilePicView(pubkey: damus_state.pubkey, size: 45.0, highlight: .none, profiles: damus_state.profiles) ProfilePicView(pubkey: damus_state.pubkey, size: 45.0, highlight: .none, profiles: damus_state.profiles)
VStack(alignment: .leading) { TextEntry
ZStack(alignment: .topLeading) {
TextViewWrapper(attributedText: $post)
.focused($focus)
.textInputAutocapitalization(.sentences)
.onChange(of: post) { _ in
if let replying_to {
damus_state.drafts.replies[replying_to] = post
} else {
damus_state.drafts.post = post
}
}
if post.string.isEmpty {
Text(POST_PLACEHOLDER)
.padding(.top, 8)
.padding(.leading, 4)
.foregroundColor(Color(uiColor: .placeholderText))
.allowsHitTesting(false)
}
}
}
} }
// This if-block observes @ for tagging // This if-block observes @ for tagging
@@ -140,6 +155,11 @@ struct PostView: View {
UserSearch(damus_state: damus_state, search: searching, post: $post) UserSearch(damus_state: damus_state, search: searching, post: $post)
}.zIndex(1) }.zIndex(1)
} }
Divider()
.padding([.bottom], 10)
AttachmentBar
} }
.sheet(isPresented: $attach_media) { .sheet(isPresented: $attach_media) {
ImagePicker(sourceType: .photoLibrary) { image in ImagePicker(sourceType: .photoLibrary) { image in