Skip to content

Instantly share code, notes, and snippets.

View Sajjon's full-sized avatar
💭
Core Developer @ Parity 12ktCaPgc745AwxALoU4E2NAhAc8aW3ytSM5Qigi3SwaNodc

Alexander Cyon Sajjon

💭
Core Developer @ Parity 12ktCaPgc745AwxALoU4E2NAhAc8aW3ytSM5Qigi3SwaNodc
View GitHub Profile
@Sajjon
Sajjon / SignInViewModel.swift
Last active November 27, 2018 13:27
Medium article: SLC part 1 - SignInViewModel
enum SignInNavigationStep {
case signIn
}
final class SignInViewModel: BaseViewModel<
SignInNavigationStep,
SignInViewModel.InputFromView,
SignInViewModel.Output
> {
@Sajjon
Sajjon / AuthenticateNavigationStep.swift
Created November 29, 2018 11:42
Medium article: SLC part 3 - NavigationStep ViewModel
// The cases should be named as if they were prefixed with the words
// "user intends to" or "user did"
enum AuthenticateNavigationStep {
case signIn
case signUp
}
@Sajjon
Sajjon / AppDelegate.swift
Created November 29, 2018 13:32
Medium article: SLC part 3 - AppDelegate
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder {
lazy var window: UIWindow? = .default
private lazy var appCoordinator = AppCoordinator(
window: window!,
deepLinkHandler: DeepLinkHandler(),
useCaseProvider: DefaultUseCaseProvider.shared
)
@Sajjon
Sajjon / AnyCoordinator.swift
Last active November 29, 2018 13:52
Medium article: SLC part 3 - AnyCoordinator
import UIKit
/// Base protocol for any Coordinator. The coordinator is responsible for the navigation logic in the app.
/// Since it has no `associatedtype` we can use it as the element for a `childCoordinators` array, which contains
/// all the children of any coordinator.
protocol AnyCoordinator: AnyObject {
/// Coordinator stack, any child Coordinator should be appended to new array in order to retain it and handle its life cycle.
var childCoordinators: [AnyCoordinator] { get set }
/// This method is invoked by parent coodinator when this coordinator has been retained and presented.
@Sajjon
Sajjon / BaseCoordinator.swift
Created November 29, 2018 13:59
Medium article: SLC part 3 - BaseCoordinator Definition
import UIKit
import RxCocoa
import RxSwift
/// Base class for our coordinators.
class BaseCoordinator<NavigationStep>: AnyCoordinator, Navigating {
/// Coordinator stack, any child Coordinator should be appended to new array in order to retain it and handle its life cycle.
var childCoordinators = [AnyCoordinator]()
@Sajjon
Sajjon / Navigating.swift
Created November 29, 2018 14:03
Medium article: SLC part 3 - Navigating
/// Type capable of navigating. Declaring which navigation steps it can perform, by
/// declaring an `associatedtype` named `NavigationStep` which typically is a nested
/// enum.
protocol Navigating {
associatedtype NavigationStep
var navigator: Navigator<NavigationStep> { get }
}
@Sajjon
Sajjon / BaseCoordinator+StartCoordinator.swift
Created November 29, 2018 14:13
Medium article: SLC part 3 - BaseCoordinator+StartCoordinator
extension BaseCoordinator {
enum CoordinatorTransition {
case append
case replace
}
/// Starts a child coordinator which might be part of a flow of mutiple coordinators.
/// Use this method when you know that you will finish the root coordinator at some
/// point, which also will finish this new child coordinator.
///
@Sajjon
Sajjon / BaseCoordinator+Modal.swift
Created November 29, 2018 15:07
Medium article: SLC part 3 - BaseCoordinator+ModalCoordinator
extension MainCoordinator {
/// Starts a new temporary flow with a new Coordinator.
///
/// "Temporary" meaning that it's expected that the new coordinator (the "child")
/// is expected to finish and when it finishes the calling coordinator (the "parent")
/// will remove it from its `childCoordinator` collection.
///
/// The child coordinator initialized by the parent call-site, in the `makeCoordinator` closure.
/// This function initializes a new `UINavigationController` that is passed into the
/// by the `makeCoordinator` closure as an argument.
@Sajjon
Sajjon / PresentCoordinator+Pincode.swift
Created November 29, 2018 15:19
Medium article: SLC part 3 - Coordinator subscribe to navigation
func toSetPincode() {
presentModalCoordinator(
makeCoordinator: { SetPincodeCoordinator(navigationController: $0, useCase: useCaseProvider.makePincodeUseCase()) },
navigationHandler: { userDid, dismissModalFlow in
switch userDid {
case .setPincode: dismissModalFlow(true)
}
})
}
@Sajjon
Sajjon / BaseCoordinator+PushScene.swift
Last active November 30, 2018 10:42
Medium article: SLC part 3 - BaseCoordinator Push Scene.
extension BaseCoordinator {
/// This method is used to push a new Scene (ViewController).
///
/// - Parameters:
/// - scene: Type of `Scene` (UIViewController) to present.
/// - viewModel: An instance of the ViewModel used by the `Scene`s View.
/// - animated: Whether to animate the presentation of the scene or not.
/// - navigationPresentationCompletion: Optional closure invoked when the
/// presentation of the scene is done (animation has finished). This