Skip to content

Commit

Permalink
Merge pull request #231 from weiran/swiftui-login
Browse files Browse the repository at this point in the history
New Login UI
  • Loading branch information
weiran authored Apr 9, 2022
2 parents 68d8f85 + 4048c17 commit bd2fab7
Show file tree
Hide file tree
Showing 19 changed files with 321 additions and 359 deletions.
4 changes: 3 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ type_name:
identifier_name:
excluded:
- id
- by
- by
allowed_symbols:
- _body
5 changes: 2 additions & 3 deletions App/Comments/CommentsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import PromiseKit
import Loaf

class CommentsViewController: UITableViewController {
var authenticationUIService: AuthenticationUIService?
var swipeCellKitActions: SwipeCellKitActions?
var navigationService: NavigationService?

Expand Down Expand Up @@ -288,7 +287,7 @@ extension CommentsViewController {
switch error {
case .unauthenticated:
self.present(
self.authenticationUIService!.unauthenticatedAlertController(),
AuthenticationHelper.unauthenticatedAlertController(self),
animated: true
)
default:
Expand Down Expand Up @@ -324,7 +323,7 @@ extension CommentsViewController {
switch error {
case .unauthenticated:
self.present(
self.authenticationUIService!.unauthenticatedAlertController(),
AuthenticationHelper.unauthenticatedAlertController(self),
animated: true
)
default:
Expand Down
13 changes: 2 additions & 11 deletions App/Extensions/SwinjectStoryboardExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,19 @@ extension SwinjectStoryboard {
@objc class func setup() {
let container = defaultContainer

container.storyboardInitCompleted(FeedCollectionViewController.self) { resolver, controller in
controller.authenticationUIService = resolver.resolve(AuthenticationUIService.self)!
}
container.storyboardInitCompleted(CommentsViewController.self) { resolver, controller in
controller.authenticationUIService = resolver.resolve(AuthenticationUIService.self)!
controller.swipeCellKitActions = resolver.resolve(SwipeCellKitActions.self)!
controller.navigationService = resolver.resolve(NavigationService.self)!
}
container.storyboardInitCompleted(SettingsViewController.self) { resolver, controller in
controller.sessionService = resolver.resolve(SessionService.self)!
controller.authenticationUIService = resolver.resolve(AuthenticationUIService.self)!
}

container.register(SessionService.self) { _ in
SessionService()
}.inObjectScope(.container)
container.register(AuthenticationUIService.self) { resolver in
AuthenticationUIService(sessionService: resolver.resolve(SessionService.self)!)
}.inObjectScope(.container)
container.register(SwipeCellKitActions.self) { resolver in
SwipeCellKitActions(
authenticationUIService: resolver.resolve(AuthenticationUIService.self)!)
container.register(SwipeCellKitActions.self) { _ in
SwipeCellKitActions()
}
container.register(NavigationService.self) { _ in
NavigationService()
Expand Down
38 changes: 38 additions & 0 deletions App/Extensions/SwinjectSwiftUI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// SwinjectSwiftUI.swift
// Hackers
//
// Created by Weiran Zhang on 04/04/2022.
// Copyright © 2022 Glass Umbrella. All rights reserved.
//

import SwiftUI
import Swinject
import SwinjectStoryboard

@propertyWrapper
struct Inject<Component> {
let wrappedValue: Component
init() {
self.wrappedValue = Resolver.shared.resolve(Component.self)
}
}

class Resolver {
static let shared = Resolver()
private let container = buildContainer()

func resolve<T>(_ type: T.Type) -> T {
container.resolve(T.self)!
}
}

func buildContainer() -> Container {
let container = SwinjectStoryboard.defaultContainer

container.register(SessionService.self) { _ in
return SessionService()
}.inObjectScope(.container)

return container
}
8 changes: 2 additions & 6 deletions App/Feed/FeedCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import Loaf
class FeedCollectionViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!

var authenticationUIService: AuthenticationUIService?

private lazy var dataSource = makeDataSource()
private lazy var viewModel = FeedViewModel()

Expand Down Expand Up @@ -299,16 +297,14 @@ extension FeedCollectionViewController {
}

private func handleVoteError(error: Error) {
guard
let error = error as? HackersKitError,
let authenticationUIService = self.authenticationUIService else {
guard let error = error as? HackersKitError else {
return
}

switch error {
case .unauthenticated:
self.present(
authenticationUIService.unauthenticatedAlertController(),
AuthenticationHelper.unauthenticatedAlertController(self),
animated: true
)
default:
Expand Down
Loading

0 comments on commit bd2fab7

Please sign in to comment.