Skip to content

Commit

Permalink
MMButton, SnackBar Components 구현 (#3)
Browse files Browse the repository at this point in the history
* feat: MMSnackBar 구현 (without Font, Image)

* merge: 사파리 Resources 작업 가져오기

commit 04c74ca
Author: Safari <[email protected]>
Date:   Mon Apr 8 10:21:15 2024 +0900

    fix: Bundle 통해 리소스 데이터 가져오도록 수정

commit 8d51203
Author: Safari <[email protected]>
Date:   Mon Apr 8 10:20:32 2024 +0900

    chore: 오타 수정

commit 348a4e0
Author: Safari <[email protected]>
Date:   Mon Apr 8 10:20:02 2024 +0900

    chore: plist SceneDelegate 설정

* feat: MMSnackBar에 Font, Image 추가

* feat: Color Components 구현

* feat: Fonts 미리보기 구현

* feat: MM버튼 개선 및 MMButton 디자인시스템 구현

* Create pull_request_template.md
  • Loading branch information
FirstDo authored Apr 8, 2024
1 parent 022b948 commit 0285e22
Show file tree
Hide file tree
Showing 17 changed files with 642 additions and 78 deletions.
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 작업 내용

- [ ] TODO
- [ ] TODO
- [ ] TODO

## 리뷰어에게 (필요시)

- ~참고 해주세요

## 스크린샷 (필요시)
26 changes: 16 additions & 10 deletions Projects/Shared/DesignSystem/Demo/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {}

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
return true
}

// MARK: UISceneSession Lifecycle
func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
}
65 changes: 65 additions & 0 deletions Projects/Shared/DesignSystem/Demo/Sources/ButtonVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import UIKit

import DesignSystem

final class ButtonVC: UIViewController {

private let button1 = MMButton(title: "dudu", type: .primary)
private let button2 = MMButton(title: "dudu", type: .primary)
private let button3 = MMButton(title: "dudu", type: .primary)
private let segmentedControl: UISegmentedControl = {
let v = UISegmentedControl(items: ["primary", "secondary", "disable", "negative"])
v.selectedSegmentIndex = 0
return v
}()

private let rootContainer = UIView()

override func viewDidLoad() {
super.viewDidLoad()

setupView()
setupConstraints()
}

private func setupView() {
view.backgroundColor = .systemBackground
title = "MMButton"

let buttons = [button1, button2, button3]

segmentedControl.setAction(UIAction(title: "Primary") { _ in
buttons.forEach { $0.setState(.primary) }
}, forSegmentAt: 0)

segmentedControl.setAction(UIAction(title: "Secondary") { _ in
buttons.forEach { $0.setState(.secondary) }
}, forSegmentAt: 1)

segmentedControl.setAction(UIAction(title: "Disable") { _ in
buttons.forEach { $0.setState(.disable) }
}, forSegmentAt: 2)

segmentedControl.setAction(UIAction(title: "Negative") { _ in
buttons.forEach { $0.setState(.negative) }
}, forSegmentAt: 3)
}

private func setupConstraints() {
view.addSubview(rootContainer)

rootContainer.flex.justifyContent(.center).padding(20).define { flex in
flex.addItem(button1).height(56).marginBottom(20)
flex.addItem(button2).height(44).marginBottom(20)
flex.addItem(button3).height(40).marginBottom(20)
flex.addItem(segmentedControl).height(50)
}
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

rootContainer.pin.all()
rootContainer.flex.layout()
}
}
72 changes: 72 additions & 0 deletions Projects/Shared/DesignSystem/Demo/Sources/ColorVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import UIKit

import DesignSystem

final class ColorVC: UITableViewController {

private var items = [
["White": [Colors.White._1]],
["Black": [Colors.Black._1]],
["Gray": [Colors.Gray._1, Colors.Gray._2, Colors.Gray._3, Colors.Gray._4, Colors.Gray._5, Colors.Gray._6, Colors.Gray._7, Colors.Gray._8, Colors.Gray._9, Colors.Gray._10]],
["Blue": [Colors.Blue._1, Colors.Blue._2, Colors.Blue._3, Colors.Blue._4]],
["SkyBlue": [Colors.SkyBlue._1]],
["Mint": [Colors.Mint._1, Colors.Mint._2, Colors.Mint._3]],
["Yellow": [Colors.Yellow._1]],
["Red": [Colors.Red._1, Colors.Red._2, Colors.Red._3]],
]

override func viewDidLoad() {
super.viewDidLoad()

setupView()
}

private func setupView() {
tableView.register(UITableViewCell.self, forCellReuseIdentifier: String(describing: UITableViewCell.self))
title = "Colors"
}
}

extension ColorVC {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items[section].values.first!.count
}

override func numberOfSections(in tableView: UITableView) -> Int {
return items.count
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return items[section].keys.first
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UITableViewCell.self), for: indexPath)

let colorName = items[indexPath.section].keys.first!
let color = items[indexPath.section].values.first![indexPath.row]

cell.textLabel?.text = " \(colorName)_\(indexPath.row + 1)"
cell.textLabel?.font = .systemFont(ofSize: 20)

let image = UIGraphicsImageRenderer(size: .init(width: 40, height: 40)).image { rendererContext in
color.setFill()
rendererContext.fill(CGRect(origin: .zero, size: .init(width: 40, height: 40)))
}

cell.imageView?.image = image
cell.imageView?.layer.cornerRadius = 20
cell.imageView?.layer.borderColor = UIColor.black.cgColor
cell.imageView?.layer.borderWidth = 1
cell.imageView?.clipsToBounds = true
return cell
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60
}

override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
return nil
}
}
64 changes: 64 additions & 0 deletions Projects/Shared/DesignSystem/Demo/Sources/DesignSystemVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import UIKit

final class DesignSystemVC: UITableViewController {

enum Screen: Int, CaseIterable {
case color
case font
case button
case snackbar

var title: String {
switch self {
case .color: return "Colors"
case .font: return "Fonts"
case .button: return "Buttons"
case .snackbar: return "SnackBar"
}
}

func move(with navigationController: UINavigationController?) {
let vc: UIViewController
switch self {
case .color: vc = ColorVC(style: .insetGrouped)
case .font: vc = FontVC(style: .insetGrouped)
case .button: vc = ButtonVC()
case .snackbar: vc = SnackBarVC()
}

navigationController?.pushViewController(vc, animated: true)
}
}

override func viewDidLoad() {
super.viewDidLoad()

setupView()
}

private func setupView() {
tableView.register(UITableViewCell.self, forCellReuseIdentifier: String(describing: UITableViewCell.self))
title = "Components"
navigationController?.navigationBar.prefersLargeTitles = true
}
}

extension DesignSystemVC {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Screen.allCases.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UITableViewCell.self), for: indexPath)
cell.accessoryType = .disclosureIndicator
cell.textLabel?.text = Screen(rawValue: indexPath.row)?.title
cell.textLabel?.font = .systemFont(ofSize: 20)
return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

Screen(rawValue: indexPath.row)?.move(with: navigationController)
}
}

This file was deleted.

57 changes: 57 additions & 0 deletions Projects/Shared/DesignSystem/Demo/Sources/FontVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import UIKit
import DesignSystem

final class FontVC: UITableViewController {

private let items: [UIFont] = [
Fonts.heading._1,
Fonts.heading._2,
Fonts.heading._3,
Fonts.heading._4,
Fonts.heading._5,
Fonts.body._1,
Fonts.body._2,
Fonts.body._3,
Fonts.body._4,
Fonts.body._5,
]

override func viewDidLoad() {
super.viewDidLoad()

setupView()
}

private func setupView() {
tableView.register(UITableViewCell.self, forCellReuseIdentifier: String(describing: UITableViewCell.self))
title = "Fonts"
}
}

extension FontVC {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count / 2
}

override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return section == 0 ? "Heading" : "Body"
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UITableViewCell.self), for: indexPath)

let style = indexPath.section == 0 ? "heading" : "body"

cell.textLabel?.text = "\(style)_\(indexPath.row+1)"
cell.textLabel?.font = items[indexPath.section * 5 + indexPath.row]
return cell
}

override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
return nil
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import UIKit

import DesignSystem

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = DesignSystemViewController()
window?.rootViewController = UINavigationController(rootViewController: DesignSystemVC(style: .insetGrouped))
window?.makeKeyAndVisible()

Fonts.registerFont()
}

func sceneDidDisconnect(_ scene: UIScene) {}
Expand Down
Loading

0 comments on commit 0285e22

Please sign in to comment.