Skip to content

Commit 474164a

Browse files
committed
FIX: TupleView Issue
1 parent c7376eb commit 474164a

File tree

3 files changed

+31
-40
lines changed

3 files changed

+31
-40
lines changed

Sources/OpenTDS/Component/TabView/TabView+Ext.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,9 @@ import SwiftUI
22

33
@available(macOS 11, iOS 14, *)
44
public extension View {
5-
@ViewBuilder func tossTransition(_ id: Int, _ selected: Int) -> some View {
6-
self
7-
.offset(x: { () -> CGFloat in
8-
if id == selected {
9-
return 0
10-
} else if id < selected {
11-
return -10
12-
} else {
13-
return 10
14-
}
15-
}())
16-
.opacity(id == selected ? 1 : 0)
17-
}
18-
195
@ViewBuilder func tossTabItem(_ title: String, _ image: Image) -> TossTabItemView<Self> {
206
TossTabItemView(title: title, image: image) {
217
self
228
}
239
}
2410
}
25-
26-
@available(macOS 11, iOS 14, *)
27-
public struct TossTransition: ViewModifier {
28-
let offset: CGFloat
29-
let opacity: CGFloat
30-
31-
public func body(content: Content) -> some View {
32-
content
33-
.offset(x: offset)
34-
.opacity(opacity)
35-
.clipped()
36-
}
37-
}

Sources/OpenTDS/Component/TabView/TabView+Item.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ public struct TossTabItemView<Content: View>: TossTabItemViewProtocol {
55

66
public let title: String
77
public let image: Image
8-
let content: Content
8+
public let content: AnyView
99

1010
public init(title: String,
1111
image: Image,
1212
@ViewBuilder content: () -> Content)
1313
{
1414
self.title = title
1515
self.image = image
16-
self.content = content()
16+
self.content = AnyView(content())
1717
}
1818

19-
public var body: some View {
20-
content
21-
}
19+
public var body: some View { EmptyView() }
2220
}
2321

2422
@available(macOS 11, iOS 14, *)
@@ -35,4 +33,5 @@ public struct TossTabItemModifier: ViewModifier {
3533
public protocol TossTabItemViewProtocol: View {
3634
var title: String { get }
3735
var image: Image { get }
36+
var content: AnyView { get }
3837
}

Sources/OpenTDS/Component/TabView/TabView.swift

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,40 @@ import SwiftUI
1414
}
1515
*/
1616
@available(macOS 11, iOS 14, *)
17-
public struct TossTabView<Content: TossTabItemViewProtocol>: View {
17+
public struct TossTabView: View {
1818

1919
@State var selected: Int = 0
20-
let content: [Content]
20+
let content: [any TossTabItemViewProtocol]
2121

22-
public init(@ViewBuilder content: @escaping () -> TupleView<(Content, Content)>)
22+
public init<C0: TossTabItemViewProtocol,
23+
C1: TossTabItemViewProtocol>(@ViewBuilder content: @escaping () -> TupleView<(C0, C1)>)
2324
{
2425
let cv = content().value
2526
self.content = [cv.0, cv.1]
2627
}
2728

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)>)
2932
{
3033
let cv = content().value
3134
self.content = [cv.0, cv.1, cv.2]
3235
}
3336

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)>)
3541
{
3642
let cv = content().value
3743
self.content = [cv.0, cv.1, cv.2, cv.3]
3844
}
3945

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)>)
4151
{
4252
let cv = content().value
4353
self.content = [cv.0, cv.1, cv.2, cv.3, cv.4]
@@ -48,8 +58,17 @@ public struct TossTabView<Content: TossTabItemViewProtocol>: View {
4858
ZStack(alignment: .bottom) {
4959
ZStack {
5060
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)
5372
}
5473

5574
}

0 commit comments

Comments
 (0)