Skip to content

Commit

Permalink
feat: tabItem 파라미터 수정 (#13)
Browse files Browse the repository at this point in the history
feat: tab 기본 화면들 background color 추가(#13)
  • Loading branch information
hryeong66 committed Jun 17, 2024
1 parent d427765 commit 41636e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
37 changes: 22 additions & 15 deletions Projects/Core/DesignSystem/Sources/MainTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

enum Tab: String, CaseIterable, Identifiable {
enum MainTab: String, CaseIterable, Identifiable {
case recommend
case search
case mypage
Expand All @@ -25,6 +25,17 @@ enum Tab: String, CaseIterable, Identifiable {
}
}

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:
Expand All @@ -49,15 +60,15 @@ enum Tab: String, CaseIterable, Identifiable {
}

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

public init() {}

public var body: some View {
ZStack {
VStack {
TabView(selection: $selectedTab) {
ForEach(Tab.allCases) { tab in
ForEach(MainTab.allCases) { tab in
VStack {
tab.tabView
}
Expand All @@ -73,17 +84,15 @@ public struct MainTabView: View {


struct CustomTabBar: View {
@Binding var selectedTab: Tab
@Binding var selectedTab: MainTab

var body: some View {
VStack {
Spacer()
VStack {
HStack {
ForEach(Tab.allCases) { tab in
TabItemView(image: tab.image,
selectedImage: tab.image,
tabTitle: tab.title)
ForEach(MainTab.allCases) { tab in
TabItemView(tab: tab, isSelected: selectedTab == tab)
.onTapGesture {
selectedTab = tab
}
Expand All @@ -92,31 +101,29 @@ struct CustomTabBar: View {
Spacer(minLength: 20)
}
.frame(maxWidth: .infinity, maxHeight: 98)
.background(Color.gray.opacity(0.3))
.background(Color.white)
.cornerRadius(30, corners: [.topLeft, .topRight])
}
}
}

struct TabItemView: View {

let image: String
let selectedImage: String
let tabTitle: String
let tab: MainTab
let isSelected: Bool

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



#Preview {
MainTabView()
}
2 changes: 2 additions & 0 deletions Projects/Core/DesignSystem/Sources/MyPage/MyPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public struct MyPageView: View {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public struct RecommendView: View {
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.yellow)



}
}

Expand Down
2 changes: 2 additions & 0 deletions Projects/Core/DesignSystem/Sources/Search/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public struct SearchView: View {

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

Expand Down

0 comments on commit 41636e7

Please sign in to comment.