damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 2e2b33e21ded2a0e82f2eff0ac3030a282a8ab2a
parent c24b0afb8fbc3ec2c981d600297c221fe19d0e68
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 17 Mar 2023 10:13:23 -0600

Fix bug where small black text appears during image upload

Changelog-Fixed: Fix bug where small black text appears during image upload

Diffstat:
Mdamus/Views/PostView.swift | 26+++++++++++++++-----------
Mdamus/Views/TextViewWrapper.swift | 13+++++++++----
2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift @@ -154,6 +154,20 @@ struct PostView: View { .padding([.top, .bottom], 4) } + func append_url(_ url: String) { + let uploadedImageURL = NSMutableAttributedString(string: url) + let combinedAttributedString = NSMutableAttributedString() + combinedAttributedString.append(post) + if !post.string.hasSuffix(" ") { + combinedAttributedString.append(NSAttributedString(string: " ")) + } + combinedAttributedString.append(uploadedImageURL) + + // make sure we have a space at the end + combinedAttributedString.append(NSAttributedString(string: " ")) + post = combinedAttributedString + } + func handle_upload(image: UIImage) { let uploader = get_image_uploader(damus_state.pubkey) @@ -162,17 +176,7 @@ struct PostView: View { switch res { case .success(let url): - let uploadedImageURL = NSMutableAttributedString(string: url, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18.0), NSAttributedString.Key.foregroundColor: UIColor.label]) - let combinedAttributedString = NSMutableAttributedString() - combinedAttributedString.append(post) - if !post.string.hasSuffix(" ") { - combinedAttributedString.append(NSAttributedString(string: " ")) - } - combinedAttributedString.append(uploadedImageURL) - - // make sure we have a space at the end - combinedAttributedString.append(NSAttributedString(string: " ")) - post = combinedAttributedString + append_url(url) case .failed(let error): if let error { diff --git a/damus/Views/TextViewWrapper.swift b/damus/Views/TextViewWrapper.swift @@ -13,16 +13,21 @@ struct TextViewWrapper: UIViewRepresentable { func makeUIView(context: Context) -> UITextView { let textView = UITextView() textView.delegate = context.coordinator - textView.font = UIFont.preferredFont(forTextStyle: .body) - textView.textColor = UIColor.label + TextViewWrapper.setTextProperties(textView) + return textView + } + + static func setTextProperties(_ uiView: UITextView) { + uiView.textColor = UIColor.label + uiView.font = UIFont.preferredFont(forTextStyle: .body) let linkAttributes: [NSAttributedString.Key : Any] = [ NSAttributedString.Key.foregroundColor: UIColor(Color.accentColor)] - textView.linkTextAttributes = linkAttributes - return textView + uiView.linkTextAttributes = linkAttributes } func updateUIView(_ uiView: UITextView, context: Context) { uiView.attributedText = attributedText + TextViewWrapper.setTextProperties(uiView) } func makeCoordinator() -> Coordinator {