From 31a79cbef06a5b470cb05425a3179c5b5a1a6b71 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 6 Jul 2021 17:53:01 +0800 Subject: [PATCH] fix: profile fields not set hidden when blocked issue. resolve #195 --- .../Profile/Header/ProfileHeaderViewController.swift | 11 ++++++++--- .../Profile/Header/ProfileHeaderViewModel.swift | 1 + .../Profile/Header/View/ProfileHeaderView.swift | 12 +++++++----- Mastodon/Scene/Profile/ProfileViewController.swift | 5 +++-- Mastodon/Scene/Profile/ProfileViewModel.swift | 4 ++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Mastodon/Scene/Profile/Header/ProfileHeaderViewController.swift b/Mastodon/Scene/Profile/Header/ProfileHeaderViewController.swift index bf109888d..566b8c6ae 100644 --- a/Mastodon/Scene/Profile/Header/ProfileHeaderViewController.swift +++ b/Mastodon/Scene/Profile/Header/ProfileHeaderViewController.swift @@ -222,13 +222,18 @@ extension ProfileHeaderViewController { } .store(in: &disposeBag) - Publishers.CombineLatest( + Publishers.CombineLatest3( viewModel.isEditing, - viewModel.displayProfileInfo.fields + viewModel.displayProfileInfo.fields, + viewModel.needsFiledCollectionViewHidden ) .receive(on: RunLoop.main) - .sink { [weak self] isEditing, fields in + .sink { [weak self] isEditing, fields, needsHidden in guard let self = self else { return } + guard !needsHidden else { + self.profileHeaderView.fieldCollectionView.isHidden = true + return + } self.profileHeaderView.fieldCollectionView.isHidden = isEditing ? false : fields.isEmpty } .store(in: &disposeBag) diff --git a/Mastodon/Scene/Profile/Header/ProfileHeaderViewModel.swift b/Mastodon/Scene/Profile/Header/ProfileHeaderViewModel.swift index 453aa2e43..9a0145751 100644 --- a/Mastodon/Scene/Profile/Header/ProfileHeaderViewModel.swift +++ b/Mastodon/Scene/Profile/Header/ProfileHeaderViewModel.swift @@ -22,6 +22,7 @@ final class ProfileHeaderViewModel { let isEditing = CurrentValueSubject(false) let viewDidAppear = CurrentValueSubject(false) let needsSetupBottomShadow = CurrentValueSubject(true) + let needsFiledCollectionViewHidden = CurrentValueSubject(false) let isTitleViewContentOffsetSet = CurrentValueSubject(false) let emojiDict = CurrentValueSubject([:]) let accountForEdit = CurrentValueSubject(nil) diff --git a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift index 2ba4cef86..509e6739d 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift @@ -218,7 +218,7 @@ final class ProfileHeaderView: UIView { collectionView.isScrollEnabled = false return collectionView }() - var fieldCollectionViewHeightLaoutConstraint: NSLayoutConstraint! + var fieldCollectionViewHeightLayoutConstraint: NSLayoutConstraint! var fieldCollectionViewHeightObservation: NSKeyValueObservation? override init(frame: CGRect) { @@ -239,6 +239,8 @@ final class ProfileHeaderView: UIView { extension ProfileHeaderView { private func _init() { + backgroundColor = ThemeService.shared.currentTheme.value.systemGroupedBackgroundColor + fieldCollectionView.backgroundColor = ThemeService.shared.currentTheme.value.profileFieldCollectionViewBackgroundColor ThemeService.shared.currentTheme .receive(on: RunLoop.main) .sink { [weak self] theme in @@ -427,17 +429,17 @@ extension ProfileHeaderView { fieldCollectionView.translatesAutoresizingMaskIntoConstraints = false metaContainerStackView.addArrangedSubview(fieldCollectionView) - fieldCollectionViewHeightLaoutConstraint = fieldCollectionView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh) + fieldCollectionViewHeightLayoutConstraint = fieldCollectionView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh) NSLayoutConstraint.activate([ - fieldCollectionViewHeightLaoutConstraint, + fieldCollectionViewHeightLayoutConstraint, ]) fieldCollectionViewHeightObservation = fieldCollectionView.observe(\.contentSize, options: .new, changeHandler: { [weak self] tableView, _ in guard let self = self else { return } guard self.fieldCollectionView.contentSize.height != .zero else { - self.fieldCollectionViewHeightLaoutConstraint.constant = 44 + self.fieldCollectionViewHeightLayoutConstraint.constant = 44 return } - self.fieldCollectionViewHeightLaoutConstraint.constant = self.fieldCollectionView.contentSize.height + self.fieldCollectionViewHeightLayoutConstraint.constant = self.fieldCollectionView.contentSize.height }) bringSubviewToFront(bannerContainerView) diff --git a/Mastodon/Scene/Profile/ProfileViewController.swift b/Mastodon/Scene/Profile/ProfileViewController.swift index a1ad3f02b..bbe7af0c0 100644 --- a/Mastodon/Scene/Profile/ProfileViewController.swift +++ b/Mastodon/Scene/Profile/ProfileViewController.swift @@ -495,7 +495,8 @@ extension ProfileViewController { let isNeedSetHidden = isBlocking || isBlockedBy || suspended self.profileHeaderViewController.viewModel.needsSetupBottomShadow.value = !isNeedSetHidden self.profileHeaderViewController.profileHeaderView.bioContainerView.isHidden = isNeedSetHidden - self.profileHeaderViewController.pageSegmentedControl.isHidden = isNeedSetHidden + self.profileHeaderViewController.viewModel.needsFiledCollectionViewHidden.value = isNeedSetHidden + self.profileHeaderViewController.pageSegmentedControl.isEnabled = !isNeedSetHidden self.viewModel.needsPagePinToTop.value = isNeedSetHidden } .store(in: &disposeBag) @@ -530,7 +531,7 @@ extension ProfileViewController { self.profileHeaderViewController.profileHeaderView.statusDashboardView.followersDashboardMeterView.accessibilityLabel = L10n.Scene.Profile.Dashboard.Accessibility.countFollowers(count ?? 0) } .store(in: &disposeBag) - viewModel.needsPaingEnabled + viewModel.needsPagingEnabled .receive(on: RunLoop.main) .sink { [weak self] needsPaingEnabled in guard let self = self else { return } diff --git a/Mastodon/Scene/Profile/ProfileViewModel.swift b/Mastodon/Scene/Profile/ProfileViewModel.swift index 45a2386be..5e8874c22 100644 --- a/Mastodon/Scene/Profile/ProfileViewModel.swift +++ b/Mastodon/Scene/Profile/ProfileViewModel.swift @@ -63,7 +63,7 @@ class ProfileViewModel: NSObject { let isMeBarButtonItemsHidden = CurrentValueSubject(true) let needsPagePinToTop = CurrentValueSubject(false) - let needsPaingEnabled = CurrentValueSubject(true) + let needsPagingEnabled = CurrentValueSubject(true) let needsImageOverlayBlurred = CurrentValueSubject(false) init(context: AppContext, optionalMastodonUser mastodonUser: MastodonUser?) { @@ -161,7 +161,7 @@ class ProfileViewModel: NSObject { isBlockingOrBlocked .map { !$0 } - .assign(to: \.value, on: needsPaingEnabled) + .assign(to: \.value, on: needsPagingEnabled) .store(in: &disposeBag) isBlockingOrBlocked