Skip to content

Commit

Permalink
ADD: Toolbar Option for ScrollView
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercen-Lee committed Oct 16, 2023
1 parent f5a7513 commit a776086
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import SwiftUI

@resultBuilder
public struct TossToolbarButtonBuilder {
public static func buildBlock(_ components: TossToolbarButton...) -> [TossToolbarButton] {
components
}
}
29 changes: 29 additions & 0 deletions Sources/OpenTDS/Component/Button/Toolbar/ToolbarButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import SwiftUI

@available(macOS 11, iOS 14, *)
public struct TossToolbarButton: View {

let image: Image
let action: () -> ()

/**
- Parameters:
- image: Image of the Button.
- action: Action when the Button pressed.
*/
public init(_ image: Image, action: @escaping () -> ()) {
self.image = image
self.action = action
}

public var body: some View {
Button(action: action) {
image
.resizable()
.renderingMode(.template)
.scaledToFit()
.frame(width: 22, height: 22)
.foregroundColor(TossColor.button)
}
}
}
11 changes: 9 additions & 2 deletions Sources/OpenTDS/Component/Example/ExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import SwiftUI
struct ExampleView: View {
var body: some View {
TossTabView {
Text("View1")
.tossTabItem("View1", Image(systemName: "house.fill"))
TossScrollView("a") {
Text("View1")
}
.toolbarButton {
TossToolbarButton(Image(systemName: "house.fill"), action: {

})
}
.tossTabItem("View1", Image(systemName: "house.fill"))
Text("View2")
.tossTabItem("View2", Image(systemName: "person.fill"))
}
Expand Down
15 changes: 13 additions & 2 deletions Sources/OpenTDS/Component/ScrollView/ScrollView+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ extension TossScrollView {
TossScrollView(self.title,
showsIndicators: self.showsIndicators,
backButtonExists: true,
backButtonAction: action) {
self.content
backButtonAction: action,
toolbarButton: self.toolbarButton) {
self.content()
}
}

public func toolbarButton(@TossToolbarButtonBuilder content: () -> [TossToolbarButton]) -> TossScrollView {
TossScrollView(self.title,
showsIndicators: self.showsIndicators,
backButtonExists: self.backButtonExists,
backButtonAction: self.backButtonAction,
toolbarButton: content()) {
self.content()
}
}
}
20 changes: 14 additions & 6 deletions Sources/OpenTDS/Component/ScrollView/ScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SwiftUI
}
*/
@available(macOS 11, iOS 14, *)
public struct TossScrollView<Content: View>: View {
public struct TossScrollView<C: View>: View {

@Environment(\.presentationMode) var presentationMode
@State var shrink: Bool = false
Expand All @@ -17,7 +17,8 @@ public struct TossScrollView<Content: View>: View {
let showsIndicators: Bool
let backButtonExists: Bool
let backButtonAction: (() -> ())?
let content: Content
let toolbarButton: [TossToolbarButton]?
let content: () -> C

/**
- Parameters:
Expand All @@ -28,18 +29,20 @@ public struct TossScrollView<Content: View>: View {
showsIndicators: Bool = true,
backButtonExists: Bool = false,
backButtonAction: (() -> ())? = nil,
@ViewBuilder content: @escaping () -> Content) {
toolbarButton: [TossToolbarButton]? = nil,
@ViewBuilder content: @escaping () -> C) {
self.title = title
self.showsIndicators = showsIndicators
self.backButtonExists = backButtonExists
self.backButtonAction = backButtonAction
self.content = content()
self.toolbarButton = toolbarButton
self.content = content
}

public var body: some View {
VStack {
ZStack {
HStack {
HStack(spacing: 26) {
if backButtonExists {
Button(action: {
if let backButtonAction = backButtonAction {
Expand All @@ -55,6 +58,11 @@ public struct TossScrollView<Content: View>: View {
}
}
Spacer()
if let toolbarButton {
ForEach(toolbarButton.indices, id: \.self) { idx in
toolbarButton[idx]
}
}
}
.padding(.horizontal, 18)
Text(title)
Expand All @@ -79,7 +87,7 @@ public struct TossScrollView<Content: View>: View {
}
}
}
content
content()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenTDS/Component/TabView/TabView+Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public struct TossTabViewButton: View {
.padding(2)
.scaleEffect(x: animationState == 2 ? 1.1 : 1, y: 1)
.scaleEffect(x: 1, y: animationState == 3 ? 1.05 : 1)
.foregroundColor(selected || touchdownState ? TossColor.label : TossColor.tabViewButtonIcon)
.foregroundColor(selected || touchdownState ? TossColor.label : TossColor.button)
Text(label)
.font(.system(size: 11, weight: .medium))
.scaleEffect(animationState == 2 ? 1.05 : 1)
.foregroundColor(selected || touchdownState ? TossColor.label : TossColor.tabViewButtonLabel)
.foregroundColor(selected || touchdownState ? TossColor.label : TossColor.buttonLabel)
}
}
.frame(width: 56, height: 56)
Expand Down
3 changes: 1 addition & 2 deletions Sources/OpenTDS/Component/TabView/TabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public struct TossTabView: View {
let content: [TossTabItem]

public init(haptic: UIImpactFeedbackGenerator.FeedbackStyle? = .light,
@TossTabViewBuilder content: () -> [TossTabItem])
{
@TossTabViewBuilder content: () -> [TossTabItem]) {
self.content = content()
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenTDS/Foundation/Color/TossColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public enum TossColor {
extension TossColor {

public static let homeBackground: Color = dynamicColor("#F3F4F6", dark: "#101013")
public static let tabViewButtonIcon: Color = dynamicColor("#B1B8C0", dark: "#62626D")
public static let tabViewButtonLabel: Color = dynamicColor("#6D7582", dark: "#9E9EA4")
public static let button: Color = dynamicColor("#B1B8C0", dark: "#62626D")
public static let buttonLabel: Color = dynamicColor("#6D7582", dark: "#9E9EA4")
public static let background: Color = dynamicColor("#FFFFFF", dark: "#17171C")
public static let label: Color = dynamicColor("#1A1E27", dark: "#FFFFFF")
public static let stripe: Color = dynamicColor("#E4E8EB", dark: "#3C3C47")
Expand Down

0 comments on commit a776086

Please sign in to comment.