Skip to content

Commit

Permalink
Fixes issue where draggesture would interfere with pickerwheel (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
styrken authored Aug 16, 2020
1 parent db2fe55 commit 5467190
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Example/PartialSheetExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
1F177AA623E1F0E0006F59D0 /* PartialSheetViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F177AA323E1F0E0006F59D0 /* PartialSheetViewModifier.swift */; };
1F177AA723E1F0E0006F59D0 /* DragState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F177AA423E1F0E0006F59D0 /* DragState.swift */; };
1F177AA823E1F0E0006F59D0 /* View+PartialSheetModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F177AA523E1F0E0006F59D0 /* View+PartialSheetModifier.swift */; };
3B9841FC24E880870052A996 /* PickerExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B9841FA24E880870052A996 /* PickerExample.swift */; };
3B9841FD24E880870052A996 /* DatePickerExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B9841FB24E880870052A996 /* DatePickerExample.swift */; };
3BF874DF24E6F4DE004F4550 /* BlurredSheetExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BF874DE24E6F4DE004F4550 /* BlurredSheetExample.swift */; };
/* End PBXBuildFile section */

Expand All @@ -46,6 +48,8 @@
1F177AA323E1F0E0006F59D0 /* PartialSheetViewModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PartialSheetViewModifier.swift; sourceTree = "<group>"; };
1F177AA423E1F0E0006F59D0 /* DragState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DragState.swift; sourceTree = "<group>"; };
1F177AA523E1F0E0006F59D0 /* View+PartialSheetModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "View+PartialSheetModifier.swift"; sourceTree = "<group>"; };
3B9841FA24E880870052A996 /* PickerExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PickerExample.swift; sourceTree = "<group>"; };
3B9841FB24E880870052A996 /* DatePickerExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatePickerExample.swift; sourceTree = "<group>"; };
3BF874DE24E6F4DE004F4550 /* BlurredSheetExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurredSheetExample.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -63,6 +67,8 @@
01A013972458E4C300D0F5DD /* Examples */ = {
isa = PBXGroup;
children = (
3B9841FB24E880870052A996 /* DatePickerExample.swift */,
3B9841FA24E880870052A996 /* PickerExample.swift */,
01A013932458E4A900D0F5DD /* NormalExample.swift */,
01A013952458E4C000D0F5DD /* TextfieldExample.swift */,
01A013982458E4D800D0F5DD /* ListExample.swift */,
Expand Down Expand Up @@ -197,6 +203,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3B9841FC24E880870052A996 /* PickerExample.swift in Sources */,
01CCB63C244AEE3900F7F67F /* View+IfDeviceType.swift in Sources */,
01294541244ED5E5006190B0 /* PartialSheetStyle.swift in Sources */,
0174F417245962B80053C454 /* PushNavigationExample.swift in Sources */,
Expand All @@ -207,6 +214,7 @@
01477D8B2458E928007AE720 /* PartialSheetManager.swift in Sources */,
1F177AA823E1F0E0006F59D0 /* View+PartialSheetModifier.swift in Sources */,
1DDC0E5923E3E6DB0033EC03 /* ContentView.swift in Sources */,
3B9841FD24E880870052A996 /* DatePickerExample.swift in Sources */,
0174F419245A569C0053C454 /* BlurEffectView.swift in Sources */,
1F177AA723E1F0E0006F59D0 /* DragState.swift in Sources */,
1F177AA623E1F0E0006F59D0 /* PartialSheetViewModifier.swift in Sources */,
Expand Down
11 changes: 9 additions & 2 deletions Example/PartialSheetExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ struct ContentView: View {
label: {Text("Push Navigation Example")

})
NavigationLink(
destination: DatePickerExample(),
label: {Text("DatePicker Example")
})
NavigationLink(
destination: PickerExample(),
label: {Text("Picker Example")
})
NavigationLink(
destination: BlurredExample(),
label: {Text("Blurred Example")

})
})
}
Spacer()
Spacer()
Expand Down
59 changes: 59 additions & 0 deletions Example/PartialSheetExample/Examples/DatePickerExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// DatePickerExample.swift
// PartialSheetExample
//
// Created by Rasmus Styrk on 14/08/2020.
// Copyright © 2020 Swift. All rights reserved.
//

import SwiftUI

struct DatePickerExample: View {

@EnvironmentObject var partialSheetManager : PartialSheetManager

var body: some View {
HStack {
Spacer()
Button(action: {
self.partialSheetManager.showPartialSheet({
print("DatePickerExample sheet dismissed")
}) {
DatePickerSheetView()
}
}, label: {
Text("Display the DatePickerExample Sheet")
})
.padding()
Spacer()
}
.navigationBarTitle("DatePickerExample Example")
.navigationViewStyle(StackNavigationViewStyle())
}
}

struct DatePickerExample_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
DatePickerSheetView()
}
.addPartialSheet()
.navigationViewStyle(StackNavigationViewStyle())
.environmentObject(PartialSheetManager())
}
}

struct DatePickerSheetView: View {
@State private var date: Date = Date()

var body: some View {
VStack {
VStack {
Text("Settings Panel").font(.headline)
DatePicker("Date", selection: $date)
}
.padding()
.frame(height: 270)
}
}
}
64 changes: 64 additions & 0 deletions Example/PartialSheetExample/Examples/PickerExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// PickerExample.swift
// PartialSheetExample
//
// Created by Rasmus Styrk on 14/08/2020.
// Copyright © 2020 Swift. All rights reserved.
//

import SwiftUI

struct PickerExample: View {

@EnvironmentObject var partialSheetManager : PartialSheetManager

var body: some View {
HStack {
Spacer()
Button(action: {
self.partialSheetManager.showPartialSheet({
print("PickerExample sheet dismissed")
}) {
PickerSheetView()
}
}, label: {
Text("Display the PickerExample Sheet")
})
.padding()
Spacer()
}
.navigationBarTitle("PickerExample Example")
.navigationViewStyle(StackNavigationViewStyle())
}
}

struct PickerExample_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
PickerSheetView()
}
.addPartialSheet()
.navigationViewStyle(StackNavigationViewStyle())
.environmentObject(PartialSheetManager())
}
}

struct PickerSheetView: View {
var strengths = ["Mild", "Medium", "Mature"]
@State private var selectedStrength = 0

var body: some View {
VStack {
VStack {
Text("Settings Panel").font(.headline)
Picker(selection: $selectedStrength, label: EmptyView()) {
ForEach(0 ..< strengths.count) {
Text(self.strengths[$0])
}
}
}
.padding()
.frame(height: 250)
}
}
}
2 changes: 1 addition & 1 deletion Sources/PartialSheet/PartialSheetViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ extension PartialSheet {

/// Create a new **DragGesture** with *updating* and *onEndend* func
private func dragGesture() -> _EndedGesture<GestureStateGesture<DragGesture, DragState>> {
DragGesture()
DragGesture(minimumDistance: 30, coordinateSpace: .local)
.updating($dragState) { drag, state, _ in
self.dismissKeyboard()
let yOffset = drag.translation.height
Expand Down

0 comments on commit 5467190

Please sign in to comment.