Skip to content

Commit

Permalink
fix: Unable to tab to Contacts - WPB-10514 (#1830)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Wyndham <[email protected]>
  • Loading branch information
github-actions[bot] and samwyndham authored Aug 16, 2024
1 parent c8aa7dd commit fd0295d
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 29 deletions.
4 changes: 4 additions & 0 deletions wire-ios/Wire-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@
BFFD439E1DE47FFA00505C8C /* UIView+RightToLeft.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFFD439D1DE47FFA00505C8C /* UIView+RightToLeft.swift */; };
BFFE943C1E7839D10025AD75 /* ConversationRenamedCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFFE943B1E7839D10025AD75 /* ConversationRenamedCellTests.swift */; };
BFFE943E1E7839EB0025AD75 /* CoreDataSnapshotTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFFE943D1E7839EB0025AD75 /* CoreDataSnapshotTestCase.swift */; };
CB51204B2C6F6C84000C8FEC /* TabBarChangeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB51204A2C6F6C84000C8FEC /* TabBarChangeHandler.swift */; };
CE2402811E0A992200665A91 /* AnalyticsConsoleProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2402801E0A992200665A91 /* AnalyticsConsoleProvider.swift */; };
CEEEAF071CB562BF00111759 /* PlaceholderConversationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEEAF061CB562BF00111759 /* PlaceholderConversationView.swift */; };
D30880FB292CD8F200DDEAB0 /* CallingBottomSheetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D30880FA292CD8F200DDEAB0 /* CallingBottomSheetViewController.swift */; };
Expand Down Expand Up @@ -3255,6 +3256,7 @@
BFFD439D1DE47FFA00505C8C /* UIView+RightToLeft.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+RightToLeft.swift"; sourceTree = "<group>"; };
BFFE943B1E7839D10025AD75 /* ConversationRenamedCellTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConversationRenamedCellTests.swift; sourceTree = "<group>"; };
BFFE943D1E7839EB0025AD75 /* CoreDataSnapshotTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataSnapshotTestCase.swift; sourceTree = "<group>"; };
CB51204A2C6F6C84000C8FEC /* TabBarChangeHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarChangeHandler.swift; sourceTree = "<group>"; };
CE06C93E1DF5C3D900497685 /* AVAsset+VideoConvert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AVAsset+VideoConvert.swift"; sourceTree = "<group>"; };
CE2402801E0A992200665A91 /* AnalyticsConsoleProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnalyticsConsoleProvider.swift; sourceTree = "<group>"; };
CE8E4FA91DF066750009F437 /* FileMetaDataGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileMetaDataGenerator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8345,6 +8347,7 @@
EF3CBC092147D81700566295 /* ConversationListViewController+PushPermissions.swift */,
EF6E9FE323193439000B7785 /* ConversationListViewController+State.swift */,
BFAAB2421DEDB21E00CBC096 /* ConversationListViewController+Transitions.swift */,
CB51204A2C6F6C84000C8FEC /* TabBarChangeHandler.swift */,
EF471BE023265305008E11A5 /* ViewModel */,
);
path = Container;
Expand Down Expand Up @@ -10221,6 +10224,7 @@
87BEB0441D3E478500DE9575 /* AssetLibrary.swift in Sources */,
D30880FE292E521D00DDEAB0 /* CallingActionsInfoViewController.swift in Sources */,
16D74BEA2B5895C900160298 /* AuthenticationMissingUsernameErrorHandler.swift in Sources */,
CB51204B2C6F6C84000C8FEC /* TabBarChangeHandler.swift in Sources */,
EE593F9C2B73C3F0008D1109 /* DeepLinksView.swift in Sources */,
E90B7DB628117DED001831FB /* DynamicFontLabel.swift in Sources */,
EECA90AA287449EC0024B301 /* DeveloperFlagsView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ final class ConversationListViewController: UIViewController {
/// internal View Model
var state: ConversationListState = .conversationList

private var previouslySelectedTabIndex = MainTabBarControllerTab.conversations

/// private
private var viewDidAppearCalled = false
private static let contentControllerBottomInset: CGFloat = 16
Expand Down Expand Up @@ -185,8 +183,6 @@ final class ConversationListViewController: UIViewController {
if !viewDidAppearCalled {
viewDidAppearCalled = true

tabBarController?.delegate = self

zClientViewController?.showAvailabilityBehaviourChangeAlertIfNeeded()
}
}
Expand Down Expand Up @@ -341,31 +337,6 @@ extension ConversationListViewController: ConversationListContainerViewModelDele
}
}

// MARK: - UITabBarControllerDelegate

extension ConversationListViewController: UITabBarControllerDelegate {

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {

switch MainTabBarControllerTab(rawValue: tabBarController.selectedIndex) {
case .contacts:
presentPeoplePicker { [self] in
tabBarController.selectedIndex = previouslySelectedTabIndex.rawValue
}
case .conversations, .folders:
previouslySelectedTabIndex = .init(rawValue: tabBarController.selectedIndex) ?? .conversations
case .archive:
setState(.archived, animated: true) { [self] in
tabBarController.selectedIndex = previouslySelectedTabIndex.rawValue
}
case .none:
fallthrough
default:
fatalError("unexpected selected tab index")
}
}
}

private extension NSAttributedString {

static var attributedTextForNoConversationLabel: NSAttributedString? {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// Wire
// Copyright (C) 2024 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//

import UIKit

/// Responds to selected tab changes, ensuring the correct _principle_ tab is selected and `Contacts` or `Archive` views
/// are shown.
///
/// Currently we abuse our main `UITabBarController`. Two tabs (`Conversations` & `Folders`) contain
/// `ConversationListViewController` instances with real content. These are considered `PrincipleTab`s. The other two
/// tabs (`Contacts` & `Archive`) contain **empty** `UIViewController` instances. We use these empty tabs as buttons.
/// When either of these tabs are tapped we switch back to the currently selected _principle tab_ and request it to
/// present the corresponding `Contacts` or `Archive` view.
///
/// - Warning: This solution is only temporary and should be removed in the ongoing navigation overhaul. [WPB-6647]
final class TabBarChangeHandler: NSObject, UITabBarControllerDelegate {

enum PrincipleTab {
case conversations
case folders
}

private let conversationsViewController: ConversationListViewController
private let foldersViewController: ConversationListViewController
private var principleTab: PrincipleTab

/// Initializes a `TabBarChangeHandler`.
/// - Parameters:
/// - conversationsViewController: The view controller corresponding the `Conversations` tab.
/// - foldersViewController: The view controller corresponding the `Folders` tab.
/// - selectedTab: The initially selected tab.
init(
conversationsViewController: ConversationListViewController,
foldersViewController: ConversationListViewController,
selectedTab: PrincipleTab
) {
self.conversationsViewController = conversationsViewController
self.foldersViewController = foldersViewController
self.principleTab = selectedTab
}

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
guard let selectedIndex = MainTabBarControllerTab(rawValue: tabBarController.selectedIndex) else {
fatalError("unexpected selected tab index")
}

switch selectedIndex {
case .contacts:
principleViewController.presentPeoplePicker { [self] in
tabBarController.selectedIndex = principleTabIndex
}
case .conversations:
principleTab = .conversations
case .folders:
principleTab = .folders
case .archive:
principleViewController.setState(.archived, animated: true) { [self] in
tabBarController.selectedIndex = principleTabIndex
}
}
}

private var principleViewController: ConversationListViewController {
switch principleTab {
case .conversations:
conversationsViewController
case .folders:
foldersViewController
}
}

private var principleTabIndex: Int {
switch principleTab {
case .conversations:
MainTabBarControllerTab.conversations.rawValue
case .folders:
MainTabBarControllerTab.folders.rawValue
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ final class ZClientViewController: UIViewController {
// TODO [WPB-9867]: make private or remove this property
private(set) var mediaPlaybackManager: MediaPlaybackManager?
private(set) var mainTabBarController: UITabBarController!
// TODO [WPB-6647]: Remove in navigation overhaul
private var tabBarChangeHandler: TabBarChangeHandler!

private var selfProfileViewControllerBuilder: SelfProfileViewControllerBuilder {
.init(
Expand Down Expand Up @@ -197,6 +199,15 @@ final class ZClientViewController: UIViewController {
)
wireSplitViewController.leftViewController = mainTabBarController

// TODO [WPB-6647]: Remove in navigation overhaul
// `selectedTab` must be in sync with tab set in MainTabBarController(contacts:conversations:folders:archive:)
tabBarChangeHandler = TabBarChangeHandler(
conversationsViewController: conversationListViewController,
foldersViewController: conversationListWithFoldersViewController,
selectedTab: .conversations
)
mainTabBarController.delegate = tabBarChangeHandler

if pendingInitialStateRestore {
restoreStartupState()
}
Expand Down

0 comments on commit fd0295d

Please sign in to comment.