Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

텍스트 필드 재사용 가능하게 함 #22

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 110 additions & 90 deletions gigi.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion gigi/Resources/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
// MARK: - Asset Catalogs

// swiftlint:disable identifier_name line_length nesting type_body_length type_name
internal enum Asset {}
internal enum Asset {
internal static let separator = ColorAsset(name: "separator")
}

// swiftlint:enable identifier_name line_length nesting type_body_length type_name

Expand Down
20 changes: 20 additions & 0 deletions gigi/Resources/Assets.xcassets/separator.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "155",
"alpha" : "1.000",
"blue" : "155",
"green" : "155"
}
}
}
]
}
2 changes: 0 additions & 2 deletions gigi/Resources/Storyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ internal enum StoryboardScene {

internal enum LaunchScreen: StoryboardType {
internal static let storyboardName = "LaunchScreen"

internal static let initialScene = InitialSceneType<UIKit.UIViewController>(storyboard: LaunchScreen.self)
}

internal enum Map: StoryboardType {
Expand Down
8 changes: 8 additions & 0 deletions gigi/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = .init()

UINavigationBar.appearance().do {
$0.setBackgroundImage(.init(), for: .default)
$0.shadowImage = .init()
$0.isTranslucent = true
}

let rootViewController = StoryboardScene.Visitor.initialScene.instantiate().then {
($0.topViewController as? VisitorMainViewController)?.viewModel = VisitorMainViewModel()
}
window?.rootViewController = rootViewController
window?.makeKeyAndVisible()
return true
}
}
Expand Down
38 changes: 38 additions & 0 deletions gigi/Sources/Extension/UIAlertController+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// UIAlertController+.swift
// gigi
//
// Created by Presto on 2019/12/02.
// Copyright © 2019 Ieungieung. All rights reserved.
//

import UIKit

import RxSwift

extension UIAlertController {
static func alert(title: String?,
message: String?,
style: UIAlertController.Style = .alert) -> UIAlertController {
return .init(title: title, message: message, preferredStyle: style)
}

func action(title: String?,
style: UIAlertAction.Style = .default,
completion: ((UIAlertAction) -> Void)? = nil) -> UIAlertController {
let action = UIAlertAction(title: title, style: style, handler: completion)
addAction(action)
return self
}

func textField(configuration: ((UITextField) -> Void)? = nil) -> UIAlertController {
addTextField(configurationHandler: configuration)
return self
}

func present(to viewController: UIViewController?,
animated: Bool = true,
completion: (() -> Void)? = nil) {
viewController?.present(self, animated: animated, completion: completion)
}
}
26 changes: 26 additions & 0 deletions gigi/Sources/Extension/UIColor+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// UIColor+.swift
// gigi
//
// Created by Presto on 2019/11/28.
// Copyright © 2019 Ieungieung. All rights reserved.
//

import UIKit

extension UIColor {
convenience init(red: CGFloat, green: CGFloat, blue: CGFloat) {
self.init(red: red / 255, green: green / 255, blue: blue / 255, alpha: 1)
}

convenience init(rgb: CGFloat) {
self.init(red: rgb, green: rgb, blue: rgb)
}

convenience init(red: Int, green: Int, blue: Int) {
self.init(red: CGFloat(red) / 255,
green: CGFloat(green) / 255,
blue: CGFloat(blue) / 255,
alpha: 1)
}
}
15 changes: 15 additions & 0 deletions gigi/Sources/Extension/UIView+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// UIView+.swift
// gigi
//
// Created by Presto on 2019/11/28.
// Copyright © 2019 Ieungieung. All rights reserved.
//

import UIKit

extension UIView {
func addSubviews(_ subviews: UIView...) {
subviews.forEach { addSubview($0) }
}
}
93 changes: 93 additions & 0 deletions gigi/Sources/View/GigiTextField.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// GigiTextField.swift
// gigi
//
// Created by Presto on 2019/11/28.
// Copyright © 2019 Ieungieung. All rights reserved.
//

import UIKit

import RxCocoa
import RxSwift
import SnapKit

@IBDesignable
final class GigiTextField: UIView {
fileprivate let textField = UITextField()
private let separatorView = UIView()

@IBInspectable var placeholder: String? {
get {
return textField.placeholder
}
set {
textField.placeholder = newValue
}
}

override init(frame: CGRect) {
super.init(frame: frame)
setup()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
setup()
}

convenience init(placeholder: String?) {
self.init(frame: .zero)
self.placeholder = placeholder
}

@discardableResult
override func resignFirstResponder() -> Bool {
textField.resignFirstResponder()
return super.resignFirstResponder()
}
}

// MARK: - Private Method

private extension GigiTextField {
func setup() {
setupProperties()
setupLayouts()
}

func setupProperties() {
textField.font = .systemFont(ofSize: 22)
separatorView.backgroundColor = Asset.separator.color
}

func setupLayouts() {
addSubviews(textField, separatorView)

textField.snp.makeConstraints {
$0.top.equalToSuperview()
$0.leading.equalToSuperview()
$0.trailing.equalToSuperview()
}

separatorView.snp.makeConstraints {
$0.top.equalTo(textField.snp.bottom)
$0.leading.equalToSuperview()
$0.trailing.equalToSuperview()
$0.bottom.equalToSuperview()
$0.height.equalTo(2)
}
}
}

// MARK: - Reactive Extension

extension Reactive where Base: GigiTextField {
var text: ControlProperty<String?> {
return base.textField.rx.text
}

var editingDidEndOnExit: ControlEvent<Void> {
return base.textField.rx.controlEvent(.editingDidEndOnExit)
}
}
7 changes: 5 additions & 2 deletions gigi/Sources/ViewController/Base/GigiViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ class GigiViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setup()
bind()
bindViewModelInputs()
bindViewModelOutputs()
}

func setup() {}

func bind() {}
func bindViewModelInputs() {}

func bindViewModelOutputs() {}
}
Loading