Skip to content

Commit

Permalink
Replace LoginOverlay xib with SwiftUI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
hartlco committed Dec 2, 2021
1 parent 466b596 commit 87338e5
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 75 deletions.
8 changes: 4 additions & 4 deletions Icro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 */; };
Expand Down Expand Up @@ -329,7 +329,6 @@
5B66EE6D227D734800317FE3 /* MediaEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaEndpoint.swift; sourceTree = "<group>"; };
5B66EE73227D74DF00317FE3 /* MockClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockClient.swift; sourceTree = "<group>"; };
5B66EE75227D780300317FE3 /* UserListViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserListViewModelTests.swift; sourceTree = "<group>"; };
5B689BAB20837ECE005B9874 /* TabBarViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = TabBarViewController.xib; path = ViewController/TabBarViewController.xib; sourceTree = "<group>"; };
5B69E65022AA16310081CDFB /* SettingsContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SettingsContentView.swift; path = View/Settings/SettingsContentView.swift; sourceTree = "<group>"; };
5B6A565C21735A4F003C4D92 /* Functions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Functions.swift; sourceTree = "<group>"; };
5B6BCC3021A2F215007225C2 /* LoadMoreCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadMoreCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>"; };
C5443C632758AF1500F5BB1C /* LoginOverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LoginOverlayView.swift; path = View/LoginOverlayView.swift; sourceTree = "<group>"; };
C5454DA723CB991A00739A6C /* VerticalTabView */ = {isa = PBXFileReference; lastKnownFileType = folder; path = VerticalTabView; sourceTree = "<group>"; };
C550D7782740F0BC00E10CF6 /* Style */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Style; sourceTree = "<group>"; };
C550D77F2740F79000E10CF6 /* Font+Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+Settings.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -757,7 +757,6 @@
5B609F1123091FD500F2C1BC /* ListViewController.swift */,
5B609F1223091FD600F2C1BC /* ListViewController.xib */,
5B8754F92070137300018DFA /* TabBarViewController.swift */,
5B689BAB20837ECE005B9874 /* TabBarViewController.xib */,
5B20951C22F6B05800C06123 /* VerticalTabsSplitViewController.swift */,
);
name = ViewController;
Expand Down Expand Up @@ -980,6 +979,7 @@
5B51621A22B2C900009C0064 /* LoginView.swift */,
5B165D8722BF436D00B851B2 /* TipJarView.swift */,
5B28C8CF22C89B2600A46C52 /* UserListView.swift */,
C5443C632758AF1500F5BB1C /* LoginOverlayView.swift */,
);
name = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 */,
Expand Down
39 changes: 39 additions & 0 deletions Icro/View/LoginOverlayView.swift
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
32 changes: 29 additions & 3 deletions Icro/ViewController/ListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import UIKit
import Style
import DropdownTitleView
import SwiftUI

final class ListViewController: UIViewController, LoadingViewController {
@IBOutlet fileprivate weak var tableView: UITableView! {
Expand All @@ -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<LoginOverlayView>

private var dataSource: UITableViewDiffableDataSource<ListViewModel.Section, ListViewModel.ViewType>?

init(viewModel: ListViewModel,
Expand All @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
50 changes: 8 additions & 42 deletions Icro/ViewController/ListViewController.xib
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14865.1" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19528" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14819.2"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ListViewController">
<connections>
<outlet property="loginLabel" destination="lzf-hW-gSq" id="Vhb-f2-EhW"/>
<outlet property="loginView" destination="mTp-vb-XJe" id="6Kk-PP-nSS"/>
<outlet property="tableView" destination="6st-4k-O1Z" id="9d4-Qj-kh0"/>
<outlet property="unreadLabel" destination="dTo-bR-xcK" id="nU8-h0-jY7"/>
<outlet property="unreadView" destination="VeU-rW-Mbg" id="89p-Yh-osn"/>
Expand All @@ -25,7 +24,7 @@
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="6st-4k-O1Z">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<color key="separatorColor" name="separatorColor"/>
<connections>
<outlet property="delegate" destination="-1" id="U23-59-Afg"/>
Expand Down Expand Up @@ -55,53 +54,17 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="mTp-vb-XJe">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="qcM-sU-AmK">
<rect key="frame" x="77.5" y="302" width="220" height="63.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="You need to be logged in" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lzf-hW-gSq">
<rect key="frame" x="0.0" y="0.0" width="220" height="20.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MOe-KC-Jyz">
<rect key="frame" x="0.0" y="30.5" width="220" height="33"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<state key="normal" title="Log In"/>
<connections>
<action selector="loginPressed:" destination="-1" eventType="touchUpInside" id="NLa-Jv-3rb"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="width" constant="220" id="onA-de-hu8"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="qcM-sU-AmK" firstAttribute="centerX" secondItem="mTp-vb-XJe" secondAttribute="centerX" id="4Zo-NW-0B2"/>
<constraint firstItem="qcM-sU-AmK" firstAttribute="centerY" secondItem="mTp-vb-XJe" secondAttribute="centerY" id="SbQ-72-5j9"/>
</constraints>
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="CPL-Gv-fyg"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="mTp-vb-XJe" firstAttribute="leading" secondItem="CPL-Gv-fyg" secondAttribute="leading" id="Ds9-PZ-vgS"/>
<constraint firstItem="CPL-Gv-fyg" firstAttribute="bottom" secondItem="6st-4k-O1Z" secondAttribute="bottom" id="ETh-4r-VYt"/>
<constraint firstItem="CPL-Gv-fyg" firstAttribute="trailing" secondItem="mTp-vb-XJe" secondAttribute="trailing" id="TfG-R8-BMr"/>
<constraint firstItem="CPL-Gv-fyg" firstAttribute="bottom" secondItem="mTp-vb-XJe" secondAttribute="bottom" id="VfP-z5-LsQ"/>
<constraint firstItem="6st-4k-O1Z" firstAttribute="leading" secondItem="CPL-Gv-fyg" secondAttribute="leading" id="bkL-ly-8UA"/>
<constraint firstItem="VeU-rW-Mbg" firstAttribute="top" secondItem="6st-4k-O1Z" secondAttribute="top" constant="-4" id="g11-ep-p4W"/>
<constraint firstItem="VeU-rW-Mbg" firstAttribute="leading" secondItem="CPL-Gv-fyg" secondAttribute="leading" constant="12" id="oLW-DA-mFk"/>
<constraint firstItem="CPL-Gv-fyg" firstAttribute="trailing" secondItem="6st-4k-O1Z" secondAttribute="trailing" id="v2N-qK-Ptq"/>
<constraint firstItem="mTp-vb-XJe" firstAttribute="top" secondItem="CPL-Gv-fyg" secondAttribute="top" id="vfm-fR-Wl2"/>
<constraint firstItem="6st-4k-O1Z" firstAttribute="top" secondItem="CPL-Gv-fyg" secondAttribute="top" id="xMl-HH-xv6"/>
</constraints>
<viewLayoutGuide key="safeArea" id="CPL-Gv-fyg"/>
<point key="canvasLocation" x="85.5" y="53.5"/>
</view>
</objects>
Expand All @@ -112,5 +75,8 @@
<namedColor name="separatorColor">
<color white="0.83899998664855957" alpha="0.30000001192092896" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</namedColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
25 changes: 0 additions & 25 deletions Icro/ViewController/TabBarViewController.xib

This file was deleted.

2 changes: 1 addition & 1 deletion IcroUIKit/Navigator/ItemNavigatorProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import UIKit

public protocol ItemNavigatorProtocol {
public protocol ItemNavigatorProtocol: AnyObject {
func open(url: URL)

func open(author: Author)
Expand Down
1 change: 1 addition & 0 deletions IcroUIKit/View/SingleImageCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class SingleImageCollectionViewCell: UICollectionViewCell {

let imageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.translatesAutoresizingMaskIntoConstraints = false

return imageView
Expand Down

0 comments on commit 87338e5

Please sign in to comment.