App protocol in iOS - how do I pass EnvironmentObject #187
Replies: 3 comments 1 reply
-
OK... I'm back trying to resolve my "LAST" issue... passing in AppState to the App. Looking at the TravelBookings App - it seems to uses similar TravelBookingsApp.swift as the ScrumskipperApp.swift. Both are using an App wrapped by the #if !SKIP without an #else for the Android platform... so I get lost tracing this down. How does an Android App launch? My original App passes in the AppState via WindowGroup.environmentObject(appState) and the state get's handed to all children... `
}` My current issue... how do I do the similar thing with Skip? |
Beta Was this translation helpful? Give feedback.
-
I'm incompetent at reading Apple Docs... and learn best from examples, now. https://skip.tools/docs/components/observable/ I don't know the latest issues with Apple Observable and how it's morphed over the releases... it's looking like Skip has support for iOS 17 Observable... I'm I right / wrong or just off? That Skip web page doesn't tell ME much. What does it all mean? |
Beta Was this translation helpful? Give feedback.
-
I finally went back to the beginning - undoing some of my BONEHEAD changes... And looking at the example TravelBookings App used the methods there to declare an ObservedObject AppState. And injecting it with the View.environmentObject(appState) call. |
Beta Was this translation helpful? Give feedback.
-
I'm a bit confused with how to pass an AppState object into the SKIP application. Looking at the example Scrumdinger / Scrumskipper I don't see it passing in any Env Objs?
In the code for the App - there are #if !SKIP #endif - but no ELSE block... what happens on Android?
How does the Android App get launched and passed Env Objs?
I do NOT see the App protocol defined in that list of classes/objects: Components
https://skip.tools/docs/components/ so I'm not sure how the iOS gets ported to Android at the very top level.
Maybe I'm making this too hard... Got any better examples?
Ref: ScrumSkipper App
https://skip.tools/blog/scrumskipper/
Where the AppMain object declared in Darwin/Sources/ScrumskipperAppMain.swift
`import SwiftUI
import Scrumskipper
/// The entry point to the app simply loads the App implementation from SPM module.
@main struct AppMain: App, ScrumskipperApp {
}`
Has the ScrumskipperApp implementation Sources/Scrumskipper/ScrumskipperApp.swift
`import Foundation
import OSLog
import SwiftUI
let logger: Logger = Logger(subsystem: "com.xyz.Scrumskipper", category: "Scrumskipper")
/// The Android SDK number we are running against, or
nil
if not running on Androidlet androidSDK = ProcessInfo.processInfo.environment["android.os.Build.VERSION.SDK_INT"].flatMap({ Int($0) })
/// The shared top-level view for the app, loaded from the platform-specific App delegates below.
///
/// The default implementation merely loads the
ContentView
for the app and logs a message.public struct RootView : View {
public init() {
}
}
#if !SKIP
public protocol ScrumskipperApp : App {
}
/// The entry point to the Scrumskipper app.
/// The concrete implementation is in the ScrumskipperApp module.
public extension ScrumskipperApp {
var body: some Scene {
WindowGroup {
RootView()
}
}
}
#endif`
Beta Was this translation helpful? Give feedback.
All reactions