Skip to content

Commit c1e530c

Browse files
committed
UPDATE: Back Button Action
1 parent ca763f1 commit c1e530c

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
//
2-
// File.swift
3-
//
4-
//
5-
// Created by Mercen on 2023/07/14.
6-
//
7-
81
import Foundation

Sources/OpenTDS/Component/ScrollView/ScrollView+Ext.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import SwiftUI
22

33
extension TossScrollView {
4+
5+
@available(*, deprecated, renamed: "backButton")
46
public func showDismiss() -> TossScrollView {
5-
TossScrollView(self.title, showsIndicators: self.showsIndicators, showsDismiss: true) {
7+
self.backButton()
8+
}
9+
10+
public func backButton(action: @escaping () -> () = {
11+
let presentationMode = Environment(\.presentationMode).wrappedValue
12+
presentationMode.wrappedValue.dismiss()
13+
}) -> TossScrollView {
14+
TossScrollView(self.title,
15+
showsIndicators: self.showsIndicators,
16+
backButtonAction: action) {
617
self.content
718
}
819
}

Sources/OpenTDS/Component/ScrollView/ScrollView.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct TossScrollView<Content: View>: View {
1515

1616
let title: String
1717
let showsIndicators: Bool
18-
let showsDismiss: Bool
18+
let backButtonAction: (() -> ())?
1919
let content: Content
2020

2121
/**
@@ -25,22 +25,20 @@ public struct TossScrollView<Content: View>: View {
2525
*/
2626
public init(_ title: String,
2727
showsIndicators: Bool = true,
28-
showsDismiss: Bool = false,
28+
backButtonAction: (() -> ())? = nil,
2929
@ViewBuilder content: @escaping () -> Content) {
3030
self.title = title
3131
self.showsIndicators = showsIndicators
32-
self.showsDismiss = showsDismiss
32+
self.backButtonAction = backButtonAction
3333
self.content = content()
3434
}
3535

3636
public var body: some View {
3737
VStack {
3838
ZStack {
3939
HStack {
40-
if showsDismiss {
41-
Button(action: {
42-
presentationMode.wrappedValue.dismiss()
43-
}) {
40+
if let backButtonAction = backButtonAction {
41+
Button(action: backButtonAction) {
4442
TossIcon.chevron
4543
.resizable()
4644
.frame(width: 10.14, height: 17.77)

0 commit comments

Comments
 (0)