Skip to content

Commit

Permalink
ADD: ScrollView
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercen-Lee committed Jul 12, 2023
1 parent 0440196 commit 1159ca5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Sources/OpenTDS/Component/Example/ExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import SwiftUI

struct ExampleView: View {
var body: some View {
TossTabView {
Text("a")
.tossTabItem("", Image(systemName: "house.fill"))
Text("b")
.tossTabItem("마이", Image(systemName: "person.fill"))
TossScrollView("전체") {
Text("AnyView")
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions Sources/OpenTDS/Component/ScrollView/ScrollView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import SwiftUI

/**
Dynamic Scroll View of Toss.

TossScrollView("Home") {
AnyView()
}
*/
@available(macOS 11, iOS 14, *)
public struct TossScrollView<Content: View>: View {

@State var shrink: Bool = false
let title: String
let showsIndicators: Bool
let content: Content

/**
- Parameters:
- title: Title of the View.
- showsIndicators: To show indicators or not.
*/
public init(_ title: String,
showsIndicators: Bool = true,
@ViewBuilder content: @escaping () -> Content) {
self.title = title
self.showsIndicators = showsIndicators
self.content = content()
}

public var body: some View {
VStack {
Text(title)
.font(.system(size: 17, weight: .medium))
.opacity(shrink ? 1 : 0)
.padding(.vertical, 12)
.frame(maxWidth: .infinity)
GeometryReader { outsideProxy in
ScrollView(showsIndicators: showsIndicators) {
VStack(spacing: 36) {
GeometryReader { insideProxy in
Text(title)
.font(.system(size: 26, weight: .bold))
.padding(.leading, 24)
.onChange(of: insideProxy.frame(in: .global).minY) { newValue in
DispatchQueue.main.async {
let proxy = outsideProxy.frame(in: .global).minY - newValue
withAnimation(.default) {
shrink = proxy > 36
}
}
}
}
content
}
}
}
}
}
}

0 comments on commit 1159ca5

Please sign in to comment.