From 526f6d4a23df5a286efadd22ed5df37e5f2ef5a2 Mon Sep 17 00:00:00 2001 From: damien-nd Date: Tue, 24 May 2022 12:13:43 +0200 Subject: [PATCH] Add isDraggable to PartialSheetManager --- .../Examples/ViewModifierExample.swift | 8 ++++++++ Sources/PartialSheet/PartialSheetManager.swift | 2 ++ Sources/PartialSheet/PartialSheetViewModifier.swift | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Example/PartialSheetExample/Examples/ViewModifierExample.swift b/Example/PartialSheetExample/Examples/ViewModifierExample.swift index bd14410..18a3b65 100644 --- a/Example/PartialSheetExample/Examples/ViewModifierExample.swift +++ b/Example/PartialSheetExample/Examples/ViewModifierExample.swift @@ -9,6 +9,8 @@ import SwiftUI struct ViewModifierExample: View { + @EnvironmentObject var partialSheetManager: PartialSheetManager + @State var isSheetShown = false @State var viewContent = "Initial content" var body: some View { @@ -28,6 +30,12 @@ struct ViewModifierExample: View { ViewModifierView(content: self.$viewContent) .padding(.vertical, 50) } + .onAppear { + partialSheetManager.isDraggable = false + } + .onDisappear { + partialSheetManager.isDraggable = true + } } } diff --git a/Sources/PartialSheet/PartialSheetManager.swift b/Sources/PartialSheet/PartialSheetManager.swift index c833107..7e1aa28 100644 --- a/Sources/PartialSheet/PartialSheetManager.swift +++ b/Sources/PartialSheet/PartialSheetManager.swift @@ -34,6 +34,8 @@ public class PartialSheetManager: ObservableObject { } } } + /// Published var to activate or not drag gesture on the partial sheet + @Published var isDraggable: Bool = true /// The content of the sheet @Published private(set) var content: AnyView /// the onDismiss code runned when the partial sheet is closed diff --git a/Sources/PartialSheet/PartialSheetViewModifier.swift b/Sources/PartialSheet/PartialSheetViewModifier.swift index 9927451..0cd5741 100644 --- a/Sources/PartialSheet/PartialSheetViewModifier.swift +++ b/Sources/PartialSheet/PartialSheetViewModifier.swift @@ -247,7 +247,9 @@ extension PartialSheet { .cornerRadius(style.cornerRadius) .shadow(color: Color(.sRGBLinear, white: 0, opacity: 0.13), radius: 10.0) .offset(y: self.sheetPosition) - .gesture(drag) + .ifIs(manager.isDraggable, transform: { view in + view.gesture(drag) + }) } } }