Skip to content

Commit

Permalink
Add example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dypme committed Apr 5, 2022
1 parent 6ed865f commit eed7db0
Show file tree
Hide file tree
Showing 28 changed files with 1,568 additions and 228 deletions.
37 changes: 35 additions & 2 deletions iOStarter/Constants/AppStoryboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import UIKit

// swiftlint:disable explicit_type_interface identifier_name line_length type_body_length type_name
internal enum StoryboardScene {
internal enum Auth: StoryboardType {
internal static let storyboardName = "Auth"

internal static let initialScene = InitialSceneType<iOStarter.LoginVC>(storyboard: Auth.self)
}
internal enum LaunchScreen: StoryboardType {
internal static let storyboardName = "LaunchScreen"

Expand All @@ -22,9 +27,37 @@ internal enum StoryboardScene {

internal static let initialScene = InitialSceneType<iOStarter.LaunchScreenVC>(storyboard: Main.self)

internal static let exampleVC = SceneType<iOStarter.ExampleVC>(storyboard: Main.self, identifier: "ExampleVC")

internal static let launchScreenVC = SceneType<iOStarter.LaunchScreenVC>(storyboard: Main.self, identifier: "LaunchScreenVC")

internal static let tabBarMenuVC = SceneType<iOStarter.TabBarMenuVC>(storyboard: Main.self, identifier: "TabBarMenuVC")
}
internal enum Menu: StoryboardType {
internal static let storyboardName = "Menu"

internal static let initialScene = InitialSceneType<iOStarter.ExampleVC>(storyboard: Menu.self)

internal static let exampleVC = SceneType<iOStarter.ExampleVC>(storyboard: Menu.self, identifier: "ExampleVC")

internal static let gridNavigation = SceneType<UIKit.UINavigationController>(storyboard: Menu.self, identifier: "GridNavigation")

internal static let gridVC = SceneType<iOStarter.GridVC>(storyboard: Menu.self, identifier: "GridVC")

internal static let homeNavigation = SceneType<UIKit.UINavigationController>(storyboard: Menu.self, identifier: "HomeNavigation")

internal static let tableNavigation = SceneType<UIKit.UINavigationController>(storyboard: Menu.self, identifier: "TableNavigation")

internal static let tableVC = SceneType<iOStarter.TableVC>(storyboard: Menu.self, identifier: "TableVC")
}
internal enum Profile: StoryboardType {
internal static let storyboardName = "Profile"

internal static let initialScene = InitialSceneType<UIKit.UINavigationController>(storyboard: Profile.self)

internal static let notLoginNavigation = SceneType<UIKit.UINavigationController>(storyboard: Profile.self, identifier: "NotLoginNavigation")

internal static let profileNavigation = SceneType<UIKit.UINavigationController>(storyboard: Profile.self, identifier: "ProfileNavigation")

internal static let profileVC = SceneType<iOStarter.ProfileVC>(storyboard: Profile.self, identifier: "ProfileVC")
}
}
// swiftlint:enable explicit_type_interface identifier_name line_length type_body_length type_name
Expand Down
23 changes: 23 additions & 0 deletions iOStarter/Example/Cell/ItemCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ItemCell.swift
// iOStarter
//
// Created by Macintosh on 05/04/22.
// Copyright © 2022 WahyuAdyP. All rights reserved.
//

import UIKit

class ItemCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var nameLbl: UILabel!
@IBOutlet weak var detailLbl: UILabel!

var viewModel: ItemVM! {
didSet {
imageView.kf.setImage(with: viewModel.imageUrl)
nameLbl.text = viewModel.name
detailLbl.text = viewModel.detail
}
}
}
18 changes: 10 additions & 8 deletions iOStarter/Example/Controller/ExampleVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import UIKit

class ExampleVC: ViewController {

@IBOutlet weak var button: UIButton!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var nameLbl: UILabel!
@IBOutlet weak var detailLbl: UILabel!

override func setupMethod() {
super.setupMethod()

button.addTarget(self, action: #selector(tapButton), for: .touchUpInside)
}
var viewModel: ItemVM!

@objc func tapButton() {
self.presentToast(message: "Hallo World")
override func setupView() {
super.setupView()

imageView.kf.setImage(with: viewModel.imageUrl)
nameLbl.text = viewModel.name
detailLbl.text = viewModel.detail
}

}
40 changes: 40 additions & 0 deletions iOStarter/Example/Controller/GridVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// GridVC.swift
// iOStarter
//
// Created by Macintosh on 05/04/22.
// Copyright © 2022 WahyuAdyP. All rights reserved.
//

import UIKit

class GridVC: CollectionViewController {
let viewModel = ListVM()

override func fetch(isLoadMore: Bool = false) {
viewModel.fetch(isLoadMore: isLoadMore) { [weak self] backgroundView, footerView in
self?.collectionView.backgroundView = backgroundView
} fetchDidFinish: { [weak self] isSuccess, message in
self?.collectionView.reloadData()
self?.refreshControl.endRefreshing()
}
}
}

extension GridVC {
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
viewModel.numberOfItems
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! ItemCell
cell.viewModel = viewModel.viewModelOfItem(at: indexPath)
return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vc = StoryboardScene.Menu.exampleVC.instantiate()
vc.viewModel = viewModel.viewModelOfItem(at: indexPath)
self.navigationController?.pushViewController(vc, animated: true)
}
}
27 changes: 27 additions & 0 deletions iOStarter/Example/Controller/LaunchScreenVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// LaunchScreenVC.swift
// iOStarter
//
// Created by Macintosh on 01/04/22.
// Copyright © 2022 WahyuAdyP. All rights reserved.
//

import UIKit

class LaunchScreenVC: ViewController {

override func viewDidLoad() {
super.viewDidLoad()

startLaunchScreen()
}

func startLaunchScreen() {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
guard let vc = AppDelegate.shared.mainController else { return }
vc.modalPresentationStyle = .fullScreen
vc.modalTransitionStyle = .crossDissolve
self.present(vc, animated: true, completion: nil)
}
}
}
43 changes: 43 additions & 0 deletions iOStarter/Example/Controller/LoginVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// LoginVC.swift
// iOStarter
//
// Created by Macintosh on 05/04/22.
// Copyright © 2022 dypme. All rights reserved.
//

import UIKit

class LoginVC: ViewController {

@IBOutlet weak var emailFld: UITextField!
@IBOutlet weak var passwordFld: UITextField!
@IBOutlet weak var loginBtn: UIButton!

let viewModel = LoginVM()

override func setupMethod() {
super.setupMethod()

loginBtn.addTarget(self, action: #selector(login), for: .touchUpInside)
}

@objc func login() {
let email = emailFld.text!
let password = passwordFld.text!

if let errorMessage = viewModel.errorMessage(email: email, password: password) {
self.simpleAlert(title: nil, message: errorMessage, handler: nil)
return
}
viewModel.login(email: email, password: password) { [weak self] isSuccess, message in
if isSuccess {
let tabBarVC = self?.presentingViewController as? TabBarMenuVC
tabBarVC?.setupMenu()
self?.dismiss(animated: true, completion: nil)
} else {
self?.simpleAlert(title: nil, message: message, handler: nil)
}
}
}
}
56 changes: 0 additions & 56 deletions iOStarter/Example/Controller/Menu/DrawerMenu.swift

This file was deleted.

88 changes: 0 additions & 88 deletions iOStarter/Example/Controller/Menu/DrawerMenu/DrawerMenuVC.swift

This file was deleted.

Loading

0 comments on commit eed7db0

Please sign in to comment.