Skip to content

Commit

Permalink
wip: Implement custom tabBar using Path
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteHyun committed Jul 12, 2024
1 parent 2807967 commit bc16db2
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 6.0;
};
name = Debug;
};
Expand Down Expand Up @@ -371,6 +372,7 @@
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 6.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down Expand Up @@ -400,7 +402,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.whitehyun.pillyze;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -430,7 +432,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.whitehyun.pillyze;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -448,7 +450,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.whitehyun.pillyzeTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/pillyze.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/pillyze";
};
Expand All @@ -467,7 +469,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.whitehyun.pillyzeTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/pillyze.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/pillyze";
};
Expand All @@ -484,7 +486,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.whitehyun.pillyzeUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = pillyze;
};
Expand All @@ -501,7 +503,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.whitehyun.pillyzeUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = pillyze;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFC",
"green" : "0xF7",
"red" : "0xF8"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFC",
"green" : "0xF7",
"red" : "0xF8"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ struct ContentView: View {
@State private var index: Int = 0
var body: some View {
VStack {

Spacer()
PillyzeTabBar(index: $index)
}
.background(Color.pillyzeBackground.ignoresSafeArea(edges: .top))
}
}


private enum Metrics {
static let tabBarHeight: CGFloat = 60
}

#Preview {
ContentView()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import SwiftUI

struct PillyzeTabBar: View {
@Binding var index: Int

var body: some View {
HStack(spacing: 30) {
Button {

} label: {
TabBarItem(title: "내 건강", image: Image(systemName: "heart.fill"))
}

Button {

} label: {
Image(systemName: "plus")
.resizable()
Expand All @@ -28,33 +28,86 @@ struct PillyzeTabBar: View {
.foregroundStyle(.white)
.background(.pillyzePrimary)
.clipShape(Circle())
.offset(y: -8)
.offset(y: -Metrics.centerButtonOffset)
}

Button {

} label: {
TabBarItem(title: "영양제", image: Image(systemName: "pill.fill"))
}
}
.frame(width: .infinity, height: 60)
.padding(.top, Metrics.centerButtonOffset)
.frame(height: Metrics.tabBarHeight)
.frame(maxWidth: .infinity)
.background(.background)
.clipShape(TabBarBackgroundShape())
}
}

struct TabBarItem: View {
private struct TabBarItem: View {
let title: String
let image: Image
var body: some View {
VStack(spacing: 8) {
VStack(spacing: Metrics.centerButtonOffset) {
image
Text(title)
}
.frame(width: 82)
}
}

struct TabBarBackgroundShape: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
path.move(to: .init(x: 0, y: rect.height))
path.addLine(to: .init(x: rect.width, y: rect.height))
path
.addLine(
to: .init(
x: rect.width,
y: Metrics.cornerRadius + Metrics.centerButtonOffset
)
)
path.addArc(
tangent1End: .init(x: rect.width, y: Metrics.centerButtonOffset),
tangent2End: .init(
x: rect.width - Metrics.cornerRadius,
y: Metrics.centerButtonOffset
),
radius: Metrics.cornerRadius
)
path
.addLine(
to: .init(x: Metrics.cornerRadius, y: Metrics.centerButtonOffset)
)
path.addArc(
tangent1End: .init(x: 0, y: Metrics.centerButtonOffset),
tangent2End: .init(
x: 0,
y: Metrics.cornerRadius + Metrics.centerButtonOffset
),
radius: Metrics.cornerRadius
)
}
}
}

private enum Metrics {
static let cornerRadius: CGFloat = 35
static let centerButtonOffset: CGFloat = 8
static let tabBarHeight: CGFloat = 60
}

#Preview {
PillyzeTabBar(index: .constant(0))
}

#Preview("TabBarBackgroundShape") {
VStack {
Spacer()
TabBarBackgroundShape()
.frame(width: .infinity, height: Metrics.tabBarHeight)
.background(.yellow)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import XCTest

final class pillyzeUITestsLaunchTests: XCTestCase {

override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}

override func setUpWithError() throws {
continueAfterFailure = false
}
Expand Down

0 comments on commit bc16db2

Please sign in to comment.