diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 5906d3b..6d5684b 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -98,7 +98,7 @@ kotlin { implementation(libs.favre.bcrypt) } - nativeMain.dependencies { + iosMain.dependencies { implementation(libs.sqldelight.native.driver) } diff --git a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/MainViewController.kt b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/MainViewController.kt index ab2542d..a6031a6 100644 --- a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/MainViewController.kt +++ b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/MainViewController.kt @@ -7,7 +7,7 @@ import net.codinux.banking.dataaccess.BankmeisterDb import net.codinux.banking.ui.config.DI fun MainViewController() = ComposeUIViewController { - DI.setRepository(NativeSqliteDriver(Database.Schema.synchronous(), "Bankmeister.db")) + DI.setRepository(NativeSqliteDriver(BankmeisterDb.Schema.synchronous(), "Bankmeister.db")) App() } \ No newline at end of file diff --git a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/Platform.ios.kt b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/Platform.ios.kt index 8c7bb91..4911a4e 100644 --- a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/Platform.ios.kt +++ b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/Platform.ios.kt @@ -1,6 +1,36 @@ package net.codinux.banking.ui +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.dp +import kotlinx.cinterop.ExperimentalForeignApi +import kotlinx.cinterop.useContents +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.IO +import platform.CoreGraphics.CGRect import platform.UIKit.UIDevice +import platform.UIKit.UIScreen + +actual val Dispatchers.IOorDefault: CoroutineDispatcher + get() = Dispatchers.IO + +@OptIn(ExperimentalForeignApi::class) +@Composable +actual fun rememberScreenSizeInfo(): ScreenSizeInfo { + val density = LocalDensity.current + val screenBounds: CGRect = UIScreen.mainScreen.bounds.useContents { this } + val screenWidth = screenBounds.size.width + val screenHeight = screenBounds.size.height + + return remember(density, screenWidth, screenHeight) { + ScreenSizeInfo( + heightDp = with(density) { screenHeight.dp }, + widthDp = with(density) { screenWidth.dp } + ) + } +} class IOSPlatform: Platform { override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion diff --git a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/service/ImageService.ios.kt b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/service/ImageService.ios.kt new file mode 100644 index 0000000..5bb6cff --- /dev/null +++ b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/service/ImageService.ios.kt @@ -0,0 +1,37 @@ +package net.codinux.banking.ui.service + +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.toComposeImageBitmap +import kotlinx.cinterop.ExperimentalForeignApi +import kotlinx.cinterop.readBytes +import org.jetbrains.skia.Image +import kotlinx.coroutines.suspendCancellableCoroutine +import platform.Foundation.* +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException + +actual fun createImageBitmap(imageBytes: ByteArray): ImageBitmap = + Image.makeFromEncoded(imageBytes).toComposeImageBitmap() + +@OptIn(ExperimentalForeignApi::class) +actual suspend fun fetchBytesFromUrl(url: String): ByteArray { + val nsUrl = NSURL(string = url) ?: throw IllegalArgumentException("Invalid URL") + + return suspendCancellableCoroutine { continuation -> + val request = NSURLRequest.requestWithURL(nsUrl) + val session = NSURLSession.sharedSession + val task = session.dataTaskWithRequest(request) { data, response, error -> + when { + error != null -> continuation.resumeWithException(Exception(error.localizedDescription)) + data != null -> continuation.resume(data.bytes!!.readBytes(data.length.toInt())) + else -> continuation.resumeWithException(Exception("Unknown error")) + } + } + + continuation.invokeOnCancellation { + task.cancel() // Cancel the task if the coroutine is cancelled + } + + task.resume() + } +} \ No newline at end of file