Skip to content

Commit

Permalink
Merge pull request #15 from lorenzhk/main
Browse files Browse the repository at this point in the history
Make it work for @StateObject style example
  • Loading branch information
ezefranca authored Jun 19, 2023
2 parents 8b78e9a + d409bab commit df242a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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

0 comments on commit df242a8

Please sign in to comment.