skiptools / skip-ui

SwiftUI for Android
https://skip.tools
GNU Lesser General Public License v3.0
119 stars 12 forks source link

ScenePhase, applicationState... #38

Closed jeffc-dev closed 3 months ago

jeffc-dev commented 3 months ago

SkipUI does not currently support the ability to tie into the .scenePhase environment key.

This makes it impossible to run certain code on Android when a given app enters or returns from the background.

@Environment(\.scenePhase) var scenePhase

// ...

VStack {
    // ...
}
.onChange(of: self.scenePhase) { oldPhase, newPhase in
    if newPhase == .active {
        // ...do something here...
    }
}

On a related note, it also does not appear that Skip supports the following, either:

UIApplication.shared.applicationState

While this is part of UIKit, it is still useful in order to get the application state (foreground, background) state within a reusable framework that has no SwiftUI component. It'd be helpful to either add support for it or have an alternative approach to getting this information within a non-UI framework.

Thanks!

Note: This is not super high priority for me.

aabewhite commented 3 months ago

Thanks for the request! This is something we've wanted to implement anyway. Unfortunately figuring out the application state has historically been more difficult than you would expect on Android, but we'll figure it out

aabewhite commented 3 months ago

Added in skip-ui 0.9.9