launch main onboarding view from coordinator with localized labels

This commit is contained in:
loj 2019-01-08 21:39:37 +01:00
parent 7fc9c82a44
commit 9936600921
8 changed files with 105 additions and 7 deletions

View File

@ -16,6 +16,7 @@
EE07A46C21E29EA4006031C8 /* BaseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE07A46B21E29EA4006031C8 /* BaseCoordinator.swift */; };
EE07A46E21E3E71B006031C8 /* OnboardingCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE07A46D21E3E71B006031C8 /* OnboardingCoordinator.swift */; };
EE07A47221E3EACE006031C8 /* OnboardingCoordinator.Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE07A47121E3EACE006031C8 /* OnboardingCoordinator.Delegate.swift */; };
EE377EB321E5303E00138385 /* ViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE377EB221E5303D00138385 /* ViewFactory.swift */; };
EE576FFE21CFCC5500433CAB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE576FFD21CFCC5500433CAB /* AppDelegate.swift */; };
EE57700021CFCC5500433CAB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE576FFF21CFCC5500433CAB /* ViewController.swift */; };
EE57700321CFCC5500433CAB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EE57700121CFCC5500433CAB /* Main.storyboard */; };
@ -65,6 +66,7 @@
EE07A46B21E29EA4006031C8 /* BaseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCoordinator.swift; sourceTree = "<group>"; };
EE07A46D21E3E71B006031C8 /* OnboardingCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingCoordinator.swift; sourceTree = "<group>"; };
EE07A47121E3EACE006031C8 /* OnboardingCoordinator.Delegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingCoordinator.Delegate.swift; sourceTree = "<group>"; };
EE377EB221E5303D00138385 /* ViewFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewFactory.swift; sourceTree = "<group>"; };
EE576FFA21CFCC5500433CAB /* ZWallet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZWallet.app; sourceTree = BUILT_PRODUCTS_DIR; };
EE576FFD21CFCC5500433CAB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
EE576FFF21CFCC5500433CAB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@ -135,6 +137,14 @@
path = Infrastructure;
sourceTree = "<group>";
};
EE377EB121E5300400138385 /* Services */ = {
isa = PBXGroup;
children = (
EE377EB221E5303D00138385 /* ViewFactory.swift */,
);
path = Services;
sourceTree = "<group>";
};
EE576FF121CFCC5500433CAB = {
isa = PBXGroup;
children = (
@ -161,6 +171,7 @@
EE57702721D000EE00433CAB /* Definitions */,
EE76B84321D8D1350093571F /* Externals */,
EE07A45321E2498D006031C8 /* Infrastructure */,
EE377EB121E5300400138385 /* Services */,
EE57701F21CFD00100433CAB /* Storyboards */,
EE57702421CFFDB700433CAB /* UIElements */,
EE57702021CFD02900433CAB /* ViewCoordinators */,
@ -406,6 +417,7 @@
EE07A46C21E29EA4006031C8 /* BaseCoordinator.swift in Sources */,
EE57702B21D0230C00433CAB /* ZWProgressBar.swift in Sources */,
EE57702921D0011400433CAB /* Colors.swift in Sources */,
EE377EB321E5303E00138385 /* ViewFactory.swift in Sources */,
EE57700021CFCC5500433CAB /* ViewController.swift in Sources */,
EE07A47221E3EACE006031C8 /* OnboardingCoordinator.Delegate.swift in Sources */,
EE07A45521E24FDD006031C8 /* Localization.swift in Sources */,

View File

@ -28,8 +28,6 @@
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>

View File

@ -12,6 +12,7 @@ import Foundation
internal protocol IocContainerProtocol {
var localizer: Localizable { get }
var viewFactory: ViewFactoryProtocol { get }
}
@ -20,7 +21,10 @@ internal class IocContainer: IocContainerProtocol {
public static let instance = IocContainer()
public lazy var localizer: Localizable = {
let localizer = Localization()
return localizer
return Localization()
}()
public lazy var viewFactory: ViewFactoryProtocol = {
return ViewFactory()
}()
}

View File

@ -16,7 +16,15 @@ internal protocol Localizable: class {
internal class Localization: Localizable {
func localized(_ text: String) -> String {
return NSLocalizedString(text, comment: text)
private var languageBundle: Bundle
private let languageId = "en"
public init() {
let path = Bundle.main.path(forResource: self.languageId, ofType: "lproj")!
self.languageBundle = Bundle(path: path)!
}
public func localized(_ text: String) -> String {
return self.languageBundle.localizedString(forKey: text, value: text, table: "InfoPlist")
}
}

View File

@ -0,0 +1,37 @@
//
// ViewFactory.swift
// ZWallet
//
// Created by loj on 08.01.19.
// Copyright © 2019 XMR Systems LLC. All rights reserved.
//
import Foundation
import UIKit
//internal struct StoryboardScene {
// var storyboardName: String
// var sceneName: String
//}
//
//internal enum Views {
// case onboarding
//}
internal protocol ViewFactoryProtocol {
func getOnboardingMainView() -> MainVC
}
internal class ViewFactory: ViewFactoryProtocol {
private lazy var mainStoryboard: UIStoryboard = {
return UIStoryboard(name: "Main", bundle: nil)
}()
func getOnboardingMainView() -> MainVC {
let vc = self.mainStoryboard.instantiateViewController(withIdentifier: "Main") as! MainVC
return vc
}
}

View File

@ -14,13 +14,30 @@ internal class OnboardingCoordinator: BaseCoordinator {
internal weak var delegate: OnboardingCoordinatorDelegate?
private var iocContainer: IocContainerProtocol
private var viewFactory: ViewFactoryProtocol
private var localizer: Localizable
internal init(navigationController: UINavigationController,
iocContainer: IocContainerProtocol)
{
self.iocContainer = iocContainer
self.viewFactory = self.iocContainer.viewFactory
self.localizer = self.iocContainer.localizer
super.init(navigationController: navigationController)
}
internal func start() {
#warning("implement")
self.showMainView()
}
private func showMainView() {
let vc = self.viewFactory.getOnboardingMainView()
// vc.delegate = self
vc.localizer = self.localizer
self.navigationController.pushViewController(vc, animated: true)
}
}

View File

@ -29,6 +29,11 @@ class MainVC: UIViewController {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.setup()
}
private func setup() {
if let localizer = self.localizer {
self.welcomeLabel.text = localizer.localized("main.welcome")

View File

@ -12,10 +12,27 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var appCoordinator: AppCoordinator!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let navigationController = UINavigationController()
navigationController.setToolbarHidden(true, animated: false)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.tintColor = UIColor.black
self.window?.rootViewController = navigationController
let iocContainer = IocContainer()
self.appCoordinator = AppCoordinator(navigationController: navigationController,
iocContainer: iocContainer)
self.appCoordinator.start()
self.window?.makeKeyAndVisible()
return true
}