I have the following code inside of a component: ...
# decompose
f
I have the following code inside of a component:
Copy code
init {
    lifecycle.doOnStart { // make some action }
}
But the action is not called in iOS. Are there some reason???
j
have you hooked up your lifecycle on iOS?
f
hummm no 😞 btw I do know how to do that.
j
f
ok thanks, I am using compose for ios, but I think is just to adapt it
j
this is my setup:
Copy code
// iOSApp.swift
@main
struct iOSApp: App {
    @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate

    @Environment(\.scenePhase) private var scenePhase

    var lifecycleHolder: LifecycleHolder { appDelegate.lifecycleHolder }

    var body: some Scene {
        WindowGroup {
            ComposeViewControllerToSwiftUI(lifecycleHolder.lifecycle)
                //.ignoresSafeArea()
                //.onTapGesture {
                    // Hide keyboard on tap outside of TextField
                    // UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
                //}
        }.onChange(of: scenePhase) { newPhase in
            switch newPhase {
                case .background: LifecycleRegistryExtKt.stop(lifecycleHolder.lifecycle)
                case .inactive: LifecycleRegistryExtKt.pause(lifecycleHolder.lifecycle)
                case .active: LifecycleRegistryExtKt.resume(lifecycleHolder.lifecycle)
                @unknown default: break
            }
        }
    }
}

class AppDelegate: NSObject, UIApplicationDelegate {
    let lifecycleHolder: LifecycleHolder = LifecycleHolder()
}

struct ComposeViewControllerToSwiftUI: UIViewControllerRepresentable {
    
    private let lifecycle: LifecycleRegistry
    
    init(_ lifecycle: LifecycleRegistry) {
        self.lifecycle = lifecycle
    }
    
    func makeUIViewController(context: Context) -> UIViewController {
       Main_iosKt.MainViewController(lifecycle: lifecycle)
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}

class LifecycleHolder : ObservableObject {
    let lifecycle: LifecycleRegistry

    init() {
        lifecycle = LifecycleRegistryKt.LifecycleRegistry()
        
        LifecycleRegistryExtKt.create(lifecycle)
    }

    deinit {
        // Destroy the root component before it is deallocated
        LifecycleRegistryExtKt.destroy(lifecycle)
    }
}
and for compose-multiplatform I have something like this in src-set iOSMain defined:
Copy code
fun MainViewController(lifecycle: Lifecycle): UIViewController {

    val root = RootComponent(
        componentContext = DefaultComponentContext(
            lifecycle = lifecycle,
            stateKeeper = StateKeeperDispatcher(),
            instanceKeeper = InstanceKeeperDispatcher()
        )
    )

    return ComposeUIViewController {
        AppContent(root)
    }
}
f
ahhh wait... I have an error in my code. Before I had the lifexcycle hooked, but I removed....damnnnn,
thank you so much for the help
j
glad to help
f
hello again
Copy code
error: cannot find type 'LifecycleRegistry' in scope
    let lifecycle: LifecycleRegistry
I unable to find LifecycleRegistry in swift.
import shared
is ok
I think that the framework for iOS is not correctly build. All I can recommend is check this link
maybe you added the wrong decompose deps?
f
maybe you added the wrong decompose deps?
No, the dependencies is right, but I did not export the deps
Do you know the reason we need export???
j
probably to generate the correct header files for iOS
f
ahhh ok
@Jan worked fine, tks a lot
🙌 1