Fix bug where small black text appears during image upload

Changelog-Fixed: Fix bug where small black text appears during image upload
This commit is contained in:
William Casarin
2023-03-17 10:13:23 -06:00
parent c24b0afb8f
commit 2e2b33e21d
2 changed files with 24 additions and 15 deletions

View File

@@ -154,6 +154,20 @@ struct PostView: View {
.padding([.top, .bottom], 4) .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) { func handle_upload(image: UIImage) {
let uploader = get_image_uploader(damus_state.pubkey) let uploader = get_image_uploader(damus_state.pubkey)
@@ -162,17 +176,7 @@ struct PostView: View {
switch res { switch res {
case .success(let url): case .success(let url):
let uploadedImageURL = NSMutableAttributedString(string: url, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18.0), NSAttributedString.Key.foregroundColor: UIColor.label]) append_url(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
case .failed(let error): case .failed(let error):
if let error { if let error {

View File

@@ -13,16 +13,21 @@ struct TextViewWrapper: UIViewRepresentable {
func makeUIView(context: Context) -> UITextView { func makeUIView(context: Context) -> UITextView {
let textView = UITextView() let textView = UITextView()
textView.delegate = context.coordinator textView.delegate = context.coordinator
textView.font = UIFont.preferredFont(forTextStyle: .body) TextViewWrapper.setTextProperties(textView)
textView.textColor = UIColor.label return textView
}
static func setTextProperties(_ uiView: UITextView) {
uiView.textColor = UIColor.label
uiView.font = UIFont.preferredFont(forTextStyle: .body)
let linkAttributes: [NSAttributedString.Key : Any] = [ let linkAttributes: [NSAttributedString.Key : Any] = [
NSAttributedString.Key.foregroundColor: UIColor(Color.accentColor)] NSAttributedString.Key.foregroundColor: UIColor(Color.accentColor)]
textView.linkTextAttributes = linkAttributes uiView.linkTextAttributes = linkAttributes
return textView
} }
func updateUIView(_ uiView: UITextView, context: Context) { func updateUIView(_ uiView: UITextView, context: Context) {
uiView.attributedText = attributedText uiView.attributedText = attributedText
TextViewWrapper.setTextProperties(uiView)
} }
func makeCoordinator() -> Coordinator { func makeCoordinator() -> Coordinator {