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

[정주] Pillyze - 식단 추가 버튼 이벤트, 검색 취소 버튼 이벤트 구현 #5

Merged
merged 6 commits into from
Jul 14, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
9B5AE8312C42B2E500BC1ED7 /* ViewModelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5AE8302C42B2E500BC1ED7 /* ViewModelable.swift */; };
9B5AE8332C42B49E00BC1ED7 /* MyHealthView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5AE8322C42B49E00BC1ED7 /* MyHealthView.swift */; };
9B5AE8352C42B54200BC1ED7 /* LayoutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5AE8342C42B54200BC1ED7 /* LayoutViewController.swift */; };
9B5AE8392C4397D800BC1ED7 /* AddDietView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5AE8382C4397D800BC1ED7 /* AddDietView.swift */; };
9B5AE83B2C4397DF00BC1ED7 /* AddDietViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5AE83A2C4397DF00BC1ED7 /* AddDietViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -48,6 +50,8 @@
9B5AE8302C42B2E500BC1ED7 /* ViewModelable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModelable.swift; sourceTree = "<group>"; };
9B5AE8322C42B49E00BC1ED7 /* MyHealthView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyHealthView.swift; sourceTree = "<group>"; };
9B5AE8342C42B54200BC1ED7 /* LayoutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutViewController.swift; sourceTree = "<group>"; };
9B5AE8382C4397D800BC1ED7 /* AddDietView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddDietView.swift; sourceTree = "<group>"; };
9B5AE83A2C4397DF00BC1ED7 /* AddDietViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddDietViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -94,6 +98,7 @@
9B046FF82C41735B00ADAFF3 /* ContentView.swift */,
9B0470232C427F5B00ADAFF3 /* TabBar */,
9B0470202C41752100ADAFF3 /* MyHealth */,
9B5AE8372C43978C00BC1ED7 /* AddDiet */,
9B0470282C4288C300ADAFF3 /* Extensions */,
9B0470212C41752800ADAFF3 /* Resource */,
9B046FFC2C41735C00ADAFF3 /* Preview Content */,
Expand Down Expand Up @@ -177,6 +182,15 @@
path = Base;
sourceTree = "<group>";
};
9B5AE8372C43978C00BC1ED7 /* AddDiet */ = {
isa = PBXGroup;
children = (
9B5AE8382C4397D800BC1ED7 /* AddDietView.swift */,
9B5AE83A2C4397DF00BC1ED7 /* AddDietViewController.swift */,
);
path = AddDiet;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -280,6 +294,8 @@
9B5AE8352C42B54200BC1ED7 /* LayoutViewController.swift in Sources */,
9B0470252C427F6C00ADAFF3 /* MainTabBar.swift in Sources */,
9B5AE8332C42B49E00BC1ED7 /* MyHealthView.swift in Sources */,
9B5AE8392C4397D800BC1ED7 /* AddDietView.swift in Sources */,
9B5AE83B2C4397DF00BC1ED7 /* AddDietViewController.swift in Sources */,
9B5AE8262C42AAD200BC1ED7 /* MyHealthViewController.swift in Sources */,
9B04702B2C4288DB00ADAFF3 /* View+cornerRadius.swift in Sources */,
9B046FF92C41735B00ADAFF3 /* ContentView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// AddDietView.swift
// BoostPillyze
//
// Created by 유정주 on 7/14/24.
//

import SwiftUI
import Combine

struct AddDietView: View {

let didTapCancelButton = PassthroughSubject<Void, Never>()

@State private var searchKeyword = ""

var body: some View {
SearchHeaderView(
didTapCancelButton: didTapCancelButton,
searchKeyword: $searchKeyword
)
.padding(.horizontal)

Spacer()
}
}

// MARK: - Search Header

private struct SearchHeaderView: View {

let didTapCancelButton: PassthroughSubject<Void, Never>

@Binding var searchKeyword: String

var body: some View {
HStack {
HStack(spacing: 0) {
Image(systemName: "magnifyingglass")
.padding(.leading, 16)
TextField("음식명으로 검색", text: $searchKeyword)
.padding(.vertical)
.padding(.horizontal, 4)
}
.background(Color.primaryPlaceholder)
.clipShape(Capsule())

Button(
action: {
didTapCancelButton.send()
},
label: {
Text("취소")
.font(.system(size: 15))
}
)
.foregroundStyle(.black)
}
}
}

// MARK: - Preview

#Preview {
AddDietView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// AddDietViewController.swift
// BoostPillyze
//
// Created by 유정주 on 7/14/24.
//

import UIKit
import SwiftUI
import Combine

final class AddDietViewController: LayoutViewController<AddDietView> {

// MARK: - Attribute

private var cancellables: Set<AnyCancellable> = []

// MARK: - Initializer

init() {
super.init(rootView: AddDietView())
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Setup

override func setUpBinding() {
contentView.didTapCancelButton
.receive(on: RunLoop.main)
.sink { [weak self] in
guard let self else { return }
dismiss(animated: true)
}
.store(in: &cancellables)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
//

import SwiftUI
import Combine

struct MyHealthView: View {

let didTapHealthScoreButton = PassthroughSubject<Void, Never>()

// MARK: - Body

var body: some View {
Expand All @@ -24,7 +27,7 @@ struct MyHealthView: View {
ContentBackground()

VStack(spacing: 0) {
HealthScoreView()
HealthScoreView(didTapHealthScoreButton: didTapHealthScoreButton)
.shadow(color: .primaryNormal.opacity(0.1), radius: 16)
.padding(20)

Expand Down Expand Up @@ -168,6 +171,8 @@ private struct ContentBackground: View {

private struct HealthScoreView: View {

let didTapHealthScoreButton: PassthroughSubject<Void, Never>

var body: some View {
HStack {
Spacer()
Expand All @@ -180,7 +185,9 @@ private struct HealthScoreView: View {
.foregroundStyle(.primaryNormal)
.padding(.vertical, 4)
Button(
action: {},
action: {
didTapHealthScoreButton.send()
},
label: {
HStack {
Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
import SwiftUI
import Combine

// MARK: - MyHealthRepresentView

Expand All @@ -21,4 +22,33 @@ struct MyHealthRepresentView: UIViewControllerRepresentable {

// MARK: - MyHealthViewController

final class MyHealthViewController: LayoutViewController<MyHealthView> {}
final class MyHealthViewController: LayoutViewController<MyHealthView> {

// MARK: - Attribute

private var cancellables: Set<AnyCancellable> = []

// MARK: - Setup

override func setUpBinding() {
contentView.didTapHealthScoreButton
.receive(on: RunLoop.main)
.sink { [weak self] in
guard let self else { return }
moveToAddDietViewController()
}
.store(in: &cancellables)
}
}

// MARK: - Move to AddDietViewController

private extension MyHealthViewController {

func moveToAddDietViewController() {
let addDietViewController = AddDietViewController()
addDietViewController.modalPresentationStyle = .fullScreen
present(addDietViewController, animated: true)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import SwiftUI

class LayoutViewController<Content: View>: UIHostingController<Content> {

var contentView: Content {
rootView
}

// MARK: - Life Cycle

override func viewDidLoad() {
Expand Down