Skip to content

Commit 1d28b58

Browse files
committed
UPDATE: TabView Logic
1 parent 10b54e6 commit 1d28b58

File tree

4 files changed

+23
-63
lines changed

4 files changed

+23
-63
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import SwiftUI
2+
3+
@available(macOS 11, iOS 14, *)
4+
public struct TossScrollItem {
5+
public var image: Image
6+
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import SwiftUI
22

3+
@resultBuilder
4+
struct TossTabViewBuilder {
5+
static func buildBlock(_ components: TossTabItem...) -> [TossTabItem] {
6+
components
7+
}
8+
}
9+
310
@available(macOS 11, iOS 14, *)
411
public extension View {
5-
@ViewBuilder func tossTabItem(_ title: String, _ image: Image) -> TossTabItemView<Self> {
6-
TossTabItemView(title: title, image: image) {
7-
self
8-
}
12+
func tossTabItem(_ title: String, _ image: Image) -> TossTabItem {
13+
TossTabItem(title: title, image: image, content: AnyView(self))
914
}
1015
}
Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
import SwiftUI
22

33
@available(macOS 11, iOS 14, *)
4-
public struct TossTabItemView<Content: View>: TossTabItemViewProtocol {
4+
public struct TossTabItem {
55

66
public let title: String
77
public let image: Image
88
public let content: AnyView
99

1010
public init(title: String,
11-
image: Image,
12-
@ViewBuilder content: () -> Content)
11+
image: Image,
12+
content: AnyView)
1313
{
1414
self.title = title
1515
self.image = image
16-
self.content = AnyView(content())
16+
self.content = content
1717
}
18-
19-
public var body: some View { EmptyView() }
20-
}
21-
22-
@available(macOS 11, iOS 14, *)
23-
public struct TossTabItemModifier: ViewModifier {
24-
let title: String
25-
let image: Image
26-
27-
public func body(content: Content) -> some View {
28-
content
29-
}
30-
}
31-
32-
@available(macOS 11, iOS 14, *)
33-
public protocol TossTabItemViewProtocol: View {
34-
var title: String { get }
35-
var image: Image { get }
36-
var content: AnyView { get }
3718
}

Sources/OpenTDS/Component/TabView/TabView.swift

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,12 @@ public struct TossTabView: View {
1818

1919
@State var selected: Int = 0
2020

21-
let content: [any TossTabItemViewProtocol]
21+
let content: [TossTabItem]
2222

23-
public init<C0: TossTabItemViewProtocol,
24-
C1: TossTabItemViewProtocol>(haptic: UIImpactFeedbackGenerator.FeedbackStyle? = .light,
25-
@ViewBuilder content: @escaping () -> TupleView<(C0, C1)>)
23+
public init(haptic: UIImpactFeedbackGenerator.FeedbackStyle? = .light,
24+
@TossTabViewBuilder content: () -> [TossTabItem])
2625
{
27-
let cv = content().value
28-
self.content = [cv.0, cv.1]
29-
}
30-
31-
public init<C0: TossTabItemViewProtocol,
32-
C1: TossTabItemViewProtocol,
33-
C2: TossTabItemViewProtocol>(haptic: UIImpactFeedbackGenerator.FeedbackStyle? = .light,
34-
@ViewBuilder content: @escaping () -> TupleView<(C0, C1, C2)>)
35-
{
36-
let cv = content().value
37-
self.content = [cv.0, cv.1, cv.2]
38-
}
39-
40-
public init<C0: TossTabItemViewProtocol,
41-
C1: TossTabItemViewProtocol,
42-
C2: TossTabItemViewProtocol,
43-
C3: TossTabItemViewProtocol>(haptic: UIImpactFeedbackGenerator.FeedbackStyle? = .light,
44-
@ViewBuilder content: @escaping () -> TupleView<(C0, C1, C2, C3)>)
45-
{
46-
let cv = content().value
47-
self.content = [cv.0, cv.1, cv.2, cv.3]
48-
}
49-
50-
public init<C0: TossTabItemViewProtocol,
51-
C1: TossTabItemViewProtocol,
52-
C2: TossTabItemViewProtocol,
53-
C3: TossTabItemViewProtocol,
54-
C4: TossTabItemViewProtocol>(haptic: UIImpactFeedbackGenerator.FeedbackStyle? = .light,
55-
@ViewBuilder content: @escaping () -> TupleView<(C0, C1, C2, C3, C4)>)
56-
{
57-
let cv = content().value
58-
self.content = [cv.0, cv.1, cv.2, cv.3, cv.4]
26+
self.content = content()
5927
}
6028

6129
public var body: some View {

0 commit comments

Comments
 (0)