Skip to content

Commit 0b2cc54

Browse files
authored
[Fix] #788 - 탭 바 전환 로직 수정
[Fix] #788 - 탭 바 전환 로직 수정
2 parents d87c0a4 + a2038a5 commit 0b2cc54

File tree

6 files changed

+41
-34
lines changed

6 files changed

+41
-34
lines changed

SOPT-iOS/Projects/Core/Sources/Enum/TabBarItemType.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import Foundation
1010

1111
public enum TabBarItemType: Int, CaseIterable {
1212
case home
13-
case poke
1413
case soptamp
14+
case poke
1515
case soptlog
1616
}
1717

@@ -25,27 +25,34 @@ public extension TabBarItemType {
2525
}
2626
}
2727

28+
/// 유저타입 별 탭 바 인덱스 매핑
2829
func getTabIndex(userType: UserType) -> Int {
2930
switch userType {
3031
case .active:
31-
switch self {
32-
case .home:
33-
0
34-
case .soptamp:
35-
1
36-
case .poke:
37-
2
38-
case .soptlog:
39-
3
40-
}
32+
return self.rawValue
4133
case .visitor, .inactive:
4234
switch self {
4335
case .home, .soptamp:
44-
0
36+
return 0
4537
case .poke:
46-
1
38+
return 1
4739
case .soptlog:
48-
2
40+
return 2
41+
}
42+
}
43+
}
44+
45+
/// 실제 탭바 인덱스 -> TabBarItemType
46+
static func from(index: Int, userType: UserType) -> TabBarItemType? {
47+
switch userType {
48+
case .active:
49+
return TabBarItemType(rawValue: index)
50+
case .visitor, .inactive:
51+
switch index {
52+
case 0: return .home
53+
case 1: return .poke
54+
case 2: return .soptlog
55+
default: return nil
4956
}
5057
}
5158
}

SOPT-iOS/Projects/Features/RootFeature/Sources/ApplicationCoordinator+Delegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension ApplicationCoordinator: TabBarCoordinatorDelegate {
4848
}
4949

5050
private func selectedTab(_ tab: TabBarItemType) {
51-
self.tabBarController?.selectedIndex = tab.rawValue
51+
self.tabBarController?.selectedIndex = tab.getTabIndex(userType: UserDefaultKeyList.Auth.getUserType())
5252
}
5353
}
5454

SOPT-iOS/Projects/Features/TabBarFeature/Interface/Sources/TabBarPresentable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import BaseFeatureDependency
1313
import Core
1414

1515
public protocol TabBarCoordinatable {
16-
var onTabBarItemTapped: ((Int) -> Void)? { get set }
16+
var onTabBarItemTapped: ((TabBarItemType) -> Void)? { get set }
1717
var showTabBarAlert: (() -> Void)? { get set }
1818
}
1919
public typealias TabBarViewModelType = ViewModelType & TabBarCoordinatable

SOPT-iOS/Projects/Features/TabBarFeature/Sources/Coordinator/LegacyTabBarCoordinator.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public final class LegacyTabBarCoordinator: DefaultTabBarCoordinator {
3838
private func showTabBar() {
3939
var tabBar = factory
4040

41-
tabBar.vm.onTabBarItemTapped = { [weak self] index in
41+
tabBar.vm.onTabBarItemTapped = { [weak self] tabType in
4242
// 각 탭의 코디네이터 실행
43-
switch index {
44-
case 0:
43+
switch tabType {
44+
case .home:
4545
self?.requestCoordinating?(.home)
46-
case 1:
46+
case .soptlog:
4747
self?.requestCoordinating?(.soptlog)
4848
default:
4949
return

SOPT-iOS/Projects/Features/TabBarFeature/Sources/Coordinator/TabBarCoordinator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ public final class TabBarCoordinator: BaseCoordinator {
6767
private func showTabBar() {
6868
var tabBar = factory.makeTabBar(with: views, userType: userType, coordinator: self)
6969

70-
tabBar.vm.onTabBarItemTapped = { [weak self] index in
70+
tabBar.vm.onTabBarItemTapped = { [weak self] tabType in
7171
// 각 탭의 코디네이터 실행
72-
guard let self = self,
73-
let tabType = TabBarItemType(rawValue: index) else { return }
72+
guard let self = self else { return }
73+
7474
switch tabType {
7575
case .home:
7676
self.delegate?.tabBarCoordinator(self, to: .home)
77-
case .poke:
78-
self.delegate?.tabBarCoordinator(self, to: .poke)
7977
case .soptamp:
8078
self.delegate?.tabBarCoordinator(self, to: .soptamp)
79+
case .poke:
80+
self.delegate?.tabBarCoordinator(self, to: .poke)
8181
case .soptlog:
8282
self.delegate?.tabBarCoordinator(self, to: .soptlog)
8383
}

SOPT-iOS/Projects/Features/TabBarFeature/Sources/ViewModel/TabBarViewModel.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ final public class TabBarViewModel: TabBarViewModelType {
1717

1818
// MARK: - Properties
1919

20-
private let cancelBag = CancelBag()
21-
private let userType: UserType
2220
private let coordinator: AnyCoordinatorObject
21+
private let cancelBag = CancelBag()
2322
private let homeUseCase: HomeUseCase
23+
24+
private let userType: UserType
2425
@Published public private(set) var tabBarBadges: [TabBarItemType: String] = [:]
2526

2627
// MARK: - Inputs
@@ -38,7 +39,7 @@ final public class TabBarViewModel: TabBarViewModelType {
3839

3940
// MARK: - TabBarCoordinating
4041

41-
public var onTabBarItemTapped: ((Int) -> Void)?
42+
public var onTabBarItemTapped: ((TabBarItemType) -> Void)?
4243
public var showTabBarAlert: (() -> Void)?
4344

4445
// MARK: - initialization
@@ -63,8 +64,9 @@ extension TabBarViewModel {
6364
input.isTabSelectedIndex
6465
.withUnretained(self)
6566
.sink { owner, index in
66-
owner.onTabBarItemTapped?(index)
67-
owner.trackAmplitude(itemIndex: index)
67+
guard let tabBar = TabBarItemType.from(index: index, userType: owner.userType) else { return }
68+
owner.onTabBarItemTapped?(tabBar)
69+
owner.trackAmplitude(itemType: tabBar)
6870
}.store(in: cancelBag)
6971

7072
return output
@@ -74,10 +76,8 @@ extension TabBarViewModel {
7476
// MARK: - Methods
7577

7678
extension TabBarViewModel {
77-
private func trackAmplitude(itemIndex: Int) {
78-
if let item = TabBarItemType(rawValue: itemIndex) {
79-
AmplitudeInstance.shared.trackWithUserType(event: item.toAmplitudeEventType)
80-
}
79+
private func trackAmplitude(itemType: TabBarItemType) {
80+
AmplitudeInstance.shared.trackWithUserType(event: itemType.toAmplitudeEventType)
8181
}
8282

8383
private func fetchAppServiceBadges() {

0 commit comments

Comments
 (0)