Skip to content

Commit

Permalink
Merge pull request #115 from Team-B1ND/feature/dds
Browse files Browse the repository at this point in the history
Apply new MealView design
  • Loading branch information
hhhello0507 authored Aug 13, 2024
2 parents 265976f + ac06419 commit be7536e
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 175 deletions.
4 changes: 4 additions & 0 deletions Projects/App/iOS/Source/AppMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ struct AppMain: App {
FlowPresenter(flow: flow)
}
.ignoresSafeArea()
.onAppear {
let color = Dodam.color(DodamColor.Primary.normal)
UIRefreshControl.appearance().tintColor = UIColor(color)
}
}
}
}
26 changes: 26 additions & 0 deletions Projects/Domain/Source/Entity/MealType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// MealType.swift
// Domain
//
// Created by hhhello0507 on 8/12/24.
//

import Foundation
import SwiftBok

public enum MealType: Int, RawRepresentable {
case breakfast
case lunch
case dinner

public var label: String {
switch self {
case .breakfast:
"아침"
case .lunch:
"점심"
case .dinner:
"저녁"
}
}
}
4 changes: 4 additions & 0 deletions Projects/Domain/Source/Response/Meal/MealResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public struct MealResponse: ResponseProtocol {
public let breakfast: Meal?
public let lunch: Meal?
public let dinner: Meal?

public var meals: [Meal] {
[self.breakfast, self.lunch, self.dinner].compactMap { $0 }
}
}
51 changes: 51 additions & 0 deletions Projects/Feature/Source/Component/CalendarDateCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// CalendarCell.swift
// Feature
//
// Created by hhhello0507 on 8/12/24.
//

import SwiftUI
import DDS

struct CalendarDateCell: View {

private let date: Date?
private let selected: Bool

init(date: Date?, selected: Bool) {
self.date = date
self.selected = selected
}

private var label: String {
guard let date else {
return ""
}
guard let day = date[.day] else {
return ""
}
return "\(day)"
}

var body: some View {
Text(label)
.headline(.medium)
.foreground(
selected
? DodamColor.Static.white
: DodamColor.Label.alternative
)
.padding(.vertical, 8)
.if(selected) { view in
view.background {
Rectangle()
.dodamFill(DodamColor.Primary.normal)
.clipShape(.medium)
.frame(width: 36, height: 36)
}
}
.frame(maxWidth: .infinity)
.opacity(date == nil ? 0 : 1)
}
}
63 changes: 19 additions & 44 deletions Projects/Feature/Source/Home/Component/MealContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,47 @@
import SwiftUI
import DDS
import Domain
import Shared

struct MealContainer: View {

@State private var pageSize: CGSize?
private let mealData: MealResponse?
@Binding var mealIdx: Int

public init(
data mealData: MealResponse?,
mealIdx: Binding<Int>
) {
self.mealData = mealData
self._mealIdx = mealIdx
self.animatedIdx = mealIdx.wrappedValue
}

@State private var animatedIdx: Int
@State private var heights: [Int: CGFloat] = [:]


var body: some View {
if let data = mealData {
if data.exists {
let meals = [
data.breakfast,
data.lunch,
data.dinner
]
DodamPageView(selection: $mealIdx) {
ForEach(meals.indices, id: \.self) { idx in
GeometryReader { geometryProxy in
let text = meals[idx]?.details.map {
$0.name
}.joined(separator: ", ") ?? "급식이 없어요."
Text(text)
.body1(.medium)
.foreground(DodamColor.Label.normal)
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
.onAppear {
withAnimation(.spring) {
heights[idx] = text.boundingRect(
with: CGSize(
width: geometryProxy.size.width,
height: .greatestFiniteMagnitude
),
options: .usesLineFragmentOrigin,
attributes: [
.font: UIFont(
name: Pretendard.Weight.semibold.rawValue,
size: 18
)!
],
context: nil
).height
ForEach(data.meals, id: \.self) { meal in
let splitedArray = splitArray(array: meal.details)
HStack(alignment: .top) {
ForEach(splitedArray, id: \.self) { meals in
VStack(alignment: .leading, spacing: 0) {
ForEach(meals, id: \.self) { meal in
Text(meal.name)
.body1(.medium)
.foreground(DodamColor.Label.normal)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
.onReadSize { size in
self.pageSize = size
}
.padding(.horizontal, 6)
.page()
}
}
.frame(height: heights[animatedIdx] ?? 44.928)
.onChange(of: mealIdx) { newValue in
withAnimation(.spring(duration: 0.2)) {
animatedIdx = newValue
}
}
.frame(height: pageSize?.height ?? 999)
.onAppear {
let currentTime = Date()
let calendar = Calendar.current
Expand Down
40 changes: 40 additions & 0 deletions Projects/Feature/Source/Meal/Component/MealCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// MealCell.swift
// Feature
//
// Created by hhhello0507 on 8/12/24.
//

import SwiftUI
import DDS
import Domain

struct MealCell: View {

private let type: MealType
private let meal: Meal

init(type: MealType, meal: Meal) {
self.type = type
self.meal = meal
}

var body: some View {
VStack(spacing: 12) {
HStack {
DodamTag(type.label, type: .primary)
Spacer()
Text("\(Int(meal.calorie))Kcal")
.label(.medium)
.foreground(DodamColor.Label.alternative)
}
Text(meal.details.map { $0.name }.joined(separator: "\n"))
.body1(.medium)
.foreground(DodamColor.Label.normal)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(16)
.background(DodamColor.Background.normal)
.clipShape(.large)
}
}
Loading

0 comments on commit be7536e

Please sign in to comment.