diff --git a/Dietto/Dietto/Presentation/Common/ContainerView.swift b/Dietto/Dietto/Presentation/Common/ContainerView.swift index f6f44d3..291457c 100644 --- a/Dietto/Dietto/Presentation/Common/ContainerView.swift +++ b/Dietto/Dietto/Presentation/Common/ContainerView.swift @@ -9,10 +9,10 @@ import SwiftUI struct ContainerView: View { var paddingSize: CGFloat - var height: CGFloat + var height: CGFloat? = nil let content: () -> Content - init(paddingSize: CGFloat, height: CGFloat, @ViewBuilder content: @escaping () -> Content) { + init(paddingSize: CGFloat, height: CGFloat? = nil, @ViewBuilder content: @escaping () -> Content) { self.paddingSize = paddingSize self.height = height self.content = content @@ -22,7 +22,6 @@ struct ContainerView: View { GeometryReader { geometry in if geometry.size.width > paddingSize * 2 { let width = geometry.size.width - (paddingSize * 2) - ZStack { RoundedRectangle(cornerRadius: 21) .fill(Color.white) diff --git a/Dietto/Dietto/Presentation/Common/SubViews.swift b/Dietto/Dietto/Presentation/Common/SubViews.swift index ec46a78..13acfee 100644 --- a/Dietto/Dietto/Presentation/Common/SubViews.swift +++ b/Dietto/Dietto/Presentation/Common/SubViews.swift @@ -17,4 +17,13 @@ extension View { func toastView(toast: Binding) -> some View { self.modifier(ToastModifier(toast: toast)) } + //MARK: - 높이를 동적, 정적으로 모두 사용하기 위한 .iflet + func iflet(_ value: T?, apply: (Self, T) -> some View) -> some View{ + if let value = value{ + return AnyView(apply(self, value)) + }else{ + return AnyView(self) + } + } } + diff --git a/Dietto/Dietto/Presentation/Dietary/View/RecommendView.swift b/Dietto/Dietto/Presentation/Dietary/View/RecommendView.swift index 76940b6..e48a56b 100644 --- a/Dietto/Dietto/Presentation/Dietary/View/RecommendView.swift +++ b/Dietto/Dietto/Presentation/Dietary/View/RecommendView.swift @@ -14,78 +14,71 @@ struct RecommendView: View { // @StateObject private var viewModel = DietaryViewModel() //디버깅용 @State private var isFoldRecommand : Bool = false // true : 펼친상태로 시작 , false: 가려진 채로 시작. - @State private var contentHeight : CGFloat = 0 +// @State private var contentHeight : CGFloat = 0 var body: some View { ZStack { Color(.backGround).ignoresSafeArea(edges: .all) - ScrollView { - VStack {//컨테이너 뷰의 높이 - ContainerView(paddingSize: 16, - height: 1000) - { - HStack{ - VStack{ - Text("추천 레시피에 등록된 재료를 이용해 식사를 추천합니다.") - .font(.pretendardSemiBold10) - .foregroundStyle(.textFieldGray) - .border(.black) - - //MARK: - 안에 컨텐츠. - ScrollView { - LazyVStack(alignment: .leading, spacing: 16) { - ForEach(viewModel.recommendList, id : \.title) { item in - VStack(alignment: .leading, spacing: 8) { - Text(item.title) - .font(.pretendardBold24) - Text(item.description) - .font(.pretendardSemiBold16) - } - .border(.black) + VStack { + ContainerView(paddingSize: 16) { + HStack { + VStack { + Text("추천 레시피에 등록된 재료를 이용해 식사를 추천합니다.") + .font(.pretendardSemiBold10) + .foregroundStyle(.textFieldGray) + + ScrollView { + LazyVStack(alignment: .leading, spacing: 16) { + ForEach(viewModel.recommendList, id: \.title) { item in + VStack(alignment: .leading, spacing: 8) { + Text(item.title) + .font(.pretendardBold24) + Text(item.description) + .font(.pretendardSemiBold16) } + .padding() + .backgroundStyle(Color.textFieldGray) + .border(Color.appMain) + Divider() } - .background( - - ) - } - .frame(height: 800) - .clipped() - .padding(.top, 8) - .border(.black) - - Spacer() - - Button{ - withAnimation(.bouncy) { - isFoldRecommand.toggle() - } - }label: { - Image(systemName: isFoldRecommand ? "chevron.up" : "chevron.down") - .frame(width: 10, height: 10) - .font(.pretendardBold20) } - .padding(.bottom, 8) - .border(.black) - + .padding(.horizontal) } + .clipped() + +// Spacer() +// +// Button { +// withAnimation(.bouncy) { +// isFoldRecommand.toggle() +// } +// } label: { +// Image(systemName: isFoldRecommand ? "chevron.up" : "chevron.down") +// .frame(width: 10, height: 10) +// .font(.pretendardBold20) +// } +// .padding(.bottom, 8) +// .border(.black) } - .padding() } - .padding(.bottom, 10) + .padding() } + .padding(.bottom, 10) } .padding(.top, 16) + + } .navigationTitle("추천 식사") .navigationBarTitleDisplayMode(.inline) .font(.pretendardBold16) - .progressOverlay(isPresented: $viewModel.isPresneted,message: "Alan이 식단을 생성하고 있어요 !") //로딩 + .progressOverlay(isPresented: $viewModel.isPresneted, message: "Alan이 식단을 생성하고 있어요 !") .toastView(toast: $viewModel.toast) + } } - -//디버깅용 +////디버깅용 //#Preview { // NavigationStack{ // RecommendView() diff --git a/Dietto/Dietto/Presentation/Dietary/ViewModel/DietaryViewModel.swift b/Dietto/Dietto/Presentation/Dietary/ViewModel/DietaryViewModel.swift index d0e7ccb..6ea7804 100644 --- a/Dietto/Dietto/Presentation/Dietary/ViewModel/DietaryViewModel.swift +++ b/Dietto/Dietto/Presentation/Dietary/ViewModel/DietaryViewModel.swift @@ -33,8 +33,11 @@ class DietaryViewModel: ObservableObject { ] //추천 리스트 - @Published var recommendList : [RecommendEntity] = [] - + @Published var recommendList : [RecommendEntity] = [] +// RecommendEntity(title: "asd", description: "21124387923784235879235897"), +// RecommendEntity(title: "321123132132", description: "4539259340830459378345890"), +// RecommendEntity(title: "32112321131233132132", description: "453925934083041233123213213211231313259378345890"), +// RecommendEntity(title: "엔티티", description: "카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 카리나 ") private let usecase : AlanUsecase //MARK: - init