-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MBL-854] Gate Creator Dashboard Behind Feature Flag #1828
Changes from all commits
4a246c4
c11a758
b190213
8cd67b1
6e91c2b
a8fcf0c
192da3f
87d71dd
74d59fb
2b30a91
6a338af
aa55b4e
f2760b5
18a1b49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,10 @@ public final class RootTabBarViewController: UITabBarController, MessageBannerVi | |
} | ||
|
||
public func switchToDashboard(project param: Param?) { | ||
guard featureCreatorDashboardEnabled() else { | ||
return | ||
} | ||
|
||
self.viewModel.inputs.switchToDashboard(project: param) | ||
} | ||
|
||
|
@@ -213,6 +217,10 @@ public final class RootTabBarViewController: UITabBarController, MessageBannerVi | |
} | ||
|
||
public func switchToCreatorMessageThread(projectId: Param, messageThread: MessageThread) { | ||
guard featureCreatorDashboardEnabled() else { | ||
return | ||
} | ||
|
||
self.switchToDashboard(project: nil) | ||
|
||
guard | ||
|
@@ -226,6 +234,10 @@ public final class RootTabBarViewController: UITabBarController, MessageBannerVi | |
} | ||
|
||
public func switchToProjectActivities(projectId: Param) { | ||
guard featureCreatorDashboardEnabled() else { | ||
return | ||
} | ||
|
||
self.switchToDashboard(project: nil) | ||
|
||
guard | ||
|
@@ -248,44 +260,68 @@ public final class RootTabBarViewController: UITabBarController, MessageBannerVi | |
case let .search(index): | ||
_ = tabBarItem(atIndex: index) ?|> searchTabBarItemStyle | ||
case let .dashboard(index): | ||
_ = tabBarItem(atIndex: index) ?|> dashboardTabBarItemStyle | ||
let featureFlaggedTabBarItemStyle = self | ||
.isDashboardViewControllerDisplayable() ? dashboardTabBarItemStyle : | ||
profileTabBarItemStyle(isLoggedIn: data.isLoggedIn, isMember: data.isMember) | ||
_ = tabBarItem(atIndex: index) ?|> featureFlaggedTabBarItemStyle | ||
case let .profile(avatarUrl, index): | ||
_ = tabBarItem(atIndex: index) | ||
?|> profileTabBarItemStyle(isLoggedIn: data.isLoggedIn, isMember: data.isMember) | ||
|
||
guard | ||
data.isLoggedIn == true, | ||
let avatarUrl = avatarUrl, | ||
let dir = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first | ||
else { return } | ||
|
||
let hash = avatarUrl.absoluteString.hashValue | ||
let imagePath = "\(dir)/tabbar-avatar-image-\(hash).dat" | ||
let imageUrl = URL(fileURLWithPath: imagePath) | ||
|
||
if let imageData = try? Data(contentsOf: imageUrl) { | ||
let (defaultImage, selectedImage) = tabbarAvatarImageFromData(imageData) | ||
_ = self.tabBarItem(atIndex: index) | ||
?|> profileTabBarItemStyle(isLoggedIn: true, isMember: data.isMember) | ||
?|> UITabBarItem.lens.image .~ defaultImage | ||
?|> UITabBarItem.lens.selectedImage .~ selectedImage | ||
} else { | ||
let sessionConfig = URLSessionConfiguration.default | ||
let session = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: .main) | ||
let dataTask = session.dataTask(with: avatarUrl) { [weak self] avatarData, _, _ in | ||
guard let avatarData = avatarData else { return } | ||
try? avatarData.write(to: imageUrl, options: [.atomic]) | ||
|
||
let (defaultImage, selectedImage) = tabbarAvatarImageFromData(avatarData) | ||
_ = self?.tabBarItem(atIndex: index) | ||
?|> profileTabBarItemStyle(isLoggedIn: true, isMember: data.isMember) | ||
?|> UITabBarItem.lens.image .~ defaultImage | ||
?|> UITabBarItem.lens.selectedImage .~ selectedImage | ||
} | ||
dataTask.resume() | ||
} | ||
setProfileImage(with: data, avatarUrl: avatarUrl, index: index) | ||
} | ||
} | ||
} | ||
|
||
fileprivate func setProfileImage(with data: TabBarItemsData, avatarUrl: URL?, index: Int) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move all the profile downloading to a separate function. |
||
guard | ||
data.isLoggedIn == true, | ||
let avatarUrl = avatarUrl, | ||
let dir = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first | ||
else { return } | ||
|
||
let hash = avatarUrl.absoluteString.hashValue | ||
let imagePath = "\(dir)/tabbar-avatar-image-\(hash).dat" | ||
let imageUrl = URL(fileURLWithPath: imagePath) | ||
|
||
if let imageData = try? Data(contentsOf: imageUrl) { | ||
let (defaultImage, selectedImage) = tabbarAvatarImageFromData(imageData) | ||
_ = self.tabBarItem(atIndex: index) | ||
?|> profileTabBarItemStyle(isLoggedIn: true, isMember: data.isMember) | ||
?|> UITabBarItem.lens.image .~ defaultImage | ||
?|> UITabBarItem.lens.selectedImage .~ selectedImage | ||
} else { | ||
let sessionConfig = URLSessionConfiguration.default | ||
let session = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: .main) | ||
let dataTask = session.dataTask(with: avatarUrl) { [weak self] avatarData, _, _ in | ||
guard let avatarData = avatarData else { return } | ||
try? avatarData.write(to: imageUrl, options: [.atomic]) | ||
|
||
let (defaultImage, selectedImage) = tabbarAvatarImageFromData(avatarData) | ||
_ = self?.tabBarItem(atIndex: index) | ||
?|> profileTabBarItemStyle(isLoggedIn: true, isMember: data.isMember) | ||
?|> UITabBarItem.lens.image .~ defaultImage | ||
?|> UITabBarItem.lens.selectedImage .~ selectedImage | ||
} | ||
dataTask.resume() | ||
} | ||
} | ||
|
||
fileprivate func isDashboardViewControllerDisplayable() -> Bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function just checks if the |
||
guard let navigationControllers = self.viewControllers as? [UINavigationController] else { | ||
return false | ||
} | ||
|
||
var foundDashboardViewController = false | ||
|
||
for navController in navigationControllers { | ||
if let dashboardVC = navController.viewControllers.first as? DashboardViewController { | ||
foundDashboardViewController = true | ||
break | ||
} | ||
} | ||
|
||
return foundDashboardViewController | ||
} | ||
|
||
fileprivate func tabBarItem(atIndex index: Int) -> UITabBarItem? { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,21 +488,30 @@ private func generateStandardViewControllers() -> [RootViewControllerData] { | |
|
||
private func generatePersonalizedViewControllers(userState: (isMember: Bool, isLoggedIn: Bool)) | ||
-> [RootViewControllerData] { | ||
return [.dashboard(isMember: userState.isMember), .profile(isLoggedIn: userState.isLoggedIn)] | ||
if featureCreatorDashboardEnabled() { | ||
return [.dashboard(isMember: userState.isMember), .profile(isLoggedIn: userState.isLoggedIn)] | ||
} | ||
|
||
return [.profile(isLoggedIn: userState.isLoggedIn)] | ||
} | ||
|
||
private func tabData(forUser user: User?) -> TabBarItemsData { | ||
let isMember = | ||
(user?.stats.memberProjectsCount ?? 0) > 0 | ||
let items: [TabBarItem] = isMember | ||
? [ | ||
.home(index: 0), .activity(index: 1), .search(index: 2), .dashboard(index: 3), | ||
.profile(avatarUrl: (user?.avatar.small).flatMap(URL.init(string:)), index: 4) | ||
] | ||
: [ | ||
let items: [TabBarItem] | ||
|
||
switch isMember { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the idea is that the tabs are based on the user. And they don't need gating because this tab data is only used for styling - the actual setting of the tabs in the tab bar is done in |
||
case false: | ||
items = [ | ||
.home(index: 0), .activity(index: 1), .search(index: 2), | ||
.profile(avatarUrl: (user?.avatar.small).flatMap(URL.init(string:)), index: 3) | ||
] | ||
case true: | ||
items = [ | ||
.home(index: 0), .activity(index: 1), .search(index: 2), .dashboard(index: 3), | ||
.profile(avatarUrl: (user?.avatar.small).flatMap(URL.init(string:)), index: 4) | ||
] | ||
} | ||
|
||
return TabBarItemsData( | ||
items: items, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is called as a result of
tabData(forUser
and it checks if that tab is available before styling it. So if we sent "Explore, Activity, Search, Dashboard and Profile" to this function - the view controllers may only be "Explore, Activity, Search and Profile". Which means thatDashboard
case updates its styling to reflect "Profile" and theProfile
case doesn't update anything - the tab doesn't exist.self.tabBar.items
is called under the hood fortabBarItem(atIndex:
and reflects the view controllers - which are independently set bysetViewControllers
(whenever that happens).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only trade-off is that we lose the Profile user avatar, if they were a creator logged in with the dashboard hidden. I think its' worth it because this only affects logged in creators and not backers and we're removing creator login functionality anyway.