@@ -14,30 +14,40 @@ import SwiftUI
14
14
}
15
15
*/
16
16
@available ( macOS 11 , iOS 14 , * )
17
- public struct TossTabView < Content : TossTabItemViewProtocol > : View {
17
+ public struct TossTabView : View {
18
18
19
19
@State var selected : Int = 0
20
- let content : [ Content ]
20
+ let content : [ any TossTabItemViewProtocol ]
21
21
22
- public init ( @ViewBuilder content: @escaping ( ) -> TupleView < ( Content , Content ) > )
22
+ public init < C0: TossTabItemViewProtocol ,
23
+ C1: TossTabItemViewProtocol > ( @ViewBuilder content: @escaping ( ) -> TupleView < ( C0 , C1 ) > )
23
24
{
24
25
let cv = content ( ) . value
25
26
self . content = [ cv. 0 , cv. 1 ]
26
27
}
27
28
28
- public init ( @ViewBuilder content: @escaping ( ) -> TupleView < ( Content , Content , Content ) > )
29
+ public init < C0: TossTabItemViewProtocol ,
30
+ C1: TossTabItemViewProtocol ,
31
+ C2: TossTabItemViewProtocol > ( @ViewBuilder content: @escaping ( ) -> TupleView < ( C0 , C1 , C2 ) > )
29
32
{
30
33
let cv = content ( ) . value
31
34
self . content = [ cv. 0 , cv. 1 , cv. 2 ]
32
35
}
33
36
34
- public init ( @ViewBuilder content: @escaping ( ) -> TupleView < ( Content , Content , Content , Content ) > )
37
+ public init < C0: TossTabItemViewProtocol ,
38
+ C1: TossTabItemViewProtocol ,
39
+ C2: TossTabItemViewProtocol ,
40
+ C3: TossTabItemViewProtocol > ( @ViewBuilder content: @escaping ( ) -> TupleView < ( C0 , C1 , C2 , C3 ) > )
35
41
{
36
42
let cv = content ( ) . value
37
43
self . content = [ cv. 0 , cv. 1 , cv. 2 , cv. 3 ]
38
44
}
39
45
40
- public init ( @ViewBuilder content: @escaping ( ) -> TupleView < ( Content , Content , Content , Content , Content ) > )
46
+ public init < C0: TossTabItemViewProtocol ,
47
+ C1: TossTabItemViewProtocol ,
48
+ C2: TossTabItemViewProtocol ,
49
+ C3: TossTabItemViewProtocol ,
50
+ C4: TossTabItemViewProtocol > ( @ViewBuilder content: @escaping ( ) -> TupleView < ( C0 , C1 , C2 , C3 , C4 ) > )
41
51
{
42
52
let cv = content ( ) . value
43
53
self . content = [ cv. 0 , cv. 1 , cv. 2 , cv. 3 , cv. 4 ]
@@ -48,8 +58,17 @@ public struct TossTabView<Content: TossTabItemViewProtocol>: View {
48
58
ZStack ( alignment: . bottom) {
49
59
ZStack {
50
60
ForEach ( 0 ..< content. count, id: \. self) { idx in
51
- content [ idx]
52
- . tossTransition ( idx, selected)
61
+ content [ idx] . content
62
+ . offset ( x: { ( ) -> CGFloat in
63
+ if idx == selected {
64
+ return 0
65
+ } else if idx < selected {
66
+ return - 10
67
+ } else {
68
+ return 10
69
+ }
70
+ } ( ) )
71
+ . opacity ( idx == selected ? 1 : 0 )
53
72
}
54
73
55
74
}
0 commit comments