Skip to content

Commit

Permalink
ADD: Button Component
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercen-Lee committed Jul 14, 2023
1 parent ae0f829 commit 5cd3d9e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,27 @@ dependencies: [
```

## Components
- [TossButton](#tossbutton)
- [TossTabView](#tosstabview)
- [TossTabViewButton](#tosstabviewbutton)
- [TossScrollView](#tossscrollview)

## Examples
```swift
import OpenTDS
```

### TossButton
> Animated Button of Toss.
```swift
TossButton(action: {
anyMethod()
}) {
Text("Button")
.padding()
}
```

### TossTabView
> Animated Tab View of Toss.
- The number of Views must be between 2 and 5.
Expand Down
8 changes: 8 additions & 0 deletions Sources/OpenTDS/Component/Button/Button+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// File.swift
//
//
// Created by Mercen on 2023/07/14.
//

import Foundation
32 changes: 26 additions & 6 deletions Sources/OpenTDS/Component/Button/Button.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import SwiftUI

@available(macOS 11, iOS 14, *)
struct TossButton: View {
var body: some View {
Button(action: {

/**
Animated Button of Toss.

TossButton(action: {
anyMethod()
}) {

Text("Button")
.padding()
}
*/
@available(macOS 11, iOS 14, *)
struct TossButton<Content: View>: View {

let action: () -> ()
let content: Content

/**
- Parameters:
- action: Action when the Button pressed.
*/
public init(action: @escaping () -> (),
@ViewBuilder content: @escaping () -> Content) {
self.action = action
self.content = content()
}

var body: some View {
content
}
}
11 changes: 6 additions & 5 deletions Sources/OpenTDS/Component/TabView/TabView+Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import SwiftUI
@available(macOS 11, iOS 14, *)
public struct TossTabViewButton: View {

@State var buttonRect: CGRect = CGRect.zero
@State var animationState: Int = 0
@State var touchdownState: Bool = false
@State var rectangleState: Bool = false

let label: String
let image: Image
let action: () -> ()
var selected: Bool
let haptic: UIImpactFeedbackGenerator.FeedbackStyle?
@State var buttonRect: CGRect = CGRect.zero
@State var animationState: Int = 0
@State var touchdownState: Bool = false
@State var rectangleState: Bool = false

/**
- Parameters:
Expand All @@ -31,7 +32,7 @@ public struct TossTabViewButton: View {
public init(_ label: String,
_ image: Image,
_ selected: Bool,
haptic: UIImpactFeedbackGenerator.FeedbackStyle? = nil,
haptic: UIImpactFeedbackGenerator.FeedbackStyle? = .light,
action: @escaping () -> ())
{
self.label = label
Expand Down
1 change: 1 addition & 0 deletions Sources/OpenTDS/Component/TabView/TabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import SwiftUI
public struct TossTabView: View {

@State var selected: Int = 0

let content: [any TossTabItemViewProtocol]

public init<C0: TossTabItemViewProtocol,
Expand Down

0 comments on commit 5cd3d9e

Please sign in to comment.