Connect account header text view
This commit is contained in:
parent
07521837a9
commit
582ff3623c
|
@ -171,10 +171,10 @@ private extension CollectionViewController {
|
||||||
.dropFirst()
|
.dropFirst()
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] _ in
|
.sink { [weak self] _ in
|
||||||
accountHeaderView.viewModel = accountsStatusesViewModel
|
accountHeaderView.viewModel = accountsStatusesViewModel
|
||||||
self?.sizeTableHeaderFooterViews()
|
self?.sizeTableHeaderFooterViews()
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
tableView.tableHeaderView = accountHeaderView
|
tableView.tableHeaderView = accountHeaderView
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,17 @@ public class AccountStatusesViewModel: StatusListViewModel {
|
||||||
.assign(to: &$accountViewModel)
|
.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) {
|
public override func request(maxID: String? = nil, minID: String? = nil) {
|
||||||
if case .statuses = collection, maxID == nil {
|
if case .statuses = collection, maxID == nil {
|
||||||
accountStatusesService.fetchPinnedStatuses()
|
accountStatusesService.fetchPinnedStatuses()
|
||||||
|
|
|
@ -11,7 +11,7 @@ public enum NavigationEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension NavigationEvent {
|
extension NavigationEvent {
|
||||||
init?(_ event: CollectionItemEvent) {
|
public init?(_ event: CollectionItemEvent) {
|
||||||
switch event {
|
switch event {
|
||||||
case .ignorableOutput:
|
case .ignorableOutput:
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -8,7 +8,6 @@ import ServiceLayer
|
||||||
public class StatusListViewModel: ObservableObject {
|
public class StatusListViewModel: ObservableObject {
|
||||||
@Published public private(set) var items = [[CollectionItem]]()
|
@Published public private(set) var items = [[CollectionItem]]()
|
||||||
@Published public var alertItem: AlertItem?
|
@Published public var alertItem: AlertItem?
|
||||||
public let navigationEvents: AnyPublisher<NavigationEvent, Never>
|
|
||||||
public private(set) var nextPageMaxID: String?
|
public private(set) var nextPageMaxID: String?
|
||||||
public private(set) var maintainScrollPositionOfItem: CollectionItem?
|
public private(set) var maintainScrollPositionOfItem: CollectionItem?
|
||||||
|
|
||||||
|
@ -22,7 +21,6 @@ public class StatusListViewModel: ObservableObject {
|
||||||
|
|
||||||
init(statusListService: StatusListService) {
|
init(statusListService: StatusListService) {
|
||||||
self.statusListService = statusListService
|
self.statusListService = statusListService
|
||||||
navigationEvents = navigationEventsSubject.eraseToAnyPublisher()
|
|
||||||
|
|
||||||
statusListService.statusSections
|
statusListService.statusSections
|
||||||
.combineLatest(statusListService.filters.map { $0.regularExpression() })
|
.combineLatest(statusListService.filters.map { $0.regularExpression() })
|
||||||
|
@ -43,6 +41,8 @@ public class StatusListViewModel: ObservableObject {
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var navigationEvents: AnyPublisher<NavigationEvent, Never> { navigationEventsSubject.eraseToAnyPublisher() }
|
||||||
|
|
||||||
public var title: AnyPublisher<String?, Never> { Just(statusListService.title).eraseToAnyPublisher() }
|
public var title: AnyPublisher<String?, Never> { Just(statusListService.title).eraseToAnyPublisher() }
|
||||||
|
|
||||||
public func request(maxID: String? = nil, minID: String? = nil) {
|
public func request(maxID: String? = nil, minID: String? = nil) {
|
||||||
|
|
|
@ -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 {
|
private extension AccountHeaderView {
|
||||||
func initializationActions() {
|
func initializationActions() {
|
||||||
let baseStackView = UIStackView()
|
let baseStackView = UIStackView()
|
||||||
|
@ -55,6 +72,7 @@ private extension AccountHeaderView {
|
||||||
baseStackView.axis = .vertical
|
baseStackView.axis = .vertical
|
||||||
|
|
||||||
noteTextView.isScrollEnabled = false
|
noteTextView.isScrollEnabled = false
|
||||||
|
noteTextView.delegate = self
|
||||||
baseStackView.addArrangedSubview(noteTextView)
|
baseStackView.addArrangedSubview(noteTextView)
|
||||||
|
|
||||||
for (index, collection) in AccountStatusCollection.allCases.enumerated() {
|
for (index, collection) in AccountStatusCollection.allCases.enumerated() {
|
||||||
|
|
Loading…
Reference in New Issue