Browse Source

Introduce defaultUIKitMain in compose library and use it from UIKit examples (#2426)

pull/2439/head
Nikita Lipsky 2 years ago committed by GitHub
parent
commit
daafd804f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      experimental/examples/chat-mpp/gradle.properties
  2. 35
      experimental/examples/chat-mpp/src/uikitMain/kotlin/main.uikit.kt
  3. 2
      experimental/examples/falling-balls-mpp/gradle.properties
  4. 35
      experimental/examples/falling-balls-mpp/src/uikitMain/kotlin/main.uikit.kt
  5. 2
      experimental/examples/minesweeper/build.gradle.kts
  6. 35
      experimental/examples/minesweeper/src/uikitMain/kotlin/main.uikit.kt

2
experimental/examples/chat-mpp/gradle.properties

@ -1,4 +1,4 @@
compose.version=1.3.0-alpha01-dev824
compose.version=1.3.0-alpha01-dev827
kotlin.version=1.7.10
agp.version=7.0.4
org.gradle.jvmargs=-Xmx3g

35
experimental/examples/chat-mpp/src/uikitMain/kotlin/main.uikit.kt

@ -1,37 +1,8 @@
import androidx.compose.ui.window.Application
import kotlinx.cinterop.*
import platform.UIKit.*
import platform.Foundation.*
import androidx.compose.ui.main.defaultUIKitMain
fun main() {
val args = emptyArray<String>()
memScoped {
val argc = args.size + 1
val argv = (arrayOf("skikoApp") + args).map { it.cstr.ptr }.toCValues()
autoreleasepool {
UIApplicationMain(argc, argv, null, NSStringFromClass(SkikoAppDelegate))
}
}
}
class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol {
companion object : UIResponderMeta(), UIApplicationDelegateProtocolMeta
@ObjCObjectBase.OverrideInit
constructor() : super()
private var _window: UIWindow? = null
override fun window() = _window
override fun setWindow(window: UIWindow?) {
_window = window
}
override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean {
window = UIWindow(frame = UIScreen.mainScreen.bounds)
window!!.rootViewController = Application("Chat") {
defaultUIKitMain("Chat", Application("Chat") {
ChatApp()
}
window!!.makeKeyAndVisible()
return true
}
})
}

2
experimental/examples/falling-balls-mpp/gradle.properties

@ -1,4 +1,4 @@
compose.version=1.3.0-alpha01-dev824
compose.version=1.3.0-alpha01-dev827
kotlin.version=1.7.10
agp.version=7.0.4
org.gradle.jvmargs=-Xmx3g

35
experimental/examples/falling-balls-mpp/src/uikitMain/kotlin/main.uikit.kt

@ -10,40 +10,14 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Application
import kotlinx.cinterop.*
import platform.UIKit.*
import platform.Foundation.*
import androidx.compose.ui.main.defaultUIKitMain
object UikitTime : Time {
override fun now(): Long = kotlin.system.getTimeNanos()
}
fun main() {
val args = emptyArray<String>()
memScoped {
val argc = args.size + 1
val argv = (arrayOf("skikoApp") + args).map { it.cstr.ptr }.toCValues()
autoreleasepool {
UIApplicationMain(argc, argv, null, NSStringFromClass(SkikoAppDelegate))
}
}
}
class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol {
companion object : UIResponderMeta(), UIApplicationDelegateProtocolMeta
@ObjCObjectBase.OverrideInit
constructor() : super()
private var _window: UIWindow? = null
override fun window() = _window
override fun setWindow(window: UIWindow?) {
_window = window
}
override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean {
window = UIWindow(frame = UIScreen.mainScreen.bounds)
window!!.rootViewController = Application("Falling Balls") {
defaultUIKitMain("FallingBalls", Application("Falling Balls") {
val game = remember { Game(UikitTime) }
Column {
// To skip upper part of screen.
@ -51,8 +25,5 @@ class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol {
.height(100.dp))
FallingBalls(game)
}
}
window!!.makeKeyAndVisible()
return true
}
})
}

2
experimental/examples/minesweeper/build.gradle.kts

@ -16,7 +16,7 @@ buildscript {
plugins {
kotlin("multiplatform") version "1.7.10"
id("org.jetbrains.compose") version "1.3.0-alpha01-dev824"
id("org.jetbrains.compose") version "1.3.0-alpha01-dev827"
}
version = "1.0-SNAPSHOT"

35
experimental/examples/minesweeper/src/uikitMain/kotlin/main.uikit.kt

@ -14,46 +14,17 @@ import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Application
import kotlinx.cinterop.*
import platform.UIKit.*
import platform.Foundation.*
import androidx.compose.ui.main.defaultUIKitMain
fun main() {
val args = emptyArray<String>()
memScoped {
val argc = args.size + 1
val argv = (arrayOf("skikoApp") + args).map { it.cstr.ptr }.toCValues()
autoreleasepool {
UIApplicationMain(argc, argv, null, NSStringFromClass(SkikoAppDelegate))
}
}
}
class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol {
companion object : UIResponderMeta(), UIApplicationDelegateProtocolMeta
@ObjCObjectBase.OverrideInit
constructor() : super()
private var _window: UIWindow? = null
override fun window() = _window
override fun setWindow(window: UIWindow?) {
_window = window
}
override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean {
window = UIWindow(frame = UIScreen.mainScreen.bounds)
window!!.rootViewController = Application("Minesweeper") {
defaultUIKitMain("Minesweeper", Application("Minesweeper") {
Column {
// To skip upper part of screen.
Box(modifier = Modifier
.height(100.dp))
Game()
}
}
window!!.makeKeyAndVisible()
return true
}
})
}
@Composable

Loading…
Cancel
Save