Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Example/SwipeActionsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -280,6 +281,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -294,6 +296,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = WV6XDLHK3W;
Expand All @@ -308,9 +311,13 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = app.getfind.SwipeActionsExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -322,6 +329,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = WV6XDLHK3W;
Expand All @@ -336,9 +344,13 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = app.getfind.SwipeActionsExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
10 changes: 10 additions & 0 deletions Example/SwipeActionsExample/ContentView+Customization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ extension ContentView {
if showingCustomizationClear {
SwipeView {
Container(title: "Notification", details: "Swipe for options") {
#if os(iOS)
VisualEffectView(.systemThinMaterial)
#endif
}
} trailingActions: { _ in
SwipeAction {} label: { highlight in
Text("Options")
} background: { highlight in
#if os(iOS)
VisualEffectView(.systemThinMaterial)
.brightness(highlight ? -0.1 : 0)
#endif
}

SwipeAction {
Expand All @@ -38,8 +42,10 @@ extension ContentView {
} label: { highlight in
Text("Clear")
} background: { highlight in
#if os(iOS)
VisualEffectView(.systemThinMaterial)
.brightness(highlight ? -0.1 : 0)
#endif
}
.allowSwipeToTrigger()
}
Expand All @@ -54,7 +60,9 @@ extension ContentView {
#" backgroundColor: .blue"#,
#") {}"#
) {
#if os(iOS)
VisualEffectView(.systemThickMaterial)
#endif
}
} trailingActions: { _ in
SwipeAction(
Expand All @@ -75,7 +83,9 @@ extension ContentView {
#") {}"#,
#" .swipeActionChangeLabelVisibilityOnly(true)"#
) {
#if os(iOS)
VisualEffectView(.systemChromeMaterial)
#endif
}
} trailingActions: { _ in
SwipeAction(
Expand Down
33 changes: 30 additions & 3 deletions Example/SwipeActionsExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ struct ContentView: View {

@State var expandedSectionKinds = DemoSectionKind.allCases
@State var showingDebug = false

/// Calculatable `ToolbarItemPlacement` modifier for iOS and macOS platforms
private var toolbarGroupPlacement: ToolbarItemPlacement {
#if os(iOS)
return .navigationBarTrailing
#else
return .automatic
#endif
}

var body: some View {
VStack {
Expand Down Expand Up @@ -139,7 +148,7 @@ struct ContentView: View {
.font(.system(.body, design: .monospaced).weight(.semibold))
}
.multilineTextAlignment(.center)
.accent(.primary)
.accentColor(.primary)
.padding(.top, 20)
.transition(.scale(scale: 0.8).combined(with: .opacity))
}
Expand All @@ -163,7 +172,7 @@ struct ContentView: View {
.padding(.bottom, 32)
}
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
ToolbarItemGroup(placement: toolbarGroupPlacement) {
let shouldExpandAll: Bool = {
if expandedSectionKinds.count == DemoSectionKind.allCases.count {
return false
Expand All @@ -190,7 +199,7 @@ struct ContentView: View {
}
} label: {
Image(systemName: shouldExpandAll ? "arrow.up.backward.and.arrow.down.forward" : "arrow.down.forward.and.arrow.up.backward")
.noAnimation()
.animation(nil)
}
}
}
Expand Down Expand Up @@ -229,11 +238,17 @@ struct DemoSection<Content: View>: View {
Image(systemName: "chevron.right")
.rotationEffect(.degrees(expanded.wrappedValue ? 90 : 0))
}
#if os(iOS)
.foregroundColor(.primary)
#else
.foregroundColor(.black)
#endif
.font(.title3.weight(.bold))
.padding(.horizontal, 24)
.padding(.vertical)
#if os(iOS)
.background(VisualEffectView(.systemChromeMaterial))
#endif
.cornerRadius(32)
.environment(\.colorScheme, .dark)
}
Expand All @@ -249,8 +264,10 @@ struct DemoSection<Content: View>: View {
.font(.title3.weight(.medium))
.environment(\.colorScheme, .dark)
} background: { highlight in
#if os(iOS)
VisualEffectView(.systemChromeMaterial)
.environment(\.colorScheme, .dark)
#endif
}
.allowSwipeToTrigger()
}
Expand All @@ -265,6 +282,7 @@ struct DemoSection<Content: View>: View {
}

/// Use UIKit blurs in SwiftUI.
#if os(iOS)
struct VisualEffectView: UIViewRepresentable {
/// The blur's style.
public var style: UIBlurEffect.Style
Expand All @@ -282,13 +300,22 @@ struct VisualEffectView: UIViewRepresentable {
uiView.effect = UIBlurEffect(style: style)
}
}
#endif

private struct BackgroundColorKey: EnvironmentKey {
#if os(iOS)
static let defaultValue = Color(.systemBackground)
#else
static let defaultValue = Color(.windowBackgroundColor)
#endif
}

private struct SecondaryBackgroundColorKey: EnvironmentKey {
#if os(iOS)
static let defaultValue = Color(.secondarySystemBackground)
#else
static let defaultValue = Color(.windowBackgroundColor)
#endif
}

extension EnvironmentValues {
Expand Down
2 changes: 2 additions & 0 deletions Example/SwipeActionsExample/SwipeActionsExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ struct SwipeActionsExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
#if os(iOS)
.environment(\.backgroundColor, Color(colorScheme == .light ? .systemBackground : .secondarySystemBackground))
.environment(\.secondaryBackgroundColor, Color(colorScheme == .light ? .secondarySystemBackground : .systemBackground))
#endif
}
}
}
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import PackageDescription
let package = Package(
name: "SwipeActions",
platforms: [
.iOS(.v14)
.iOS(.v14),
.macOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
13 changes: 10 additions & 3 deletions Sources/SwipeActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ public struct SwipeOptions {

/// Ensure that the user must drag a significant amount to trigger the edge action, even if the actions' total width is small.
var minimumPointToTrigger = Double(200)

#if os(iOS)
/// Applies if `swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge` is true.
/// Available only for iOS platform
var enableTriggerHaptics = true

#else
var enableTriggerHaptics = false
#endif
/// Applies if `swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge` is false, or when there's no actions on one side.
var stretchRubberBandingPower = Double(0.7)

Expand Down Expand Up @@ -458,7 +461,7 @@ public struct SwipeView<Label, LeadingActions, TrailingActions>: View where Labe
}

// MARK: - Trigger haptics

#if os(iOS)
.onChange(of: leadingState) { [leadingState] newValue in
/// Make sure the change was from `triggering` to `nil`, or the other way around.
let changed =
Expand All @@ -481,6 +484,7 @@ public struct SwipeView<Label, LeadingActions, TrailingActions>: View where Labe
generator.impactOccurred()
}
}
#endif

// MARK: - Receive `SwipeViewGroup` events

Expand Down Expand Up @@ -1198,12 +1202,15 @@ public extension SwipeView {
return view
}

#if os(iOS)
/// Applies if `swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge` is true.
/// Available only for iOS platform
func swipeEnableTriggerHaptics(_ value: Bool) -> SwipeView {
var view = self
view.options.enableTriggerHaptics = value
return view
}
#endif

/// Applies if `swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge` is false, or when there's no actions on one side.
func swipeStretchRubberBandingPower(_ value: Double) -> SwipeView {
Expand Down