From 0bf1900afe04f338d7f05b60f69e2583c7da2e41 Mon Sep 17 00:00:00 2001 From: Daniel Saidi Date: Mon, 2 Sep 2024 15:31:00 +0200 Subject: [PATCH] Deprecate gesture buttons --- RELEASE_NOTES.md | 4 + .../Resources/Localizable.xcstrings | 3 - .../SwiftUIKit/SwiftUIKit.docc/SwiftUIKit.md | 4 - .../GestureButton.swift | 171 +--------------- .../GestureButtonDefaults.swift | 2 +- .../RepeatGestureTimer.swift | 12 +- .../ScrollViewGestureButton.swift | 185 +----------------- 7 files changed, 16 insertions(+), 365 deletions(-) rename Sources/SwiftUIKit/{Gestures => _Deprecated}/GestureButton.swift (58%) rename Sources/SwiftUIKit/{Gestures => _Deprecated}/GestureButtonDefaults.swift (85%) rename Sources/SwiftUIKit/{Gestures => _Deprecated}/RepeatGestureTimer.swift (87%) rename Sources/SwiftUIKit/{Gestures => _Deprecated}/ScrollViewGestureButton.swift (64%) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b445ee1f14..f848fc70f6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -15,6 +15,10 @@ This version also adds standard button types, which makes it easier to create st * `Button+Init` adds a new button initializer. * `Button+Standard` adds new standard button types. +### 🗑️ Deprecations + +* `GestureButton` and `ScrollGestureButton` has been moved to `https://github.com/danielsaidi/GestureButton`. + ## 4.2.3 diff --git a/Sources/SwiftUIKit/Resources/Localizable.xcstrings b/Sources/SwiftUIKit/Resources/Localizable.xcstrings index 0addd43a14..fc70162e79 100644 --- a/Sources/SwiftUIKit/Resources/Localizable.xcstrings +++ b/Sources/SwiftUIKit/Resources/Localizable.xcstrings @@ -9,9 +9,6 @@ }, "%@" : { - }, - "%@:" : { - }, "%lld" : { diff --git a/Sources/SwiftUIKit/SwiftUIKit.docc/SwiftUIKit.md b/Sources/SwiftUIKit/SwiftUIKit.docc/SwiftUIKit.md index 7ea27c1236..843099efcc 100644 --- a/Sources/SwiftUIKit/SwiftUIKit.docc/SwiftUIKit.md +++ b/Sources/SwiftUIKit/SwiftUIKit.docc/SwiftUIKit.md @@ -82,11 +82,7 @@ SwiftUIKit is available under the MIT license. See the [LICENSE][License] file f ### Gestures -- ``GestureButton`` -- ``GestureButtonDefaults`` - ``GestureTimer`` -- ``RepeatGestureTimer`` -- ``ScrollViewGestureButton`` - ``SwipeGestureViewModifier`` ### Images diff --git a/Sources/SwiftUIKit/Gestures/GestureButton.swift b/Sources/SwiftUIKit/_Deprecated/GestureButton.swift similarity index 58% rename from Sources/SwiftUIKit/Gestures/GestureButton.swift rename to Sources/SwiftUIKit/_Deprecated/GestureButton.swift index 8b0f3fe3ed..4c76506cb3 100644 --- a/Sources/SwiftUIKit/Gestures/GestureButton.swift +++ b/Sources/SwiftUIKit/_Deprecated/GestureButton.swift @@ -9,14 +9,7 @@ #if os(iOS) || os(macOS) || os(watchOS) import SwiftUI -/** - This button supports triggering different gestures in a way - that maximizes performance. - - This button can't be used in a `ScrollView` since it blocks - the scroll view gesture. To implement multi-gesture support - in a `ScrollView`, use a ``ScrollViewGestureButton``. - */ +@available(*, deprecated, message: "This has moved to https://github.com/danielsaidi/GestureButton") public struct GestureButton: View { /// Create a gesture button. @@ -116,6 +109,7 @@ public struct GestureButton: View { } } +@available(*, deprecated, message: "This has moved.") private extension GestureButton { var gestureView: some View { @@ -136,6 +130,7 @@ private extension GestureButton { } } +@available(*, deprecated, message: "This has moved.") private extension GestureButton { func tryHandlePress(_ value: DragGesture.Value) { @@ -203,164 +198,4 @@ private extension GeometryProxy { return true } } - -#Preview { - - struct Preview: View { - - @StateObject - var state = PreviewState() - - @State - private var items = (1...3).map { PreviewItem(id: $0) } - - var body: some View { - VStack(spacing: 20) { - - PreviewHeader(state: state) - .padding(.horizontal) - - PreviewButtonGroup(title: "Buttons:") { - GestureButton( - isPressed: $state.isPressed, - pressAction: { state.pressCount += 1 }, - releaseInsideAction: { state.releaseInsideCount += 1 }, - releaseOutsideAction: { state.releaseOutsideCount += 1 }, - longPressDelay: 0.8, - longPressAction: { state.longPressCount += 1 }, - doubleTapAction: { state.doubleTapCount += 1 }, - repeatAction: { state.repeatTapCount += 1 }, - dragStartAction: { state.dragStartedValue = $0.location }, - dragAction: { state.dragChangedValue = $0.location }, - dragEndAction: { state.dragEndedValue = $0.location }, - endAction: { state.endCount += 1 }, - label: { PreviewButton(color: .blue, isPressed: $0) } - ) - } - } - } - } - - struct PreviewItem: Identifiable { - - var id: Int - } - - struct PreviewButton: View { - - let color: Color - let isPressed: Bool - - var body: some View { - color - .cornerRadius(10) - .opacity(isPressed ? 0.5 : 1) - .scaleEffect(isPressed ? 0.9 : 1) - .animation(.default, value: isPressed) - .padding() - .background(Color.random()) - .cornerRadius(16) - } - } - - struct PreviewButtonGroup: View { - - let title: String - let button: () -> Content - - var body: some View { - VStack(alignment: .leading, spacing: 5) { - Text(title) - HStack { - ForEach(0...3, id: \.self) { _ in - button() - } - }.frame(maxWidth: .infinity) - }.padding(.horizontal) - } - } - - class PreviewState: ObservableObject { - - @Published - var isPressed = false - - @Published - var pressCount = 0 - - @Published - var releaseInsideCount = 0 - - @Published - var releaseOutsideCount = 0 - - @Published - var endCount = 0 - - @Published - var longPressCount = 0 - - @Published - var doubleTapCount = 0 - - @Published - var repeatTapCount = 0 - - @Published - var dragStartedValue = CGPoint.zero - - @Published - var dragChangedValue = CGPoint.zero - - @Published - var dragEndedValue = CGPoint.zero - } - - struct PreviewHeader: View { - - @ObservedObject - var state: PreviewState - - var body: some View { - VStack(alignment: .leading) { - Group { - label("Pressed", state.isPressed ? "YES" : "NO") - label("Presses", state.pressCount) - label("Releases", state.releaseInsideCount + state.releaseOutsideCount) - label(" Inside", state.releaseInsideCount) - label(" Outside", state.releaseOutsideCount) - label("Ended", state.endCount) - label("Long presses", state.longPressCount) - label("Double taps", state.doubleTapCount) - label("Repeats", state.repeatTapCount) - } - Group { - label("Drag started", state.dragStartedValue) - label("Drag changed", state.dragChangedValue) - label("Drag ended", state.dragEndedValue) - } - } - .frame(maxWidth: .infinity, alignment: .leading) - .padding() - .background(RoundedRectangle(cornerRadius: 16).stroke(.blue, lineWidth: 3)) - } - - func label(_ title: String, _ int: Int) -> some View { - label(title, "\(int)") - } - - func label(_ title: String, _ point: CGPoint) -> some View { - label(title, "\(point.x.rounded()), \(point.y.rounded())") - } - - func label(_ title: String, _ value: String) -> some View { - HStack { - Text("\(title):") - Text(value).bold() - }.lineLimit(1) - } - } - - return Preview() -} #endif diff --git a/Sources/SwiftUIKit/Gestures/GestureButtonDefaults.swift b/Sources/SwiftUIKit/_Deprecated/GestureButtonDefaults.swift similarity index 85% rename from Sources/SwiftUIKit/Gestures/GestureButtonDefaults.swift rename to Sources/SwiftUIKit/_Deprecated/GestureButtonDefaults.swift index 03f9af250f..753e01a4b2 100644 --- a/Sources/SwiftUIKit/Gestures/GestureButtonDefaults.swift +++ b/Sources/SwiftUIKit/_Deprecated/GestureButtonDefaults.swift @@ -8,7 +8,7 @@ import Foundation -/// This struct is used to configure gesture button defaults. +@available(*, deprecated, message: "This has moved to https://github.com/danielsaidi/GestureButton") public struct GestureButtonDefaults { /// The max time between two taps to count as a double tap, by default `0.2`. diff --git a/Sources/SwiftUIKit/Gestures/RepeatGestureTimer.swift b/Sources/SwiftUIKit/_Deprecated/RepeatGestureTimer.swift similarity index 87% rename from Sources/SwiftUIKit/Gestures/RepeatGestureTimer.swift rename to Sources/SwiftUIKit/_Deprecated/RepeatGestureTimer.swift index 04a56391e0..c2bf873355 100644 --- a/Sources/SwiftUIKit/Gestures/RepeatGestureTimer.swift +++ b/Sources/SwiftUIKit/_Deprecated/RepeatGestureTimer.swift @@ -8,12 +8,7 @@ import Foundation -/** - This class is used to handle repeating actions on a gesture. - - The ``shared`` instance can be used if only a single button - can be pressed to repeat a certain action at any given time. - */ +@available(*, deprecated, message: "This has moved to https://github.com/danielsaidi/GestureButton") public class RepeatGestureTimer { /// Create a repeat gesture timer. @@ -41,6 +36,8 @@ public class RepeatGestureTimer { private var startDate: Date? } + +@available(*, deprecated, message: "This has moved to https://github.com/danielsaidi/GestureButton") public extension RepeatGestureTimer { /// The elapsed time since the timer was started. @@ -68,9 +65,6 @@ public extension RepeatGestureTimer { timer = nil startDate = nil } -} - -extension RepeatGestureTimer { func modifyStartDate(to date: Date) { startDate = date diff --git a/Sources/SwiftUIKit/Gestures/ScrollViewGestureButton.swift b/Sources/SwiftUIKit/_Deprecated/ScrollViewGestureButton.swift similarity index 64% rename from Sources/SwiftUIKit/Gestures/ScrollViewGestureButton.swift rename to Sources/SwiftUIKit/_Deprecated/ScrollViewGestureButton.swift index 2f43d7ae67..2dac14cb9c 100644 --- a/Sources/SwiftUIKit/Gestures/ScrollViewGestureButton.swift +++ b/Sources/SwiftUIKit/_Deprecated/ScrollViewGestureButton.swift @@ -9,22 +9,7 @@ #if os(iOS) || os(macOS) || os(watchOS) import SwiftUI -/** - This button supports triggering different gestures in a way - that works within a `ScrollView`. - - This button does npt block scroll view gesture. The code is - the result of much trial & error and has been tested to not - affect scrolling. - - If you don't need to use a scroll view, you should consider - using a ``GestureButton`` instead.- - - Note that the view uses an underlying `ButtonStyle` to make - gestures work. It can thus not apply another style, but you - can use the `isPressed` value that is passed to the `label` - builder, to configure the button view for the pressed state. - */ +@available(*, deprecated, message: "This has moved to https://github.com/danielsaidi/GestureButton") public struct ScrollViewGestureButton: View { /// Create a gesture button. @@ -122,6 +107,7 @@ public struct ScrollViewGestureButton: View { } } +@available(*, deprecated, message: "This has moved") extension ScrollViewGestureButton { class GestureState: ObservableObject { @@ -189,6 +175,7 @@ extension ScrollViewGestureButton { } } +@available(*, deprecated, message: "This has moved") private extension ScrollViewGestureButton.Style { func handleIsPressed() { @@ -211,6 +198,7 @@ private extension ScrollViewGestureButton.Style { } } +@available(*, deprecated, message: "This has moved") private extension View { typealias Action = () -> Void @@ -272,6 +260,7 @@ private extension View { } } +@available(*, deprecated, message: "This has moved") private extension GeometryProxy { func contains(_ dragEndLocation: CGPoint) -> Bool { @@ -282,168 +271,4 @@ private extension GeometryProxy { return true } } - -#Preview { - - struct Preview: View { - - @StateObject - var state = PreviewState() - - @State - private var items = (1...100).map { PreviewItem(id: $0) } - - var body: some View { - VStack(spacing: 20) { - - PreviewHeader(state: state) - .padding(.horizontal) - - PreviewScrollGroup(title: "Buttons") { - ScrollViewGestureButton( - isPressed: $state.isPressed, - pressAction: { state.pressCount += 1 }, - releaseInsideAction: { state.releaseInsideCount += 1 }, - releaseOutsideAction: { state.releaseOutsideCount += 1 }, - longPressDelay: 0.8, - longPressAction: { state.longPressCount += 1 }, - doubleTapAction: { state.doubleTapCount += 1 }, - repeatAction: { state.repeatTapCount += 1 }, - dragStartAction: { state.dragStartValue = $0.location }, - dragAction: { state.dragChangeValue = $0.location }, - dragEndAction: { state.dragEndValue = $0.location }, - endAction: { state.endCount += 1 }, - label: { PreviewButton(color: .blue, isPressed: $0) } - ) - } - } - } - } - - struct PreviewItem: Identifiable { - - var id: Int - } - - struct PreviewButton: View { - - let color: Color - let isPressed: Bool - - var body: some View { - color - .cornerRadius(10) - .frame(width: 100) - .opacity(isPressed ? 0.5 : 1) - .scaleEffect(isPressed ? 0.9 : 1) - .animation(.default, value: isPressed) - .padding() - .background(Color.random()) - .cornerRadius(16) - } - } - - struct PreviewScrollGroup: View { - - let title: String - let button: () -> Content - - var body: some View { - VStack(alignment: .leading, spacing: 0) { - Text(title) - .padding(.horizontal) - ScrollView(.horizontal) { - LazyHStack { - ForEach(0...100, id: \.self) { _ in - button() - } - }.padding(.horizontal) - } - } - } - } - - class PreviewState: ObservableObject { - - @Published - var isPressed = false - - @Published - var pressCount = 0 - - @Published - var releaseInsideCount = 0 - - @Published - var releaseOutsideCount = 0 - - @Published - var endCount = 0 - - @Published - var longPressCount = 0 - - @Published - var doubleTapCount = 0 - - @Published - var repeatTapCount = 0 - - @Published - var dragStartValue = CGPoint.zero - - @Published - var dragChangeValue = CGPoint.zero - - @Published - var dragEndValue = CGPoint.zero - } - - struct PreviewHeader: View { - - @ObservedObject - var state: PreviewState - - var body: some View { - VStack(alignment: .leading) { - Group { - label("Pressed", state.isPressed ? "YES" : "NO") - label("Presses", state.pressCount) - label("Releases", state.releaseInsideCount + state.releaseOutsideCount) - label(" Inside", state.releaseInsideCount) - label(" Outside", state.releaseOutsideCount) - label("Ended", state.endCount) - label("Long presses", state.longPressCount) - label("Double taps", state.doubleTapCount) - label("Repeats", state.repeatTapCount) - } - Group { - label("Drag start", state.dragStartValue) - label("Drag change", state.dragChangeValue) - label("Drag end", state.dragEndValue) - } - } - .frame(maxWidth: .infinity, alignment: .leading) - .padding() - .background(RoundedRectangle(cornerRadius: 16).stroke(.blue, lineWidth: 3)) - } - - func label(_ title: String, _ int: Int) -> some View { - label(title, "\(int)") - } - - func label(_ title: String, _ point: CGPoint) -> some View { - label(title, "\(point.x.rounded()), \(point.y.rounded())") - } - - func label(_ title: String, _ value: String) -> some View { - HStack { - Text("\(title):") - Text(value).bold() - }.lineLimit(1) - } - } - - return Preview() -} #endif