Skip to content

Commit

Permalink
Router.
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBonus committed Jan 7, 2018
1 parent d2799fd commit 4658b5a
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Adamant-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
E9E7CD9120026FA100DFC4DB /* SwinjectDependencies.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E7CD9020026FA100DFC4DB /* SwinjectDependencies.swift */; };
E9E7CD932002740500DFC4DB /* AdamantLoginService.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E7CD922002740500DFC4DB /* AdamantLoginService.swift */; };
E9E7CD952002812400DFC4DB /* LoginDependencies.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E7CD942002812400DFC4DB /* LoginDependencies.swift */; };
E9E7CDAF2002B8A100DFC4DB /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E7CDAE2002B8A100DFC4DB /* Router.swift */; };
E9E7CDB32002B9FB00DFC4DB /* LoginRoutes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E7CDB22002B9FB00DFC4DB /* LoginRoutes.swift */; };
E9E7CDB52002BA6900DFC4DB /* SwinjectedRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E7CDB42002BA6900DFC4DB /* SwinjectedRouter.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -75,6 +78,9 @@
E9E7CD9020026FA100DFC4DB /* SwinjectDependencies.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwinjectDependencies.swift; sourceTree = "<group>"; };
E9E7CD922002740500DFC4DB /* AdamantLoginService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantLoginService.swift; sourceTree = "<group>"; };
E9E7CD942002812400DFC4DB /* LoginDependencies.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginDependencies.swift; sourceTree = "<group>"; };
E9E7CDAE2002B8A100DFC4DB /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
E9E7CDB22002B9FB00DFC4DB /* LoginRoutes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginRoutes.swift; sourceTree = "<group>"; };
E9E7CDB42002BA6900DFC4DB /* SwinjectedRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwinjectedRouter.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -150,6 +156,7 @@
E91947AB20001A9A001362F8 /* ApiService.swift */,
E9E7CD8A20026B0600DFC4DB /* LoginService.swift */,
E9E7CD8C20026B6600DFC4DB /* DialogService.swift */,
E9E7CDAE2002B8A100DFC4DB /* Router.swift */,
);
path = ServiceProtocols;
sourceTree = "<group>";
Expand All @@ -161,6 +168,7 @@
E9E7CD922002740500DFC4DB /* AdamantLoginService.swift */,
E913C9161FFFAF76001A83F7 /* JSAdamantCore.swift */,
E9E7CD8E20026CD300DFC4DB /* SwinjectedDialogService.swift */,
E9E7CDB42002BA6900DFC4DB /* SwinjectedRouter.swift */,
);
path = Services;
sourceTree = "<group>";
Expand Down Expand Up @@ -198,6 +206,7 @@
E919479920000FFD001362F8 /* Stories */ = {
isa = PBXGroup;
children = (
E9E7CDA52002AE1C00DFC4DB /* Account */,
E919479A20001007001362F8 /* Login */,
);
path = Stories;
Expand All @@ -208,6 +217,7 @@
children = (
E919479D20001048001362F8 /* Login.storyboard */,
E9E7CD942002812400DFC4DB /* LoginDependencies.swift */,
E9E7CDB22002B9FB00DFC4DB /* LoginRoutes.swift */,
E919479B2000102E001362F8 /* LoginViewController.swift */,
);
path = Login;
Expand Down Expand Up @@ -383,7 +393,10 @@
E9E7CD932002740500DFC4DB /* AdamantLoginService.swift in Sources */,
E91947B420002809001362F8 /* Account.swift in Sources */,
E913C8F41FFFA51D001A83F7 /* ViewController.swift in Sources */,
E9E7CDB52002BA6900DFC4DB /* SwinjectedRouter.swift in Sources */,
E9E7CDAF2002B8A100DFC4DB /* Router.swift in Sources */,
E913C90B1FFFA965001A83F7 /* AdamantHash.swift in Sources */,
E9E7CDB32002B9FB00DFC4DB /* LoginRoutes.swift in Sources */,
E91947B22000246A001362F8 /* AdamantError.swift in Sources */,
E913C8F21FFFA51D001A83F7 /* AppDelegate.swift in Sources */,
E913C90D1FFFA99B001A83F7 /* Keypair.swift in Sources */,
Expand Down
53 changes: 53 additions & 0 deletions Adamant-ios/ServiceProtocols/Router.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Router.swift
// Adamant-ios
//
// Created by Anokhov Pavel on 07.01.2018.
// Copyright © 2018 Adamant. All rights reserved.
//

import UIKit

// MARK: - Adamant Story struct
struct AdamantStory: Equatable, Hashable {
let name: String

init(_ name: String) {
self.name = name
}

static func ==(lhs: AdamantStory, rhs: AdamantStory) -> Bool {
return lhs.name == rhs.name
}

var hashValue: Int {
return name.hashValue &* 171717
}
}

// MARK: - Adamant Scene
struct AdamantScene: Equatable, Hashable {
let identifier: String
let story: AdamantStory

init(story: AdamantStory, identifier: String) {
self.story = story
self.identifier = identifier
}

static func ==(lhs: AdamantScene, rhs: AdamantScene) -> Bool {
return lhs.identifier == rhs.identifier
}

var hashValue: Int {
return identifier.hashValue ^ story.hashValue &* 717171
}
}



// MARK: - Adamant Router
protocol Router {
func get(story: AdamantStory) -> UIStoryboard
func get(scene: AdamantScene) -> UIViewController
}
2 changes: 2 additions & 0 deletions Adamant-ios/Services/AdamantLoginService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import UIKit
class AdamantLoginService: LoginService {
private struct Constants {
static let loginStoryboard = "Login"

private init() {}
}

// MARK: - Dependencies
Expand Down
28 changes: 28 additions & 0 deletions Adamant-ios/Services/SwinjectedRouter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// SwinjectedRouter.swift
// Adamant-ios
//
// Created by Anokhov Pavel on 07.01.2018.
// Copyright © 2018 Adamant. All rights reserved.
//

import UIKit
import SwinjectStoryboard

class SwinjectedRouter: Router {
private var storyboards = [AdamantStory: UIStoryboard]()

func get(story: AdamantStory) -> UIStoryboard {
if let storyboard = storyboards[story] {
return storyboard
} else {
let storyboard = SwinjectStoryboard.create(name: story.name, bundle: nil)
storyboards[story] = storyboard
return storyboard
}
}

func get(scene: AdamantScene) -> UIViewController {
return get(story: scene.story).instantiateViewController(withIdentifier: scene.identifier)
}
}
2 changes: 1 addition & 1 deletion Adamant-ios/Stories/Login/Login.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<!--Login View Controller-->
<scene sceneID="kEg-Ft-tgc">
<objects>
<viewController id="jDW-6I-Kga" customClass="LoginViewController" customModule="Adamant_ios" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="LoginViewController" id="jDW-6I-Kga" customClass="LoginViewController" customModule="Adamant_ios" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="ERy-6e-jpo">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
17 changes: 17 additions & 0 deletions Adamant-ios/Stories/Login/LoginRoutes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// LoginRoutes.swift
// Adamant-ios
//
// Created by Anokhov Pavel on 07.01.2018.
// Copyright © 2018 Adamant. All rights reserved.
//

import Foundation

extension AdamantStory {
static let Login = AdamantStory("Login")
}

extension AdamantScene {
static let LoginDetails = AdamantScene(story: .Login, identifier: "LoginViewController")
}
5 changes: 2 additions & 3 deletions Adamant-ios/SwinjectDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import SwinjectStoryboard
// MARK: Services
extension Container {
func registerAdamantServices(coreJsUrl core: URL, utilitiesJsUrl utils: URL) {
self.register(DialogService.self) { _ in SwinjectedDialogService() }.inObjectScope(.container)
self.register(AdamantCore.self) { _ in try! JSAdamantCore(coreJsUrl: core, utilitiesJsUrl: utils) }

self.register(DialogService.self) { _ in SwinjectedDialogService() }.inObjectScope(.container)
self.register(Router.self) { _ in SwinjectedRouter() }.inObjectScope(.container)
self.register(ApiService.self) { r in AdamantApiService(adamantCore: r.resolve(AdamantCore.self)!) }.inObjectScope(.container)

self.register(LoginService.self) { r in
let api = r.resolve(ApiService.self)!
let dialog = r.resolve(DialogService.self)!
Expand Down

0 comments on commit 4658b5a

Please sign in to comment.