https://kotlinlang.org logo
#decompose
Title
# decompose
r

ribesg

02/26/2024, 2:54 PM
I'm trying to setup my iOS app but nothing happens, I just have a black screen. The
ComposeUIViewController
just does not seem to start or something
Here is my AppDelegate.kt:
Copy code
class AppDelegate @OverrideInit constructor() : NSObject(), UIApplicationDelegateProtocol {

    companion object : NSObjectMeta(), UIApplicationDelegateProtocolMeta

    private val startComponentContext: ComponentContext =
        DefaultComponentContext(ApplicationLifecycle())

    private var uiWindow: UIWindow? = null

    override fun application(
        application: UIApplication,
        didFinishLaunchingWithOptions: Map<Any?, *>?,
    ): Boolean {
        startKoin(koinAppDeclaration)
        configureWindowWithStartComponent()
        return true
    }

    override fun setWindow(window: UIWindow?) {
        uiWindow = window
    }

    override fun window(): UIWindow? = uiWindow

    private fun configureWindowWithStartComponent() {
        setWindow(UIWindow(frame = UIScreen.mainScreen.bounds))
        window!!.run {
            backgroundColor = UIColor.blackColor
            Logger.d { "Before ComposeUIViewController creation" }
            rootViewController = ComposeUIViewController {
                Logger.d { "Inside ComposeUIViewController content" }
                StartContent(DefaultStartComponent(startComponentContext))
            }
            makeKeyAndVisible()
        }
    }

}
I can see the first log but not the second one
I also have this warning after the first log, might be related to the issue:
Copy code
First responder issue detected: non-key window attempting reload - allowing due to manual keyboard (first responder window is <UIWindow: 0x13eb08180; frame = (0 0; 393 852); gestureRecognizers = <NSArray: 0x6000026a4e10>; backgroundColor = UIExtendedGrayColorSpace 0 1; layer = <UIWindowLayer: 0x6000026b59e0>>, key window is (null))
I don't have any Swift code, I'm using a Kotlin main that I am calling from main.swift
Copy code
fun main(args: List<String>) {
    memScoped {
        autoreleasepool {
            UIApplicationMain(
                argc = args.size + 1,
                argv = arrayOf("konan", *args.toTypedArray()).toCStringArray(memScope),
                principalClassName = null,
                delegateClassName = NSStringFromClass(AppDelegate)
            )
        }
    }
}
This is the method I used in my previous iOS app which was basically UIKit in Kotlin, and I found no decompose documentation on how to use Decompose + Compose UI on iOS
I don't know what the issue was, I started randomly deleting configuration entires in the XCode project related to scenes and launchscreen stuff… And it ended up showing my app. I don't think it's related to decompose in any way. I'm still not there yet, it doesn't take the full screen 😅
Obviously, I needed to add an empty
UILaunchScreen
key to Info.plist… Who like iOS anyway
6 Views