Skip to content

Commit 984b69c

Browse files
committed
ADD: Back Button Feature
1 parent 283e9d5 commit 984b69c

File tree

7 files changed

+74
-6
lines changed

7 files changed

+74
-6
lines changed

Sources/OpenTDS/Component/Example/ExampleView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ struct ExampleView: View {
55
TossScrollView("전체") {
66
Text("AnyView")
77
}
8+
.showDismiss()
89
}
910
}
1011

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import SwiftUI
2+
3+
extension TossScrollView {
4+
public func showDismiss() -> TossScrollView {
5+
TossScrollView(self.title, showsIndicators: self.showsIndicators, showsDismiss: true) {
6+
self.content
7+
}
8+
}
9+
}

Sources/OpenTDS/Component/ScrollView/ScrollView.swift

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import SwiftUI
1010
@available(macOS 11, iOS 14, *)
1111
public struct TossScrollView<Content: View>: View {
1212

13+
@Environment(\.presentationMode) var presentationMode
1314
@State var shrink: Bool = false
15+
1416
let title: String
1517
let showsIndicators: Bool
18+
let showsDismiss: Bool
1619
let content: Content
1720

1821
/**
@@ -22,19 +25,35 @@ public struct TossScrollView<Content: View>: View {
2225
*/
2326
public init(_ title: String,
2427
showsIndicators: Bool = true,
28+
showsDismiss: Bool = false,
2529
@ViewBuilder content: @escaping () -> Content) {
2630
self.title = title
2731
self.showsIndicators = showsIndicators
32+
self.showsDismiss = false
2833
self.content = content()
2934
}
3035

3136
public var body: some View {
3237
VStack {
33-
Text(title)
34-
.font(.system(size: 17, weight: .medium))
35-
.opacity(shrink ? 1 : 0)
36-
.padding(.vertical, 6)
37-
.frame(maxWidth: .infinity)
38+
ZStack {
39+
HStack {
40+
Button(action: {
41+
presentationMode.wrappedValue.dismiss()
42+
}) {
43+
TossIcon.chevron
44+
.resizable()
45+
.frame(width: 10.14, height: 17.77)
46+
.foregroundColor(Color(.label))
47+
}
48+
Spacer()
49+
}
50+
.padding(.horizontal, 18)
51+
Text(title)
52+
.font(.system(size: 17, weight: .medium))
53+
.opacity(shrink ? 1 : 0)
54+
.padding(.vertical, 6)
55+
}
56+
.frame(maxWidth: .infinity)
3857
GeometryReader { outsideProxy in
3958
ScrollView(showsIndicators: showsIndicators) {
4059
VStack(spacing: 36) {
@@ -46,7 +65,7 @@ public struct TossScrollView<Content: View>: View {
4665
DispatchQueue.main.async {
4766
let proxy = outsideProxy.frame(in: .global).minY - newValue
4867
withAnimation(.default) {
49-
shrink = proxy > 33
68+
shrink = proxy > 30
5069
}
5170
}
5271
}
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 enum TossIcon {
5+
public static let chevron: Image = Image("Chevron", bundle: .module)
6+
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "Chevron.svg",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
},
21+
"properties" : {
22+
"template-rendering-intent" : "template"
23+
}
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}

0 commit comments

Comments
 (0)