Skip to content

Commit

Permalink
Deprecate gesture buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Sep 2, 2024
1 parent 2d5a331 commit 0bf1900
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 365 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions Sources/SwiftUIKit/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
},
"%@" : {

},
"%@:" : {

},
"%lld" : {

Expand Down
4 changes: 0 additions & 4 deletions Sources/SwiftUIKit/SwiftUIKit.docc/SwiftUIKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Label: View>: View {

/// Create a gesture button.
Expand Down Expand Up @@ -116,6 +109,7 @@ public struct GestureButton<Label: View>: View {
}
}

@available(*, deprecated, message: "This has moved.")
private extension GestureButton {

var gestureView: some View {
Expand All @@ -136,6 +130,7 @@ private extension GestureButton {
}
}

@available(*, deprecated, message: "This has moved.")
private extension GestureButton {

func tryHandlePress(_ value: DragGesture.Value) {
Expand Down Expand Up @@ -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<Content: View>: 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
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -68,9 +65,6 @@ public extension RepeatGestureTimer {
timer = nil
startDate = nil
}
}

extension RepeatGestureTimer {

func modifyStartDate(to date: Date) {
startDate = date
Expand Down
Loading

0 comments on commit 0bf1900

Please sign in to comment.