Connect account header text view

This commit is contained in:
Justin Mazzocchi 2020-09-26 00:45:39 -07:00
parent 07521837a9
commit 582ff3623c
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
5 changed files with 36 additions and 7 deletions

View file

@ -28,6 +28,17 @@ public class AccountStatusesViewModel: StatusListViewModel {
.assign(to: &$accountViewModel)
}
public override var navigationEvents: AnyPublisher<NavigationEvent, Never> {
$accountViewModel.compactMap { $0 }
.flatMap(\.events)
.flatMap { $0 }
.map(NavigationEvent.init)
.compactMap { $0 }
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.merge(with: super.navigationEvents)
.eraseToAnyPublisher()
}
public override func request(maxID: String? = nil, minID: String? = nil) {
if case .statuses = collection, maxID == nil {
accountStatusesService.fetchPinnedStatuses()

View file

@ -11,7 +11,7 @@ public enum NavigationEvent {
}
extension NavigationEvent {
init?(_ event: CollectionItemEvent) {
public init?(_ event: CollectionItemEvent) {
switch event {
case .ignorableOutput:
return nil

View file

@ -8,7 +8,6 @@ import ServiceLayer
public class StatusListViewModel: ObservableObject {
@Published public private(set) var items = [[CollectionItem]]()
@Published public var alertItem: AlertItem?
public let navigationEvents: AnyPublisher<NavigationEvent, Never>
public private(set) var nextPageMaxID: String?
public private(set) var maintainScrollPositionOfItem: CollectionItem?
@ -22,7 +21,6 @@ public class StatusListViewModel: ObservableObject {
init(statusListService: StatusListService) {
self.statusListService = statusListService
navigationEvents = navigationEventsSubject.eraseToAnyPublisher()
statusListService.statusSections
.combineLatest(statusListService.filters.map { $0.regularExpression() })
@ -43,6 +41,8 @@ public class StatusListViewModel: ObservableObject {
.store(in: &cancellables)
}
public var navigationEvents: AnyPublisher<NavigationEvent, Never> { navigationEventsSubject.eraseToAnyPublisher() }
public var title: AnyPublisher<String?, Never> { Just(statusListService.title).eraseToAnyPublisher() }
public func request(maxID: String? = nil, minID: String? = nil) {

View file

@ -44,6 +44,23 @@ class AccountHeaderView: UIView {
}
}
extension AccountHeaderView: UITextViewDelegate {
func textView(
_ textView: UITextView,
shouldInteractWith URL: URL,
in characterRange: NSRange,
interaction: UITextItemInteraction) -> Bool {
switch interaction {
case .invokeDefaultAction:
viewModel?.accountViewModel?.urlSelected(URL)
return false
case .preview: return false
case .presentActions: return false
@unknown default: return false
}
}
}
private extension AccountHeaderView {
func initializationActions() {
let baseStackView = UIStackView()
@ -55,6 +72,7 @@ private extension AccountHeaderView {
baseStackView.axis = .vertical
noteTextView.isScrollEnabled = false
noteTextView.delegate = self
baseStackView.addArrangedSubview(noteTextView)
for (index, collection) in AccountStatusCollection.allCases.enumerated() {