-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0440196
commit 1159ca5
Showing
2 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |