Skip to content
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-856] Banner For Creator Dashboard Deprecation #1830

Merged
merged 13 commits into from
Jul 6, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import KsApi
import Library
import Prelude
import Prelude_UIKit
import SwiftUI
import UIKit

internal final class DashboardViewController: UITableViewController {
Expand All @@ -14,6 +15,12 @@ internal final class DashboardViewController: UITableViewController {
fileprivate let loadingIndicatorView = UIActivityIndicatorView()
fileprivate let backgroundView = UIView()

private var deprecationWarningHostingController: UIViewController? {
self.tabBarController?.children.first { viewController in
viewController is UIHostingController<DashboardDeprecationView>
}
}

internal static func instantiate() -> DashboardViewController {
return Storyboard.Dashboard.instantiate(DashboardViewController.self)
}
Expand Down Expand Up @@ -44,6 +51,10 @@ internal final class DashboardViewController: UITableViewController {
super.viewWillAppear(animated)

self.viewModel.inputs.viewWillAppear(animated: animated)

self.showDeprecationWarning()

self.updateTableViewBottomContentInset()
}

override func bindStyles() {
Expand All @@ -61,6 +72,8 @@ internal final class DashboardViewController: UITableViewController {
super.viewWillDisappear(animated)

self.viewModel.inputs.viewWillDisappear()

self.removeDeprecationWarning()
msadoon marked this conversation as resolved.
Show resolved Hide resolved
}

internal override func bindViewModel() {
Expand Down Expand Up @@ -198,6 +211,49 @@ internal final class DashboardViewController: UITableViewController {
}
}

private func updateTableViewBottomContentInset() {
if let tabController = self.tabBarController as? RootTabBarViewController,
let deprecationWarningHostingController = deprecationWarningHostingController {
self.tableView.contentInset
msadoon marked this conversation as resolved.
Show resolved Hide resolved
.bottom = (tabController.tabBar.bounds.height + deprecationWarningHostingController.view.bounds
.height)
}
}

private func removeDeprecationWarning() {
self.deprecationWarningHostingController?.removeFromParent()

let deprecationWarningView = self.tabBarController?.view.subviews.first(where: { view in
view.viewWithTag(-99) != nil
})

deprecationWarningView?.removeFromSuperview()
}

private func showDeprecationWarning() {
let deprecationWarningHostingController = UIHostingController(rootView: DashboardDeprecationView())

guard let tabController = self.tabBarController as? RootTabBarViewController,
let deprecationWarningView = deprecationWarningHostingController.view else { return }

deprecationWarningView.tag = -99
tabController.addChild(deprecationWarningHostingController)
tabController.view.addSubview(deprecationWarningView)

deprecationWarningHostingController.didMove(toParent: tabController)

deprecationWarningView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint
.activate([
deprecationWarningView.leftAnchor.constraint(equalTo: tabController.view.leftAnchor),
deprecationWarningView.rightAnchor
.constraint(equalTo: tabController.view.rightAnchor),
deprecationWarningView.bottomAnchor.constraint(
equalTo: tabController.tabBar.safeAreaLayoutGuide.topAnchor)
])
}

fileprivate func goToActivity(_ project: Project) {
let vc = ProjectActivitiesViewController.configuredWith(project: project)
self.navigationController?.pushViewController(vc, animated: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Library
import SwiftUI

msadoon marked this conversation as resolved.
Show resolved Hide resolved
struct DashboardDeprecationView: View {
private let contentPadding = 12.0
private let imageSizeMultiplier = 1.5
msadoon marked this conversation as resolved.
Show resolved Hide resolved
private let deprecationDateText = formatted(dateString: "2023-08-14")
msadoon marked this conversation as resolved.
Show resolved Hide resolved

var body: some View {
HStack {
msadoon marked this conversation as resolved.
Show resolved Hide resolved
if let iconImage = image(named: "fix-icon", inBundle: Bundle.framework) {
msadoon marked this conversation as resolved.
Show resolved Hide resolved
Image(uiImage: iconImage)
.frame(width: contentPadding * imageSizeMultiplier)
.scaledToFit()
msadoon marked this conversation as resolved.
Show resolved Hide resolved
.foregroundColor(Color(UIColor.ksr_white))
.padding(.horizontal, contentPadding)
}

Text(Strings.Creator_dashboard_removal_warning(expiration_date: deprecationDateText))
.font(Font(UIFont.ksr_subhead(size: 15)))
.foregroundColor(Color(UIColor.ksr_white))
.lineLimit(nil)
.padding([.vertical, .trailing], contentPadding)
}
.frame(maxWidth: .infinity, alignment: .center)
.background(Color(UIColor.ksr_alert))
}
}

private func formatted(dateString: String) -> String {
let date = toDate(dateString: dateString)
return Format.date(
secondsInUTC: date.timeIntervalSince1970,
template: "MMMM d, yyyy",
timeZone: UTCTimeZone
)
}

private func toDate(dateString: String) -> Date {
// Always use UTC timezone here this date should be timezone agnostic
guard let date = Format.date(
from: dateString,
dateFormat: "yyyy-MM-dd",
timeZone: UTCTimeZone
) else {
fatalError("Unable to parse date format")
}

return date
}
12 changes: 12 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
60DA50FE28C38DDB002E2DF1 /* AlamofireImage in Frameworks */ = {isa = PBXBuildFile; productRef = 60DA50FD28C38DDB002E2DF1 /* AlamofireImage */; };
60DA510F28C7E04B002E2DF1 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 60DA510E28C7E04B002E2DF1 /* Kingfisher */; };
60DA511428C96A65002E2DF1 /* SwiftSoup in Frameworks */ = {isa = PBXBuildFile; productRef = 60DA511328C96A65002E2DF1 /* SwiftSoup */; };
60DF50982A434E75002C771F /* DashboardDeprecationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60DF50962A434E6B002C771F /* DashboardDeprecationView.swift */; };
60EAD1C728D25A36009F9474 /* AppCenterDistribute in Frameworks */ = {isa = PBXBuildFile; productRef = 60EAD1C628D25A36009F9474 /* AppCenterDistribute */; };
701160D4291ECB9F0095BF24 /* LoadingBarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 701160D2291ECB250095BF24 /* LoadingBarButtonItem.swift */; };
70495690299D53ED00B273DF /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 7049568F299D53ED00B273DF /* SnapshotTesting */; };
Expand Down Expand Up @@ -2074,6 +2075,7 @@
608E7A5428ABE27400289E92 /* SetYourPasswordViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetYourPasswordViewModel.swift; sourceTree = "<group>"; };
60DA50E928B68990002E2DF1 /* SetYourPasswordViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetYourPasswordViewModelTests.swift; sourceTree = "<group>"; };
60DA50EF28B69534002E2DF1 /* SetYourPasswordViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetYourPasswordViewControllerTests.swift; sourceTree = "<group>"; };
60DF50962A434E6B002C771F /* DashboardDeprecationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardDeprecationView.swift; sourceTree = "<group>"; };
msadoon marked this conversation as resolved.
Show resolved Hide resolved
701160D2291ECB250095BF24 /* LoadingBarButtonItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingBarButtonItem.swift; sourceTree = "<group>"; };
7061848829BE4C11008F9941 /* MessageBannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageBannerView.swift; sourceTree = "<group>"; };
7061848C29BE577B008F9941 /* MessageBannerViewViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageBannerViewViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4743,6 +4745,7 @@
1937A6E128C92BBD00DD732D /* CuratedProjects */,
19A97CF728C7E40C0031B857 /* Dashboard */,
19A97CFD28C7E6460031B857 /* DashboardProjects */,
60DF50952A434E30002C771F /* DashboardDeprecationBanner */,
1937A6E228C92BD400DD732D /* DebugPushNotifications */,
19A97D0328C7E7350031B857 /* DiscoveryFilters */,
19A97D0928C7EA450031B857 /* Discovery */,
Expand Down Expand Up @@ -5785,6 +5788,14 @@
path = Controller;
sourceTree = "<group>";
};
60DF50952A434E30002C771F /* DashboardDeprecationBanner */ = {
isa = PBXGroup;
children = (
60DF50962A434E6B002C771F /* DashboardDeprecationView.swift */,
);
path = DashboardDeprecationBanner;
sourceTree = "<group>";
};
7061848A29BE4C1E008F9941 /* Views */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -8289,6 +8300,7 @@
8AA3DB33250AE40C009AC8EA /* SettingsViewModel.swift in Sources */,
771E630B23425977005967E8 /* CancelPledgeViewController.swift in Sources */,
06DC4144266FF184005205F7 /* RootCommentCell.swift in Sources */,
60DF50982A434E75002C771F /* DashboardDeprecationView.swift in Sources */,
A75AB2231C8A85D1002FC3E6 /* ActivityUpdateCell.swift in Sources */,
777C60A6241FECD800820C59 /* PersonalizationCell.swift in Sources */,
370C8B64234FCC6F00DE75DD /* LoadingButton.swift in Sources */,
Expand Down