Skip to content

Commit 4f340e0

Browse files
author
Fernando Moya de Rivas
committed
Buildable: Disabling tapping
Adding modifiers to disable content tapping
1 parent 4dd351d commit 4f340e0

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

Sources/SwiftUIMenu/Menu+Buildable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ extension Menu: Buildable {
4040
mutating(keyPath: \.allowsDragging, value: false)
4141
}
4242

43+
/// Removes the `TapGesture` used to close the menu by tapping on the section content
44+
public func disableContentTap() -> Self {
45+
mutating(keyPath: \.allowsTapping, value: false)
46+
}
47+
48+
/// Adds a `TapGesture` to close the menu by tapping on the section content
49+
public func allowContentTap() -> Self {
50+
mutating(keyPath: \.allowsTapping, value: false)
51+
}
52+
4353
/// Adds a header to the menu drawer
4454
public func header<Header: View>(@ViewBuilder header: @escaping () -> Header) -> Self {
4555
let header = { AnyView(header()) }

Sources/SwiftUIMenu/Menu.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public struct Menu<Item, ID, Row, Content>: View where Item: Equatable, Row: Vie
7272
/// `true` if `Menu` can be open by dragging
7373
var allowsDragging = true
7474

75+
/// `true` if `Menu` can be closed by tapping on the content
76+
var allowsTapping = true
77+
7578
/// Section list size proportion relative to the menu size
7679
var revealRatio: CGFloat = 1
7780

@@ -259,11 +262,13 @@ extension Menu {
259262
return ZStack { content }
260263
.frame(size: size)
261264
.contentShape(Rectangle())
262-
.onTapGesture (perform: {
263-
withAnimation(Animation.easeOut(duration: 0.25)) {
264-
self.isOpen = false
265-
}
266-
})
265+
.simultaneousGesture(!allowsTapping ? nil :
266+
TapGesture(count: 1)
267+
.onEnded({
268+
withAnimation(Animation.easeOut(duration: 0.25)) {
269+
self.isOpen = false
270+
}
271+
}))
267272
}
268273

269274
/// The drawer menu that slides from the side

SwiftUIMenu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "SwiftUIMenu"
4-
s.version = "1.1.0"
4+
s.version = "1.1.1"
55
s.summary = "Native component in SwiftUI to implement Menu Navigation Pattern. Easy to use, easy to customize."
66

77
s.description = <<-DESC

SwiftUIMenu.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@
319319
"@executable_path/Frameworks",
320320
"@loader_path/Frameworks",
321321
);
322-
MARKETING_VERSION = 1.1.0;
322+
MARKETING_VERSION = 1.1.1;
323323
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.example.SwiftUIMenu;
324324
PRODUCT_NAME = "$(TARGET_NAME)";
325325
SDKROOT = macosx;
@@ -348,7 +348,7 @@
348348
"@executable_path/Frameworks",
349349
"@loader_path/Frameworks",
350350
);
351-
MARKETING_VERSION = 1.1.0;
351+
MARKETING_VERSION = 1.1.1;
352352
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.example.SwiftUIMenu;
353353
PRODUCT_NAME = "$(TARGET_NAME)";
354354
SDKROOT = macosx;
@@ -376,7 +376,7 @@
376376
"@executable_path/Frameworks",
377377
"@loader_path/Frameworks",
378378
);
379-
MARKETING_VERSION = 1.1.0;
379+
MARKETING_VERSION = 1.1.1;
380380
PRODUCT_BUNDLE_IDENTIFIER = "com.fermoya.challenge.SwiftUIMenu-watchOS";
381381
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
382382
SDKROOT = watchos;
@@ -405,7 +405,7 @@
405405
"@executable_path/Frameworks",
406406
"@loader_path/Frameworks",
407407
);
408-
MARKETING_VERSION = 1.1.0;
408+
MARKETING_VERSION = 1.1.1;
409409
PRODUCT_BUNDLE_IDENTIFIER = "com.fermoya.challenge.SwiftUIMenu-watchOS";
410410
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
411411
SDKROOT = watchos;
@@ -561,7 +561,7 @@
561561
"@executable_path/Frameworks",
562562
"@loader_path/Frameworks",
563563
);
564-
MARKETING_VERSION = 1.1.0;
564+
MARKETING_VERSION = 1.1.1;
565565
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.example.SwiftUIMenu;
566566
PRODUCT_NAME = SwiftUIMenu_iOS;
567567
SKIP_INSTALL = YES;
@@ -589,7 +589,7 @@
589589
"@executable_path/Frameworks",
590590
"@loader_path/Frameworks",
591591
);
592-
MARKETING_VERSION = 1.1.0;
592+
MARKETING_VERSION = 1.1.1;
593593
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.example.SwiftUIMenu;
594594
PRODUCT_NAME = SwiftUIMenu_iOS;
595595
SKIP_INSTALL = YES;

0 commit comments

Comments
 (0)