diff --git a/Icro.xcodeproj/project.pbxproj b/Icro.xcodeproj/project.pbxproj index c50d9d3e..c696ed27 100644 --- a/Icro.xcodeproj/project.pbxproj +++ b/Icro.xcodeproj/project.pbxproj @@ -42,7 +42,6 @@ 5B609F182309203400F2C1BC /* ItemNavigator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B609F172309203400F2C1BC /* ItemNavigator.swift */; }; 5B609F1A2309204B00F2C1BC /* TipJarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B609F192309204B00F2C1BC /* TipJarViewModel.swift */; }; 5B609F1C2309206600F2C1BC /* ComposeNavigator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B609F1B2309206600F2C1BC /* ComposeNavigator.swift */; }; - 5B689BAD20837ECE005B9874 /* TabBarViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B689BAB20837ECE005B9874 /* TabBarViewController.xib */; }; 5B69E65122AA16310081CDFB /* SettingsContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B69E65022AA16310081CDFB /* SettingsContentView.swift */; }; 5B8754FA2070137300018DFA /* TabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B8754F92070137300018DFA /* TabBarViewController.swift */; }; 5B99C67A229FB47200437552 /* UITableView+Keyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B99C679229FB47200437552 /* UITableView+Keyboard.swift */; }; @@ -113,6 +112,7 @@ C5046553274F795A0004B812 /* Sourceful in Frameworks */ = {isa = PBXBuildFile; productRef = C5046552274F795A0004B812 /* Sourceful */; }; C51F8480267F1FFB002A018E /* Client in Frameworks */ = {isa = PBXBuildFile; productRef = C51F847F267F1FFB002A018E /* Client */; }; C544111E23F7CED800428609 /* Client in Frameworks */ = {isa = PBXBuildFile; productRef = C544111D23F7CED800428609 /* Client */; }; + C5443C642758AF1500F5BB1C /* LoginOverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5443C632758AF1500F5BB1C /* LoginOverlayView.swift */; }; C5454DAE23CB9A5C00739A6C /* VerticalTabView in Frameworks */ = {isa = PBXBuildFile; productRef = C5454DAD23CB9A5C00739A6C /* VerticalTabView */; }; C5454DB023CB9F4A00739A6C /* Settings in Frameworks */ = {isa = PBXBuildFile; productRef = C5454DAF23CB9F4A00739A6C /* Settings */; }; C5454DB223CB9F5000739A6C /* VerticalTabView in Frameworks */ = {isa = PBXBuildFile; productRef = C5454DB123CB9F5000739A6C /* VerticalTabView */; }; @@ -329,7 +329,6 @@ 5B66EE6D227D734800317FE3 /* MediaEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaEndpoint.swift; sourceTree = ""; }; 5B66EE73227D74DF00317FE3 /* MockClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockClient.swift; sourceTree = ""; }; 5B66EE75227D780300317FE3 /* UserListViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserListViewModelTests.swift; sourceTree = ""; }; - 5B689BAB20837ECE005B9874 /* TabBarViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = TabBarViewController.xib; path = ViewController/TabBarViewController.xib; sourceTree = ""; }; 5B69E65022AA16310081CDFB /* SettingsContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SettingsContentView.swift; path = View/Settings/SettingsContentView.swift; sourceTree = ""; }; 5B6A565C21735A4F003C4D92 /* Functions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Functions.swift; sourceTree = ""; }; 5B6BCC3021A2F215007225C2 /* LoadMoreCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadMoreCell.swift; sourceTree = ""; }; @@ -385,6 +384,7 @@ 7D2709F418E0D6293A75A02B /* Pods_Icro_Share.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Icro_Share.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B2175C9DAAFEF9FA508D0A47 /* Pods_Icro_Mac.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Icro_Mac.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BF71E43E214287CF007E88BF /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = ""; }; + C5443C632758AF1500F5BB1C /* LoginOverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LoginOverlayView.swift; path = View/LoginOverlayView.swift; sourceTree = ""; }; C5454DA723CB991A00739A6C /* VerticalTabView */ = {isa = PBXFileReference; lastKnownFileType = folder; path = VerticalTabView; sourceTree = ""; }; C550D7782740F0BC00E10CF6 /* Style */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Style; sourceTree = ""; }; C550D77F2740F79000E10CF6 /* Font+Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+Settings.swift"; sourceTree = ""; }; @@ -757,7 +757,6 @@ 5B609F1123091FD500F2C1BC /* ListViewController.swift */, 5B609F1223091FD600F2C1BC /* ListViewController.xib */, 5B8754F92070137300018DFA /* TabBarViewController.swift */, - 5B689BAB20837ECE005B9874 /* TabBarViewController.xib */, 5B20951C22F6B05800C06123 /* VerticalTabsSplitViewController.swift */, ); name = ViewController; @@ -980,6 +979,7 @@ 5B51621A22B2C900009C0064 /* LoginView.swift */, 5B165D8722BF436D00B851B2 /* TipJarView.swift */, 5B28C8CF22C89B2600A46C52 /* UserListView.swift */, + C5443C632758AF1500F5BB1C /* LoginOverlayView.swift */, ); name = View; sourceTree = ""; @@ -1276,7 +1276,6 @@ C5FA2ACB1EB4482C006DEB40 /* Assets.xcassets in Resources */, 5B609F1423091FD600F2C1BC /* ListViewController.xib in Resources */, 5B20952122F6B0CF00C06123 /* acknowledgements.json in Resources */, - 5B689BAD20837ECE005B9874 /* TabBarViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1392,6 +1391,7 @@ 5B69E65122AA16310081CDFB /* SettingsContentView.swift in Sources */, 5BA6D181208904D300F484B2 /* AppNavigator.swift in Sources */, 5B39B7BE22AD504A004D5134 /* ListView.swift in Sources */, + C5443C642758AF1500F5BB1C /* LoginOverlayView.swift in Sources */, C58956EB27500B3D00B7E392 /* Date+Ago.swift in Sources */, 5B583723212861220076121E /* ProfileViewConfigurator.swift in Sources */, C58956EC27500B3D00B7E392 /* ListViewModelListType.swift in Sources */, diff --git a/Icro/View/LoginOverlayView.swift b/Icro/View/LoginOverlayView.swift new file mode 100644 index 00000000..010c4eb5 --- /dev/null +++ b/Icro/View/LoginOverlayView.swift @@ -0,0 +1,39 @@ +// +// SwiftUIView.swift +// Icro +// +// Created by martinhartl on 02.12.21. +// Copyright © 2021 Martin Hartl. All rights reserved. +// + +import SwiftUI + +struct LoginOverlayView: View { + private let didSelectLogin: () -> Void + + init(didSelectLogin: @escaping () -> Void) { + self.didSelectLogin = didSelectLogin + } + + var body: some View { + VStack(spacing: 10.0) { + Text("You need to be logged in") + .font(.headline) + Button { + didSelectLogin() + } label: { + Text("Log In") + .font(.headline) + } + + } + } +} + +struct LoginOverlayView_Previews: PreviewProvider { + static var previews: some View { + LoginOverlayView { + print("Login") + } + } +} diff --git a/Icro/ViewController/ListViewController.swift b/Icro/ViewController/ListViewController.swift index 1d45d9b7..30e5b97e 100644 --- a/Icro/ViewController/ListViewController.swift +++ b/Icro/ViewController/ListViewController.swift @@ -6,6 +6,7 @@ import UIKit import Style import DropdownTitleView +import SwiftUI final class ListViewController: UIViewController, LoadingViewController { @IBOutlet fileprivate weak var tableView: UITableView! { @@ -31,14 +32,15 @@ final class ListViewController: UIViewController, LoadingViewController { @IBOutlet private weak var unreadView: UIView! @IBOutlet private weak var unreadLabel: UILabel! - @IBOutlet private weak var loginLabel: UILabel! - @IBOutlet private weak var loginView: UIView! + private var isLoading = false private var rowHeightEstimate = [String: CGFloat]() private let notificationCenter: NotificationCenter private let loadingSpinner = UIActivityIndicatorView(style: .medium) private let loadingBarButtonItem: UIBarButtonItem + private let loginOverlayHostingViewController: UIHostingController + private var dataSource: UITableViewDiffableDataSource? init(viewModel: ListViewModel, @@ -51,6 +53,11 @@ final class ListViewController: UIViewController, LoadingViewController { editActionsConfigurator = EditActionsConfigurator(itemNavigator: itemNavigator, viewModel: viewModel) self.notificationCenter = notificationCenter self.loadingBarButtonItem = UIBarButtonItem(customView: loadingSpinner) + self.loginOverlayHostingViewController = UIHostingController( + rootView: LoginOverlayView { [weak itemNavigator] in + itemNavigator?.showLogin() + } + ) super.init(nibName: "ListViewController", bundle: nil) @@ -124,7 +131,13 @@ final class ListViewController: UIViewController, LoadingViewController { super.viewWillAppear(animated) updateAppearance() updateDiscoverySectionsIfNeeded() - loginView.isHidden = !viewModel.showsLoginView + + if viewModel.showsLoginView { + showLoginOverlay() + } else { + hideLoginOverlay() + } + navigationItem.rightBarButtonItem?.isEnabled = viewModel.barButtonEnabled navigationItem.leftBarButtonItem?.isEnabled = viewModel.barButtonEnabled } @@ -216,6 +229,19 @@ final class ListViewController: UIViewController, LoadingViewController { } #endif } + + private func showLoginOverlay() { + addChild(loginOverlayHostingViewController) + loginOverlayHostingViewController.view.frame = view.bounds + view.addSubview(loginOverlayHostingViewController.view) + loginOverlayHostingViewController.didMove(toParent: self) + } + + private func hideLoginOverlay() { + loginOverlayHostingViewController.willMove(toParent: nil) + loginOverlayHostingViewController.view.removeFromSuperview() + loginOverlayHostingViewController.removeFromParent() + } } extension ListViewController: UITableViewDelegate { diff --git a/Icro/ViewController/ListViewController.xib b/Icro/ViewController/ListViewController.xib index ef4c797d..835f5f24 100644 --- a/Icro/ViewController/ListViewController.xib +++ b/Icro/ViewController/ListViewController.xib @@ -1,17 +1,16 @@ - + - + + - - @@ -25,7 +24,7 @@ - + @@ -55,53 +54,17 @@ - - - - - - - - - - - - - - - - - - - - + - - - - - @@ -112,5 +75,8 @@ + + + diff --git a/Icro/ViewController/TabBarViewController.xib b/Icro/ViewController/TabBarViewController.xib deleted file mode 100644 index 21a35c1b..00000000 --- a/Icro/ViewController/TabBarViewController.xib +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/IcroUIKit/Navigator/ItemNavigatorProtocol.swift b/IcroUIKit/Navigator/ItemNavigatorProtocol.swift index 013d736c..cb0fbe86 100644 --- a/IcroUIKit/Navigator/ItemNavigatorProtocol.swift +++ b/IcroUIKit/Navigator/ItemNavigatorProtocol.swift @@ -5,7 +5,7 @@ import UIKit -public protocol ItemNavigatorProtocol { +public protocol ItemNavigatorProtocol: AnyObject { func open(url: URL) func open(author: Author) diff --git a/IcroUIKit/View/SingleImageCollectionViewCell.swift b/IcroUIKit/View/SingleImageCollectionViewCell.swift index 680a18b0..8daf97ba 100644 --- a/IcroUIKit/View/SingleImageCollectionViewCell.swift +++ b/IcroUIKit/View/SingleImageCollectionViewCell.swift @@ -17,6 +17,7 @@ final class SingleImageCollectionViewCell: UICollectionViewCell { let imageView: UIImageView = { let imageView = UIImageView() + imageView.contentMode = .scaleAspectFit imageView.translatesAutoresizingMaskIntoConstraints = false return imageView