Skip to content

Commit

Permalink
FIX: Closure Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercen-Lee committed Jul 16, 2023
1 parent c1e530c commit a0730a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 3 additions & 5 deletions Sources/OpenTDS/Component/ScrollView/ScrollView+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ extension TossScrollView {
public func showDismiss() -> TossScrollView {
self.backButton()
}

public func backButton(action: @escaping () -> () = {
let presentationMode = Environment(\.presentationMode).wrappedValue
presentationMode.wrappedValue.dismiss()
}) -> TossScrollView {

public func backButton(action: (() -> ())? = nil) -> TossScrollView {
TossScrollView(self.title,
showsIndicators: self.showsIndicators,
backButtonExists: true,
backButtonAction: action) {
self.content
}
Expand Down
15 changes: 12 additions & 3 deletions Sources/OpenTDS/Component/ScrollView/ScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import SwiftUI
*/
@available(macOS 11, iOS 14, *)
public struct TossScrollView<Content: View>: View {

@Environment(\.presentationMode) var presentationMode
@State var shrink: Bool = false

let title: String
let showsIndicators: Bool
let backButtonExists: Bool
let backButtonAction: (() -> ())?
let content: Content

Expand All @@ -25,10 +26,12 @@ public struct TossScrollView<Content: View>: View {
*/
public init(_ title: String,
showsIndicators: Bool = true,
backButtonExists: Bool = false,
backButtonAction: (() -> ())? = nil,
@ViewBuilder content: @escaping () -> Content) {
self.title = title
self.showsIndicators = showsIndicators
self.backButtonExists = backButtonExists
self.backButtonAction = backButtonAction
self.content = content()
}
Expand All @@ -37,8 +40,14 @@ public struct TossScrollView<Content: View>: View {
VStack {
ZStack {
HStack {
if let backButtonAction = backButtonAction {
Button(action: backButtonAction) {
if backButtonExists {
Button(action: {
if let backButtonAction = backButtonAction {
backButtonAction()
} else {
presentationMode.wrappedValue.dismiss()
}
}) {
TossIcon.chevron
.resizable()
.frame(width: 10.14, height: 17.77)
Expand Down

0 comments on commit a0730a9

Please sign in to comment.