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

In example of @StateObject style, WatchShaker has go be inherited with ObservableObject #14

Open
lorenzhk opened this issue Jun 14, 2023 · 5 comments
Labels

Comments

@lorenzhk
Copy link
Contributor

Beside the captioned issue, looks like "isShakerAvailable" is not the right published variable to look at to detect a Shake? Wonder how the library can be tweaked to support native SwiftUI lifecycle to trigger action given a shake. Thanks.

@szagun
Copy link

szagun commented Jun 15, 2023

isShakerAvailable shows pretty much what the name suggests, I guess. Instead shake will return the lastest detected shake. To get it working, just make WatchShaker conform to ObservableObject and Shake to Equatable, so you can listen to shake, using .onChange(of:perform:):

extension WatchShaker : ObservableObject { }
extension Shake : Equatable {
    public static func == (lhs: Shake, rhs: Shake) -> Bool {
        lhs.direction == rhs.direction && lhs.sensibility == rhs.sensibility
    }
}

@lorenzhk
Copy link
Contributor Author

Thanks @szagun , good hint. I tried, and it revert with this when shake is detected. I believe the code itself are not optimized with the @mainactor so to update in main thread and main queue?

AIReplay[2082:3808856] [SwiftUI] Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.

@szagun
Copy link

szagun commented Jun 16, 2023

@lorenzhk This is fixed on the latest commit. Remove the package from your project and re-add it, this time set Dependency rule to branch: main or commit: 03f2234feb260a1c8ded87477633fbe0235a17c8.

You should read the package source code, it's really quite simple. Anyways, hf and build something great!

@lorenzhk
Copy link
Contributor Author

Cool, thx for the hint @szagun . It did fix the issue above.

Besides, i doubt Shake class perhaps need to include lastShakeDate so for onChange correctly identify new shake with identical direction. Let me try to do one and make PR. Thanks so much.

@ezefranca
Copy link
Owner

Hi @szagun and @lorenzhk, thanks for yours contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants