Swiftpack.co - heltena/Inactivity as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by heltena.
heltena/Inactivity 1.0.1
I needed to detect idle mode on a SwiftUI app for a kiosk, so I did it.
⭐️ 9
🕓 34 weeks ago
iOS
.package(url: "https://github.com/heltena/Inactivity.git", from: "1.0.1")

Inactivity

I needed to detect idle mode on a SwiftUI app for a kiosk, so I did it.

Usage

Note: The Principal class is not necessary.

This is an example:

InactivityWatcherView { proxy in
    InactiveView {
        proxy.becomeActive(timeout: 5)
    }
    .transition(.opacity)
    
    ActiveView()
        .transition(.opacity)
}

Also, you can perform an action when the state changes:

Text("Example")
    .onInactivityStateChanged { state in print("Going to \(state)") }

Finally, it is possible to access to the InactivityWatcher class using the shared attribute of the InactivityApplication:

InactivityApplication.shared.watcher.startWatch(timeout: 120)

Find an Xcode app example here: https://github.com/heltena/InactivityExample

Enjoy!

GitHub

link
Stars: 9
Last commit: 2 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.0.1
34 weeks ago

Adapted code to work on SwiftUI life cycle

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics