From 745a420c19a2c5f424a18f9cc9520617884500df Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Fri, 25 Sep 2020 17:57:35 -0700 Subject: [PATCH] Hook up delegate --- .../Sources/ViewModels/AccountViewModel.swift | 8 ++++++++ Views/AccountView.swift | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ViewModels/Sources/ViewModels/AccountViewModel.swift b/ViewModels/Sources/ViewModels/AccountViewModel.swift index 1d35f9f..01cf007 100644 --- a/ViewModels/Sources/ViewModels/AccountViewModel.swift +++ b/ViewModels/Sources/ViewModels/AccountViewModel.swift @@ -27,4 +27,12 @@ public extension AccountViewModel { var note: NSAttributedString { accountService.account.note.attributed } var emoji: [Emoji] { accountService.account.emojis } + + func urlSelected(_ url: URL) { + eventsSubject.send( + accountService.navigationService.item(url: url) + .map { CollectionItemEvent.navigation($0) } + .setFailureType(to: Error.self) + .eraseToAnyPublisher()) + } } diff --git a/Views/AccountView.swift b/Views/AccountView.swift index a5fea2d..2e843ce 100644 --- a/Views/AccountView.swift +++ b/Views/AccountView.swift @@ -39,6 +39,23 @@ extension AccountView: UIContentView { } } +extension AccountView: UITextViewDelegate { + func textView( + _ textView: UITextView, + shouldInteractWith URL: URL, + in characterRange: NSRange, + interaction: UITextItemInteraction) -> Bool { + switch interaction { + case .invokeDefaultAction: + accountConfiguration.viewModel.urlSelected(URL) + return false + case .preview: return false + case .presentActions: return false + @unknown default: return false + } + } +} + private extension AccountView { static let spacing: CGFloat = 8 static let stackViewSpacing: CGFloat = 4 @@ -67,6 +84,7 @@ private extension AccountView { accountLabel.textColor = .secondaryLabel noteTextView.isScrollEnabled = false noteTextView.backgroundColor = .clear + noteTextView.delegate = self NSLayoutConstraint.activate([ avatarImageView.widthAnchor.constraint(equalToConstant: Self.avatarDimension),