Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tvOS support #745

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ kotlin {
}.configureEach {
this.dependsOn(sourceSets.getByName("appleMain"))
}

sourceSets.matching {
it.name == "tvosMain"
}.configureEach {
this.dependsOn(sourceSets.getByName("appleMain"))
}
Alex009 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ kotlin {
watchosArm64()
watchosSimulatorArm64()

tvosX64()
tvosArm64()
tvosSimulatorArm64()

sourceSets {
val commonMain by getting

Expand All @@ -30,6 +34,19 @@ kotlin {
val watchosSimulatorArm64Main by getting{
dependsOn(watchosMain)
}

val tvosMain by creating {
dependsOn(commonMain)
}
val tvosX64Main by getting {
dependsOn(tvosMain)
}
val tvosArm64Main by getting {
dependsOn(tvosMain)
}
val tvosSimulatorArm64Main by getting {
dependsOn(tvosMain)
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.resources.test

import dev.icerock.moko.resources.FontResource
import dev.icerock.moko.resources.ImageResource

actual fun createImageResourceMock(): ImageResource = ImageResource("")
actual fun createFontResourceMock(): FontResource = FontResource("")
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.resources

import kotlinx.cinterop.CPointer
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.cinterop.UnsafeNumber
import platform.Foundation.NSError
import platform.Foundation.NSString
import platform.Foundation.NSUTF8StringEncoding
import platform.Foundation.stringWithContentsOfFile

@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
internal actual fun readContentOfFile(
filePath: String,
error: CPointer<ObjCObjectVar<NSError?>>?,
): String? {
return NSString.stringWithContentsOfFile(
path = filePath,
encoding = NSUTF8StringEncoding,
error = error
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.resources

import platform.UIKit.UIImage

actual class ImageResource(val assetImageName: String) {
fun toUIImage(): UIImage? {
return UIImage.imageNamed(name = assetImageName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.resources

actual fun ResourceContainer<ImageResource>.getImageByFileName(fileName: String): ImageResource? {
return ImageResource(fileName).let { imgRes ->
if (imgRes.toUIImage() != null) imgRes else null
}
}
Loading