@@ -13,49 +13,68 @@ struct MainTabBar: View {
13
13
@Environment ( \. colorScheme) private var colorScheme
14
14
@Binding var selectedIndex : MainTabEnum
15
15
16
- private var color : Color {
17
- switch colorScheme {
18
- case . dark:
19
- return . white
20
- default :
21
- return . black
22
- }
23
- }
24
-
25
16
var body : some View {
26
- HStack ( spacing: 0 ) {
27
- ForEach ( MainTabEnum . allCases, id: \. self) { tabType in
28
- tabBarButton ( for: tabType)
17
+ VStack ( spacing: 0 ) {
18
+ EdgeTriangles ( )
19
+ . fill ( Color . tabBarBackground)
20
+ . frame ( height: 30 )
21
+ HStack ( spacing: 0 ) {
22
+ ForEach ( Array ( MainTabEnum . allCases. enumerated ( ) ) , id: \. 1 ) { index, tabType in
23
+ let isSelected = selectedIndex == tabType
24
+ tabBarButton ( for: tabType, index: index, isSelected: isSelected)
25
+ }
29
26
}
27
+ . background (
28
+ Color . tabBarBackground
29
+ )
30
30
}
31
- . padding ( . vertical, 20 )
32
- . background (
33
- BlurView ( style: . systemChromeMaterialLight)
34
- . edgesIgnoringSafeArea ( . all)
31
+ }
32
+ }
33
+
34
+ struct EdgeTriangles : Shape {
35
+ func path( in rect: CGRect ) -> Path {
36
+ var path = Path ( )
37
+
38
+ let width = rect. width
39
+ let height = rect. height
40
+ let triangleSize : CGFloat = 50
41
+ let arcHeight : CGFloat = 1
42
+
43
+ path. move ( to: CGPoint ( x: 0 , y: height) )
44
+ path. addLine ( to: CGPoint ( x: 0 , y: height - triangleSize) )
45
+ path. addQuadCurve (
46
+ to: CGPoint ( x: triangleSize, y: height) ,
47
+ control: CGPoint ( x: triangleSize * 0.2 , y: height - arcHeight)
35
48
)
36
- . overlay ( alignment: . top) {
37
- Divider ( )
38
- }
49
+ path. closeSubpath ( )
50
+
51
+ path. move ( to: CGPoint ( x: width, y: height) )
52
+ path. addLine ( to: CGPoint ( x: width, y: height - triangleSize) )
53
+ path. addQuadCurve (
54
+ to: CGPoint ( x: width - triangleSize, y: height) ,
55
+ control: CGPoint ( x: width - triangleSize * 0.2 , y: height - arcHeight)
56
+ )
57
+ path. closeSubpath ( )
58
+
59
+ return path
39
60
}
40
61
}
41
62
42
63
extension MainTabBar {
43
64
@ViewBuilder
44
- private func tabBarButton( for tabType: MainTabEnum ) -> some View {
45
- let isSelected = selectedIndex == tabType
46
- let foregroundColor : Color = isSelected ? . red : color
47
- let scaleEffect : CGFloat = isSelected ? 1.4 : 1.0
48
-
65
+ private func tabBarButton( for tabType: MainTabEnum , index: Int , isSelected: Bool ) -> some View {
49
66
Button {
50
- withAnimation ( . spring ( response : 0.3 , dampingFraction : 0.5 , blendDuration : 0.5 ) ) {
67
+ withAnimation {
51
68
selectedIndex = tabType
52
69
}
53
70
} label: {
54
- Image ( systemName: tabType. imageName)
55
- . foregroundColor ( foregroundColor)
56
- . scaleEffect ( scaleEffect)
57
- . frame ( maxWidth: . infinity)
71
+ ColorButton (
72
+ image: Image ( systemName: tabType. imageName) ,
73
+ isSelected: isSelected,
74
+ animationType: tabType. animationType
75
+ )
58
76
}
77
+ . frame ( maxWidth: . infinity)
59
78
}
60
79
}
61
80
0 commit comments