Setup - trueangle/Blackbox GitHub Wiki
To deal with Compose Multiplatform, you might probably need to setup project configuration first. Please refer to Compose Multiplatform project template for further details.
When the project is set. Add the dependency in your common module's commonMain sourceSet
implementation("io.github.trueangle:blackbox:LATEST_VERSION")
Android
Blackbox framework is built on top of PreCompose navigation library fork. So, it uses the original entry points supplied by PreCompose package.
For androidMain target simply extend your app's activity with PreComposeActivity from the framework's package.
class MainActivity : PreComposeActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
// call your app @Composable entry point here
}
}
}
iOS
For iosMain target there is PreComposeAppController.
fun createBlackBoxApp() = PreComposeAppController {
// call your app @Composable entry point here
}
You can call the controller wherever you want in your existing iOS app navigation or set it up as window.rootViewController in your AppDelegate or SceneDelegate.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = YourEntryPointFileKt.createBlackBoxApp()
window?.makeKeyAndVisible()
return true
}
}
PreComposeAppController provides API methods for saving app state using NsUserActivity and SceneDelegate. To learn more about it, please refer Navigation: State save wiki page. Full example of Scene Delegate app setup that is completely written in Kotlin.
Desktop (JVM)
Use PreComposeWindow for jvmMain target
fun main() = application {
PreComposeWindow(
title = "Blackbox App",
onCloseRequest = {
exitApplication()
},
) {
// call your app @Composable entry point here
}
}