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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ kotlin {
}
}

sourceSets.matching {
it.name == "watchosMain"
}.configureEach {
this.dependsOn(sourceSets.getByName("appleMain"))
}
val appleSourceSets = listOf("watchos", "tvos")
val appleMainSourceSets = appleSourceSets.map { "${it}Main" }
val appleTestSourceSets = appleSourceSets.map { "${it}Test" }

sourceSets
.matching { it.name in appleMainSourceSets }
.configureEach { this.dependsOn(sourceSets.getByName("appleMain")) }

sourceSets
.matching { it.name in appleTestSourceSets }
.configureEach { this.dependsOn(sourceSets.getByName("appleTest")) }
}
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,21 @@
/*
* 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.Foundation.NSBundle
import platform.UIKit.UIImage

actual data class ImageResource(
val assetImageName: String,
val bundle: NSBundle = NSBundle.mainBundle
) {
fun toUIImage(): UIImage? {
return UIImage.imageNamed(
name = assetImageName,
inBundle = bundle,
compatibleWithTraitCollection = null
)
}
}
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
}
}
13 changes: 13 additions & 0 deletions samples/resources-gallery/mpp-library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ allprojects {
jvm()
macosX64()
macosArm64()
tvosX64()
tvosArm64()
tvosSimulatorArm64()
js(IR) { browser() }

explicitApi()
Expand All @@ -37,6 +40,16 @@ allprojects {
val macosArm64Main by getting {
dependsOn(macosMain)
}

val tvosMain by creating {
dependsOn(commonMain.get())
}
val tvosX64Main by getting {
dependsOn(tvosMain)
}
val tvosArm64Main by getting {
dependsOn(tvosMain)
}
}
}
}
Expand Down
Loading