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,15 +154,8 @@ struct PostView: View {
.padding([.top, .bottom], 4) .padding([.top, .bottom], 4)
} }
func handle_upload(image: UIImage) { func append_url(_ url: String) {
let uploader = get_image_uploader(damus_state.pubkey) let uploadedImageURL = NSMutableAttributedString(string: url)
Task.init {
let res = await image_upload.start(img: image, uploader: uploader)
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() let combinedAttributedString = NSMutableAttributedString()
combinedAttributedString.append(post) combinedAttributedString.append(post)
if !post.string.hasSuffix(" ") { if !post.string.hasSuffix(" ") {
@@ -173,6 +166,17 @@ struct PostView: View {
// make sure we have a space at the end // make sure we have a space at the end
combinedAttributedString.append(NSAttributedString(string: " ")) combinedAttributedString.append(NSAttributedString(string: " "))
post = combinedAttributedString post = combinedAttributedString
}
func handle_upload(image: UIImage) {
let uploader = get_image_uploader(damus_state.pubkey)
Task.init {
let res = await image_upload.start(img: image, uploader: uploader)
switch res {
case .success(let url):
append_url(url)
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 {