Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it work for @StateObject style example #15

Merged
merged 3 commits into from
Jun 19, 2023
Merged
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
9 changes: 8 additions & 1 deletion Sources/WatchShaker/Shake.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
public struct Shake {
import Foundation

public struct Shake: Equatable {
public let sensibility: ShakeSensibility
public let direction: ShakeDirection
public let time: Date

public static func == (lhs: Shake, rhs: Shake) -> Bool {
lhs.direction == rhs.direction && lhs.sensibility == rhs.sensibility && lhs.time == rhs.time
}
}
6 changes: 3 additions & 3 deletions Sources/WatchShaker/WatchShaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import CoreMotion
///
/// Discussion:
/// - The WatchShaker object is your entry point to the shake service.
public class WatchShaker : NSObject
public class WatchShaker : NSObject, ObservableObject
{
public var delegate: WatchShakerDelegate?
public var startWatchShakerUpdates: WatchShakerHandler?
public private(set) var coordinates: ShakeCoordinates?

@Published public var isShakerAvailable: Bool = false
@Published public var shake: Shake = .init(sensibility: .shakeSensibilityNormal, direction: .shakeDirectionDown)
@Published public var shake: Shake = .init(sensibility: .shakeSensibilityNormal, direction: .shakeDirectionDown, time: Date.now)

fileprivate var motionManager: CMMotionManager!
fileprivate var lastShakeDate: Date?
Expand Down Expand Up @@ -113,7 +113,7 @@ public class WatchShaker : NSObject
direction: .direction(coordinates?.x ?? 0, coordinates?.y ?? 0))

self.shake = .init(sensibility: sensibility,
direction: .direction(coordinates?.x ?? 0, coordinates?.y ?? 0))
direction: .direction(coordinates?.x ?? 0, coordinates?.y ?? 0), time: lastShakeDate ?? Date.now)
self.startWatchShakerUpdates?(self.sensibility, self.coordinates, nil)
}
}
Expand Down