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. 37
      experimental/examples/chat-mpp/src/uikitMain/kotlin/main.uikit.kt
  3. 2
      experimental/examples/falling-balls-mpp/gradle.properties
  4. 47
      experimental/examples/falling-balls-mpp/src/uikitMain/kotlin/main.uikit.kt
  5. 2
      experimental/examples/minesweeper/build.gradle.kts
  6. 45
      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 kotlin.version=1.7.10
agp.version=7.0.4 agp.version=7.0.4
org.gradle.jvmargs=-Xmx3g org.gradle.jvmargs=-Xmx3g

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

@ -1,37 +1,8 @@
import androidx.compose.ui.window.Application import androidx.compose.ui.window.Application
import kotlinx.cinterop.* import androidx.compose.ui.main.defaultUIKitMain
import platform.UIKit.*
import platform.Foundation.*
fun main() { fun main() {
val args = emptyArray<String>() defaultUIKitMain("Chat", Application("Chat") {
memScoped { ChatApp()
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") {
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 kotlin.version=1.7.10
agp.version=7.0.4 agp.version=7.0.4
org.gradle.jvmargs=-Xmx3g org.gradle.jvmargs=-Xmx3g

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

@ -10,49 +10,20 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Application import androidx.compose.ui.window.Application
import kotlinx.cinterop.* import androidx.compose.ui.main.defaultUIKitMain
import platform.UIKit.*
import platform.Foundation.*
object UikitTime : Time { object UikitTime : Time {
override fun now(): Long = kotlin.system.getTimeNanos() override fun now(): Long = kotlin.system.getTimeNanos()
} }
fun main() { fun main() {
val args = emptyArray<String>() defaultUIKitMain("FallingBalls", Application("Falling Balls") {
memScoped { val game = remember { Game(UikitTime) }
val argc = args.size + 1 Column {
val argv = (arrayOf("skikoApp") + args).map { it.cstr.ptr }.toCValues() // To skip upper part of screen.
autoreleasepool { Box(modifier = Modifier
UIApplicationMain(argc, argv, null, NSStringFromClass(SkikoAppDelegate)) .height(100.dp))
FallingBalls(game)
} }
} })
}
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") {
val game = remember { Game(UikitTime) }
Column {
// To skip upper part of screen.
Box(modifier = Modifier
.height(100.dp))
FallingBalls(game)
}
}
window!!.makeKeyAndVisible()
return true
}
} }

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

@ -16,7 +16,7 @@ buildscript {
plugins { plugins {
kotlin("multiplatform") version "1.7.10" 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" version = "1.0-SNAPSHOT"

45
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.graphics.painter.Painter
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Application import androidx.compose.ui.window.Application
import kotlinx.cinterop.* import androidx.compose.ui.main.defaultUIKitMain
import platform.UIKit.*
import platform.Foundation.*
fun main() { fun main() {
val args = emptyArray<String>() defaultUIKitMain("Minesweeper", Application("Minesweeper") {
memScoped { Column {
val argc = args.size + 1 // To skip upper part of screen.
val argv = (arrayOf("skikoApp") + args).map { it.cstr.ptr }.toCValues() Box(modifier = Modifier
autoreleasepool { .height(100.dp))
UIApplicationMain(argc, argv, null, NSStringFromClass(SkikoAppDelegate)) Game()
} }
} })
}
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") {
Column {
// To skip upper part of screen.
Box(modifier = Modifier
.height(100.dp))
Game()
}
}
window!!.makeKeyAndVisible()
return true
}
} }
@Composable @Composable

Loading…
Cancel
Save