Skip to content

Commit

Permalink
feat: main tab 구현 (#16)
Browse files Browse the repository at this point in the history
* feat: 기본 탭 추가 (#13)

* feat: tabItem 파라미터 수정 (#13)

feat: tab 기본 화면들 background color 추가(#13)

* feat: mainTab과 view 파일 분리 (#13)

* feat: 코드리뷰 반영 - 부분 cornerRadius 함수 clipShape로 변경

* feat: feature 프로젝트 생성 후 파일 이동 (#13)

* etc: dummy 파일 삭제 (#13)

* feat: 코드리뷰 반영 - color값 사용 방식 변경 및 indent 수정(#13)

* etc: 잘못 들어간 모듈 삭제 (#13)

* feat: TabBarView 컴포넌트 stack 정리
  • Loading branch information
hryeong66 authored Jun 27, 2024
1 parent 21e8350 commit adaf7e3
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Projects/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ let project = Project.configure(
resources: "Resources/**",
dependencies: [
.Feature.Home,
.Feature.Recommend,
.Feature.Search,
.Feature.MyPage,
.ResourceKit,
.Core.DesignSystem,
.Core.PPACNetwork,
Expand All @@ -47,6 +50,9 @@ let project = Project.configure(
resources: "Resources/**",
dependencies: [
.Feature.Home,
.Feature.Recommend,
.Feature.Search,
.Feature.MyPage,
.ResourceKit,
.Core.DesignSystem,
.Core.PPACNetwork,
Expand Down
9 changes: 5 additions & 4 deletions Projects/App/Sources/FarmemeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
//

import SwiftUI
import Home

@main
struct FarmemeApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
var body: some Scene {
WindowGroup {
MainTabView()
}
}
}
2 changes: 1 addition & 1 deletion Projects/Core/PPACNetwork/Sources/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final public class NetworkService: NetworkServiceable {
let (data, response): (Data, URLResponse)

do {
(data, response) = try? await URLSession.shared.data(for: urlRequest)
(data, response) = try await URLSession.shared.data(for: urlRequest)
} catch {
NetworkLogger.logError(.invalidResponse)
return .failure(.invalidResponse)
Expand Down
1 change: 0 additions & 1 deletion Projects/Features/Home/Sources/Dummy.swift

This file was deleted.

53 changes: 53 additions & 0 deletions Projects/Features/Home/Sources/View/MainTab/MainTab.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// MainTab.swift
// DesignSystem
//
// Created by 장혜령 on 6/17/24.
//

import SwiftUI
import Recommend
import Search
import MyPage

enum MainTab: String, CaseIterable, Identifiable {
case recommend
case search
case mypage

var id: String { rawValue }

var image: String {
switch self {
case .recommend:
return "1.square.fill"
case .search:
return "2.square.fill"
case .mypage:
return "3.square.fill"
}
}

var selectedImage: String {
switch self {
case .recommend:
return "1.square"
case .search:
return "2.square"
case .mypage:
return "3.square"
}
}

var title: String {
switch self {
case .recommend:
return "추천"
case .search:
return "검색"
case .mypage:
return "마이"
}
}

}
83 changes: 83 additions & 0 deletions Projects/Features/Home/Sources/View/MainTab/MainTabView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// MainTabView.swift
// DesignSystem
//
// Created by 장혜령 on 6/16/24.
//

import SwiftUI
import Recommend
import Search
import MyPage

public struct MainTabView: View {
@State private var selectedTab: MainTab = .recommend

public init() {}

public var body: some View {
ZStack {
TabView(selection: $selectedTab) {
RecommendView()
.tag(MainTab.recommend)
SearchView()
.tag(MainTab.search)
MyPageView()
.tag(MainTab.mypage)
}
VStack {
Spacer()
CustomTabBarView(selectedTab: $selectedTab)
}
}
.edgesIgnoringSafeArea(.bottom)
}
}

struct CustomTabBarView: View {
@Binding var selectedTab: MainTab

var body: some View {
VStack {
HStack {
ForEach(MainTab.allCases) { tab in
TabItemView(tab: tab, isSelected: selectedTab == tab)
.onTapGesture {
selectedTab = tab
}
}
}
Spacer(minLength: 20)
}
.frame(maxWidth: .infinity, maxHeight: 98)
.background(.white)
.clipShape(
.rect(
topLeadingRadius: 30,
topTrailingRadius: 30
)
)
}
}


struct TabItemView: View {

let tab: MainTab
let isSelected: Bool

var body: some View {
VStack {
Image(systemName: isSelected ? tab.selectedImage : tab.image)
.frame(width: 20, height: 20)
Text(tab.title)
.font(.system(size: 11))
}
.padding(40)
}
}


#Preview {
MainTabView()
}
26 changes: 26 additions & 0 deletions Projects/Features/MyPage/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Project.swift
// MyPage
//
// Created by hyeryeong on 6/18/24
//

import ProjectDescription
import ProjectDescriptionHelpers

let project = Project(
name: "MyPage",
targets: [
.configure(
name: "MyPage",
product: .framework,
infoPlist: .default,
sources: "Sources/**",
resources: "Resources/**",
dependencies: [

]
)
]
)

1 change: 1 addition & 0 deletions Projects/Features/MyPage/Resources/dummy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
더미임미다
22 changes: 22 additions & 0 deletions Projects/Features/MyPage/Sources/View/MyPageView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// MyPageView.swift
// DesignSystem
//
// Created by 장혜령 on 6/16/24.
//

import SwiftUI

public struct MyPageView: View {
public init() { }

public var body: some View {
Text("마이페이지 화면")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.blue)
}
}

#Preview {
MyPageView()
}
26 changes: 26 additions & 0 deletions Projects/Features/Recommend/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Project.swift
// Recommend
//
// Created by hyeryeong on 6/18/24
//

import ProjectDescription
import ProjectDescriptionHelpers

let project = Project(
name: "Recommend",
targets: [
.configure(
name: "Recommend",
product: .framework,
infoPlist: .default,
sources: "Sources/**",
resources: "Resources/**",
dependencies: [

]
)
]
)

1 change: 1 addition & 0 deletions Projects/Features/Recommend/Resources/dummy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
더미임미다
24 changes: 24 additions & 0 deletions Projects/Features/Recommend/Sources/View/RecommendView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// RecommendView.swift
// Home
//
// Created by 장혜령 on 6/16/24.
//

import SwiftUI

public struct RecommendView: View {
public init() { }

public var body: some View {
VStack {
Text("추천 화면")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.yellow)
}
}

#Preview {
RecommendView()
}
26 changes: 26 additions & 0 deletions Projects/Features/Search/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Project.swift
// Search
//
// Created by hyeryeong on 6/18/24
//

import ProjectDescription
import ProjectDescriptionHelpers

let project = Project(
name: "Search",
targets: [
.configure(
name: "Search",
product: .framework,
infoPlist: .default,
sources: "Sources/**",
resources: "Resources/**",
dependencies: [

]
)
]
)

1 change: 1 addition & 0 deletions Projects/Features/Search/Resources/dummy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
더미임미다
22 changes: 22 additions & 0 deletions Projects/Features/Search/Sources/View/SearchView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// SearchView.swift
// DesignSystem
//
// Created by 장혜령 on 6/16/24.
//

import SwiftUI

public struct SearchView: View {
public init() { }

public var body: some View {
Text("검색 화면")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.pink)
}
}

#Preview {
SearchView()
}
3 changes: 3 additions & 0 deletions Tuist/ProjectDescriptionHelpers/TargetDependency+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ extension TargetDependency {

public struct Feature {
public static let Home = project(moduleName: "Home")
public static let Recommend = project(moduleName: "Recommend")
public static let Search = project(moduleName: "Search")
public static let MyPage = project(moduleName: "MyPage")
}

public struct Core {
Expand Down

0 comments on commit adaf7e3

Please sign in to comment.