diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d22f66..15993be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog --- +## [2.0.20-Beta1-1.6.11-BETA-5] + +- Fixes EmptyFrameworkBaseNameException bug + +--- + ## [2.0.20-Beta1-1.6.11-BETA-4] - Adds experimental feature to import types from external modules. diff --git a/CHANGELOG_PLUGIN.md b/CHANGELOG_PLUGIN.md index 3af038f..204288a 100644 --- a/CHANGELOG_PLUGIN.md +++ b/CHANGELOG_PLUGIN.md @@ -3,8 +3,7 @@ ## [1.1.2] -- Compatible with 2.0.20-Beta1-1.6.11-BETA-4 - +- Compatible with 2.0.20-Beta1-1.6.11-BETA-5 --- diff --git a/build.gradle.kts b/build.gradle.kts index 0cf3200..bb23c9a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ buildscript { allprojects { group = "com.github.guilhe.kmp" - version = "2.0.20-Beta1-1.6.11-BETA-4" + version = "2.0.20-Beta1-1.6.11-BETA-5" } tasks.register("publishLibraryModules") { diff --git a/kmp-composeuiviewcontroller-common/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/common/Module.kt b/kmp-composeuiviewcontroller-common/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/common/ModuleMetadata.kt similarity index 68% rename from kmp-composeuiviewcontroller-common/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/common/Module.kt rename to kmp-composeuiviewcontroller-common/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/common/ModuleMetadata.kt index 35173e8..6222f59 100644 --- a/kmp-composeuiviewcontroller-common/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/common/Module.kt +++ b/kmp-composeuiviewcontroller-common/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/common/ModuleMetadata.kt @@ -3,7 +3,7 @@ package com.github.guilhe.kmp.composeuiviewcontroller.common import kotlinx.serialization.Serializable @Serializable -public data class Module(val name: String, val packageName: String, val frameworkBaseName: String) +public data class ModuleMetadata(val name: String, val packageName: Set, val frameworkBaseName: String) public const val TEMP_FILES_FOLDER: String = "composeuiviewcontroller" public const val FILE_NAME_ARGS: String = "modules.json" diff --git a/kmp-composeuiviewcontroller-gradle-plugin/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/gradle/KmpComposeUIViewControllerPlugin.kt b/kmp-composeuiviewcontroller-gradle-plugin/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/gradle/KmpComposeUIViewControllerPlugin.kt index 47f142f..7f2e8e5 100644 --- a/kmp-composeuiviewcontroller-gradle-plugin/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/gradle/KmpComposeUIViewControllerPlugin.kt +++ b/kmp-composeuiviewcontroller-gradle-plugin/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/gradle/KmpComposeUIViewControllerPlugin.kt @@ -1,7 +1,7 @@ package com.github.guilhe.kmp.composeuiviewcontroller.gradle import com.github.guilhe.kmp.composeuiviewcontroller.common.FILE_NAME_ARGS -import com.github.guilhe.kmp.composeuiviewcontroller.common.Module +import com.github.guilhe.kmp.composeuiviewcontroller.common.ModuleMetadata import com.github.guilhe.kmp.composeuiviewcontroller.common.TEMP_FILES_FOLDER import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -44,7 +44,7 @@ public class KmpComposeUIViewControllerPlugin : Plugin { finalizeFrameworkTasks(this) } afterEvaluate { - writeArgsToDisk(configureModuleJson(retrievePackage(), retrieveFrameworkBaseNames())) + writeModuleMetadataToDisk(configureFrameworkToPackage(retrieveModulePackageFromCommonMain(), retrieveFrameworkBaseNamesFromIosTargets())) } } } @@ -65,7 +65,7 @@ public class KmpComposeUIViewControllerPlugin : Plugin { } } - private fun Project.retrieveFrameworkBaseNames(): Set { + private fun Project.retrieveFrameworkBaseNamesFromIosTargets(): Set { val kmp = extensions.getByType(KotlinMultiplatformExtension::class.java) val frameworkNames = mutableSetOf() kmp.targets.configureEach { target -> @@ -78,59 +78,48 @@ public class KmpComposeUIViewControllerPlugin : Plugin { return frameworkNames } - private fun Project.retrievePackage(): String { + private fun Project.retrieveModulePackageFromCommonMain(): Set { val kmp = extensions.getByType(KotlinMultiplatformExtension::class.java) val commonMainSourceSet = kmp.sourceSets.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) - val srcDirs = commonMainSourceSet.kotlin.srcDirs - for (srcDir in srcDirs) { - srcDir.walkTopDown().forEach { file -> + val packages = mutableSetOf() + commonMainSourceSet.kotlin.srcDirs.forEach { dir -> + dir.walkTopDown().forEach { file -> if (file.isFile && file.extension == "kt") { - val relativePath = file.relativeTo(srcDir).parentFile?.path ?: "" + val relativePath = file.relativeTo(dir).parentFile?.path ?: "" val packagePath = relativePath.replace(File.separator, ".") if (packagePath.isNotEmpty()) { - return packagePath + packages.add(packagePath) } } } } - if (group.toString().isNotEmpty()) { - return group.toString() - } - throw IllegalStateException("Cloud not determine project's package nor group") + return packages.ifEmpty { throw GradleException("Cloud not determine project's package") } } - private fun Project.configureModuleJson(packageName: String, frameworkNames: Set): Map { - packageName.ifEmpty { return emptyMap() } + private fun Project.configureFrameworkToPackage(packageNames: Set, frameworkNames: Set): Map> { + packageNames.ifEmpty { return emptyMap() } frameworkNames.ifEmpty { return emptyMap() } - val args = mutableMapOf() val frameworkBaseName = frameworkNames.first() //let's assume for now all targets will have the same frameworkBaseName - val kotlin = extensions.getByType(KotlinMultiplatformExtension::class.java) - kotlin.targets.configureEach { target -> - if (target.fromIosFamily()) { - args[frameworkBaseName] = packageName + val map = mutableMapOf>() + extensions.getByType(KotlinMultiplatformExtension::class.java).run { + targets.configureEach { target -> + if (target.fromIosFamily()) { + map[frameworkBaseName] = packageNames + } } } - return args + return map } - private fun Project.writeArgsToDisk(args: Map) { + private fun Project.writeModuleMetadataToDisk(args: Map>) { val file = rootProject.layout.buildDirectory.file("$TEMP_FILES_FOLDER/$FILE_NAME_ARGS").get().asFile - val modules = try { - Json.decodeFromString>(file.readText()) + val moduleMetadata = try { + Json.decodeFromString>(file.readText()) } catch (e: Exception) { mutableSetOf() } - args.forEach { (key, value) -> modules.add(Module(name = name.toString(), packageName = value, frameworkBaseName = key)) } - file.writeText(Json.encodeToString(modules)) - } - - private fun Project.finalizeFrameworkTasks(extensionParameters: ComposeUiViewControllerParameters) { - tasks.matching { it.name == TASK_EMBED_AND_SING_APPLE_FRAMEWORK_FOR_XCODE || it.name == TASK_SYNC_FRAMEWORK }.configureEach { task -> - if (extensionParameters.autoExport) { - println("\n> $LOG_TAG:\n\t> ${task.name}will be finalizedBy $TASK_COPY_FILES_TO_XCODE task") - task.finalizedBy(TASK_COPY_FILES_TO_XCODE) - } - } + args.forEach { (key, value) -> moduleMetadata.add(ModuleMetadata(name = name.toString(), packageName = value, frameworkBaseName = key)) } + file.writeText(Json.encodeToString(moduleMetadata)) } private fun Project.registerCopyFilesToXcodeTask(project: Project, extensionParameters: ComposeUiViewControllerParameters) { @@ -176,8 +165,17 @@ public class KmpComposeUIViewControllerPlugin : Plugin { } } + private fun Project.finalizeFrameworkTasks(extensionParameters: ComposeUiViewControllerParameters) { + tasks.matching { it.name == TASK_EMBED_AND_SING_APPLE_FRAMEWORK_FOR_XCODE || it.name == TASK_SYNC_FRAMEWORK }.configureEach { task -> + if (extensionParameters.autoExport) { + println("\n> $LOG_TAG:\n\t> ${task.name}will be finalizedBy $TASK_COPY_FILES_TO_XCODE task") + task.finalizedBy(TASK_COPY_FILES_TO_XCODE) + } + } + } + internal companion object { - private const val VERSION_LIBRARY = "2.0.20-Beta1-1.6.11-BETA-4" + private const val VERSION_LIBRARY = "2.0.20-Beta1-1.6.11-BETA-5" private const val LOG_TAG = "KmpComposeUIViewControllerPlugin" internal const val PLUGIN_KMP = "org.jetbrains.kotlin.multiplatform" internal const val PLUGIN_KSP = "com.google.devtools.ksp" diff --git a/kmp-composeuiviewcontroller-gradle-plugin/src/main/resources/exportToXcode.sh b/kmp-composeuiviewcontroller-gradle-plugin/src/main/resources/exportToXcode.sh index cc74e99..dac5dcb 100755 --- a/kmp-composeuiviewcontroller-gradle-plugin/src/main/resources/exportToXcode.sh +++ b/kmp-composeuiviewcontroller-gradle-plugin/src/main/resources/exportToXcode.sh @@ -83,6 +83,7 @@ copy_files "$files_source" "$files_destination" if [ "$copied_count" -gt 0 ]; then echo "> Checking for new references to be added to xcodeproj" cd .. + cd .. cd $iosApp_project_folder || exit add_file_references "$xcodeproj_path" "$iosApp_target_name" "$group_name" echo "> Done" diff --git a/kmp-composeuiviewcontroller-gradle-plugin/src/test/kotlin/composeuiviewcontroller/PluginTest.kt b/kmp-composeuiviewcontroller-gradle-plugin/src/test/kotlin/composeuiviewcontroller/PluginTest.kt index 73ae784..ec17b57 100644 --- a/kmp-composeuiviewcontroller-gradle-plugin/src/test/kotlin/composeuiviewcontroller/PluginTest.kt +++ b/kmp-composeuiviewcontroller-gradle-plugin/src/test/kotlin/composeuiviewcontroller/PluginTest.kt @@ -1,7 +1,7 @@ package composeuiviewcontroller import com.github.guilhe.kmp.composeuiviewcontroller.common.FILE_NAME_ARGS -import com.github.guilhe.kmp.composeuiviewcontroller.common.Module +import com.github.guilhe.kmp.composeuiviewcontroller.common.ModuleMetadata import com.github.guilhe.kmp.composeuiviewcontroller.common.TEMP_FILES_FOLDER import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.ERROR_MISSING_KMP @@ -120,11 +120,20 @@ class PluginTest { fun `Method configureModuleJson creates and saves in disk modules metadata`() { with(project) { extensions.getByType(KotlinMultiplatformExtension::class.java).apply { - group = "com.composables.module" jvm() iosSimulatorArm64().binaries.framework { baseName = "ComposablesFramework" } } + val folder = File(projectDir.path, "src/commonMain/kotlin/com/composables/module").apply { mkdirs() } + val classFile = File(folder, "File.kt") + classFile.writeText( + """ + com.composables.module + class Test() + """.trimIndent() + ) + assertTrue(classFile.exists()) + println("> $state") (this as DefaultProject).evaluate() println("> $state") @@ -132,9 +141,9 @@ class PluginTest { val file = rootProject.layout.buildDirectory.file("$TEMP_FILES_FOLDER/$FILE_NAME_ARGS").get().asFile assertTrue(file.exists()) - val module = Json.decodeFromString>(file.readText()).first() - assertTrue(module.frameworkBaseName == "ComposablesFramework") - assertTrue(module.packageName == "com.composables.module") + val moduleMetadata = Json.decodeFromString>(file.readText()).first() + assertTrue(moduleMetadata.frameworkBaseName == "ComposablesFramework") + assertTrue(moduleMetadata.packageName.contains("com.composables.module")) } } @@ -151,6 +160,16 @@ class PluginTest { @Test fun `Task CopyFilesToXcode will inject the extension parameters into exportToXcode file`(@TempDir tempDir: File) { projectDir = File(tempDir, "testProject").apply { mkdirs() } + val folder = File(projectDir.path, "src/commonMain/kotlin/com/test").apply { mkdirs() } + val classFile = File(folder, "File.kt") + classFile.writeText( + """ + package com.test + class Test() + """.trimIndent() + ) + assertTrue(classFile.exists()) + val buildFile = File(projectDir, "build.gradle.kts") buildFile.writeText( """ @@ -167,10 +186,9 @@ class PluginTest { exportFolderName = "Composables" autoExport = true } - - group = "com.test" """.trimIndent() ) + assertTrue(buildFile.exists()) val result = GradleRunner.create() .withProjectDir(projectDir) diff --git a/kmp-composeuiviewcontroller-ksp/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/ksp/Processor.kt b/kmp-composeuiviewcontroller-ksp/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/ksp/Processor.kt index 39474a2..6a3a00f 100644 --- a/kmp-composeuiviewcontroller-ksp/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/ksp/Processor.kt +++ b/kmp-composeuiviewcontroller-ksp/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/ksp/Processor.kt @@ -1,7 +1,9 @@ +@file:Suppress("RedundantVisibilityModifier") + package com.github.guilhe.kmp.composeuiviewcontroller.ksp import com.github.guilhe.kmp.composeuiviewcontroller.common.FILE_NAME_ARGS -import com.github.guilhe.kmp.composeuiviewcontroller.common.Module +import com.github.guilhe.kmp.composeuiviewcontroller.common.ModuleMetadata import com.github.guilhe.kmp.composeuiviewcontroller.common.TEMP_FILES_FOLDER import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.CodeGenerator @@ -55,30 +57,26 @@ internal class Processor( .also { if (parameters.size != it.size + 1) throw InvalidParametersException() } } val packageName = file.packageName.asString() - val imports = extractImportsFromExternalPackages(packageName, makeParameters, parameters) - val modules = getFrameworkMetadataFromJson() - val externalModuleTypes = buildExternalModuleParameters(modules, imports) + val externalImports = extractImportsFromExternalPackages(packageName, makeParameters, parameters) + val modulesMetadata = getFrameworkMetadataFromDisk() + val externalModuleTypes = buildExternalModuleParameters(modulesMetadata, externalImports) +// val frameworkBaseNames = getFrameworkBaseNames(composable, node, makeParameters, parameters) + val currentFramework = trimFrameworkBaseNames(node, modulesMetadata, packageName) if (stateParameter == null) { - createKotlinFileWithoutState(packageName, imports, composable, makeParameters, parameters).also { + createKotlinFileWithoutState(packageName, externalImports, composable, makeParameters, parameters).also { logger.info("${composable.name()}UIViewController created!") } - -// val frameworkBaseNames = getFrameworkBaseNames(composable, node, makeParameters, parameters) - val currentFramework = trimFrameworkBaseNames(node, packageName) createSwiftFileWithoutState(listOf(currentFramework), composable, makeParameters, externalModuleTypes).also { logger.info("${composable.name()}Representable created!") } } else { val stateParameterName = stateParameter.name() createKotlinFileWithState( - packageName, imports, composable, stateParameterName, stateParameter, makeParameters, parameters + packageName, externalImports, composable, stateParameterName, stateParameter, makeParameters, parameters ).also { logger.info("${composable.name()}UIViewController created!") } - -// val frameworkBaseNames = getFrameworkBaseNames(composable, node, makeParameters, parameters) - val currentFramework = trimFrameworkBaseNames(node, packageName) createSwiftFileWithState( listOf(currentFramework), composable, stateParameterName, stateParameter, makeParameters, externalModuleTypes ).also { @@ -104,14 +102,14 @@ internal class Processor( return stateParameters } - private fun getFrameworkMetadataFromJson(): List { + private fun getFrameworkMetadataFromDisk(): List { val file = File("./build/$TEMP_FILES_FOLDER/$FILE_NAME_ARGS") - val modules = try { - Json.decodeFromString>(file.readText()) + val moduleMetadata = try { + Json.decodeFromString>(file.readText()) } catch (e: Exception) { throw ModuleDecodeException() } - return modules + return moduleMetadata } /** @@ -137,13 +135,13 @@ internal class Processor( * * [https://stackoverflow.com/a/78707072/1423773](https://stackoverflow.com/a/78707072/1423773) */ - private fun buildExternalModuleParameters(modules: List, imports: List): MutableMap { + private fun buildExternalModuleParameters(moduleMetadata: List, imports: List): MutableMap { val result = mutableMapOf() imports.forEach { it -> val type = it.split(".").last() val import = it.split(".$type").first() - modules - .filter { module -> module.packageName == import } + moduleMetadata + .filter { module -> module.packageName.contains(import) } .forEach { module -> val capitalized = module.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } val replaced = capitalized.replace("-", "_") @@ -154,16 +152,14 @@ internal class Processor( } /** - * This will be needed until [buildExternalModuleParameters] is needed to. When (if) KPM limitation is addressed this will become deprecated and substituted by [getFrameworkBaseNames] + * This will be needed until [buildExternalModuleParameters] is needed too. When (if) KPM limitation is addressed this will become deprecated and substituted by [getFrameworkBaseNames] */ - private fun trimFrameworkBaseNames(node: KSAnnotated, packageName: String): String { - val metadata = getFrameworkMetadataFromJson() - if (metadata.isEmpty()) { + private fun trimFrameworkBaseNames(node: KSAnnotated, moduleMetadata: List, packageName: String): String { + if (moduleMetadata.isEmpty()) { val framework = getFrameworkBaseNameFromAnnotation(node) ?: throw EmptyFrameworkBaseNameException() return framework } else { - val framework = - metadata.firstOrNull { it.packageName == packageName }?.frameworkBaseName?: "" + val framework = moduleMetadata.firstOrNull { it.packageName.contains(packageName) }?.frameworkBaseName ?: "" framework.ifEmpty { return getFrameworkBaseNameFromAnnotation(node) ?: throw EmptyFrameworkBaseNameException() } return framework } @@ -180,7 +176,7 @@ internal class Processor( frameworkBaseNames.addAll( extractFrameworkBaseNames( composable, - getFrameworkMetadataFromJson(), + getFrameworkMetadataFromDisk(), makeParameters, parameters, stateParameter diff --git a/kmp-composeuiviewcontroller-ksp/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/ksp/Utils.kt b/kmp-composeuiviewcontroller-ksp/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/ksp/Utils.kt index 19f52c1..6e87301 100644 --- a/kmp-composeuiviewcontroller-ksp/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/ksp/Utils.kt +++ b/kmp-composeuiviewcontroller-ksp/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/ksp/Utils.kt @@ -1,9 +1,8 @@ package com.github.guilhe.kmp.composeuiviewcontroller.ksp import com.github.guilhe.kmp.composeuiviewcontroller.common.FILE_NAME_ARGS -import com.github.guilhe.kmp.composeuiviewcontroller.common.Module +import com.github.guilhe.kmp.composeuiviewcontroller.common.ModuleMetadata import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.KSFile import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSTypeReference import com.google.devtools.ksp.symbol.KSValueParameter @@ -89,7 +88,7 @@ internal fun extractImportsFromExternalPackages( internal fun extractFrameworkBaseNames( composable: KSFunctionDeclaration, - modules: List, + moduleMetadata: List, makeParameters: List, parameters: List, stateParameter: KSValueParameter? = null @@ -112,9 +111,9 @@ internal fun extractFrameworkBaseNames( parameterPackages.add(composable.packageName.asString()) - return parameterPackages.mapNotNull { pkg -> - modules.find { it.packageName == pkg }?.frameworkBaseName - }.distinct() + return parameterPackages + .mapNotNull { pkg -> moduleMetadata.find { it.packageName.contains(pkg) }?.frameworkBaseName } + .distinct() } internal fun String.name() = split(".").last() diff --git a/kmp-composeuiviewcontroller-ksp/src/test/kotlin/composeuiviewcontroller/ProcessorTest.kt b/kmp-composeuiviewcontroller-ksp/src/test/kotlin/composeuiviewcontroller/ProcessorTest.kt index 868a384..b36a6c2 100644 --- a/kmp-composeuiviewcontroller-ksp/src/test/kotlin/composeuiviewcontroller/ProcessorTest.kt +++ b/kmp-composeuiviewcontroller-ksp/src/test/kotlin/composeuiviewcontroller/ProcessorTest.kt @@ -93,7 +93,7 @@ class ProcessorTest { """.trimIndent() val compilation = prepareCompilation(kotlin("Screen.kt", code)) - tempArgs.writeText("""[{"name":"module-test","packageName":"com.mycomposable.test","frameworkBaseName":"MyFramework"}]""") + tempArgs.writeText("""[{"name":"module-test","packageName":["com.mycomposable.test"],"frameworkBaseName":"MyFramework"}]""") val result = compilation.compile() assertEquals(result.exitCode, KotlinCompilation.ExitCode.OK) @@ -118,7 +118,7 @@ class ProcessorTest { """.trimIndent() val compilation = prepareCompilation(kotlin("Screen.kt", code)) - tempArgs.writeText("""[{"name":"module-test","packageName":"com.mycomposable.test","frameworkBaseName":""}]""") + tempArgs.writeText("""[{"name":"module-test","packageName":["com.mycomposable.test"],"frameworkBaseName":""}]""") val result = compilation.compile() assertEquals(result.exitCode, KotlinCompilation.ExitCode.OK) @@ -510,8 +510,8 @@ class ProcessorTest { tempArgs.writeText( """ [ - {"name":"module-test","packageName":"com.mycomposable.test","frameworkBaseName":"MyFramework"}, - {"name":"module-data","packageName":"com.mycomposable.data","frameworkBaseName":"MyFramework2"} + {"name":"module-test","packageName":["com.mycomposable.test"],"frameworkBaseName":"MyFramework"}, + {"name":"module-data","packageName":["com.mycomposable.data"],"frameworkBaseName":"MyFramework2"} ] """.trimIndent() ) diff --git a/sample/iosApp/Representables/GradientScreen2UIViewControllerRepresentable.swift b/sample/iosApp/Representables/GradientScreen2UIViewControllerRepresentable.swift new file mode 100644 index 0000000..2051d19 --- /dev/null +++ b/sample/iosApp/Representables/GradientScreen2UIViewControllerRepresentable.swift @@ -0,0 +1,13 @@ +import SwiftUI +import Composables + +public struct GradientScreen2Representable: UIViewControllerRepresentable { + + public func makeUIViewController(context: Context) -> UIViewController { + GradientScreen2UIViewController().make() + } + + public func updateUIViewController(_ uiViewController: UIViewController, context: Context) { + //unused + } +} \ No newline at end of file diff --git a/sample/iosApp/Representables/TestScreenUIViewControllerRepresentable.swift b/sample/iosApp/Representables/TestScreenUIViewControllerRepresentable.swift new file mode 100644 index 0000000..d424b00 --- /dev/null +++ b/sample/iosApp/Representables/TestScreenUIViewControllerRepresentable.swift @@ -0,0 +1,14 @@ +import SwiftUI +import Composables + +public struct TestScreenRepresentable: UIViewControllerRepresentable { + let state: Shared_modelsDummyExternal + + public func makeUIViewController(context: Context) -> UIViewController { + TestScreenUIViewController().make(state: state) + } + + public func updateUIViewController(_ uiViewController: UIViewController, context: Context) { + //unused + } +} \ No newline at end of file diff --git a/sample/shared-models/src/commonMain/kotlin/com/sample/models/dummy/DummyExternal.kt b/sample/shared-models/src/commonMain/kotlin/com/sample/models/dummy/DummyExternal.kt new file mode 100644 index 0000000..2a9d90e --- /dev/null +++ b/sample/shared-models/src/commonMain/kotlin/com/sample/models/dummy/DummyExternal.kt @@ -0,0 +1,3 @@ +package com.sample.models.dummy + +data class DummyExternal(val name: String) \ No newline at end of file diff --git a/sample/shared/src/commonMain/kotlin/com/sample/shared/dummy/Dummy.kt b/sample/shared/src/commonMain/kotlin/com/sample/shared/dummy/Dummy.kt new file mode 100644 index 0000000..2421df6 --- /dev/null +++ b/sample/shared/src/commonMain/kotlin/com/sample/shared/dummy/Dummy.kt @@ -0,0 +1,4 @@ +package com.sample.shared.dummy + +class Dummy { +} \ No newline at end of file diff --git a/sample/shared/src/iosMain/kotlin/com/sample/shared/Screens.kt b/sample/shared/src/iosMain/kotlin/com/sample/shared/Screens.kt index 2e3faf1..7c08feb 100644 --- a/sample/shared/src/iosMain/kotlin/com/sample/shared/Screens.kt +++ b/sample/shared/src/iosMain/kotlin/com/sample/shared/Screens.kt @@ -11,7 +11,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.graphics.Color import com.github.guilhe.kmp.composeuiviewcontroller.ComposeUIViewController import com.github.guilhe.kmp.composeuiviewcontroller.ComposeUIViewControllerState -import com.sample.models.ScreenStateExternal import platform.Foundation.NSDate import platform.Foundation.timeIntervalSince1970 @@ -19,6 +18,8 @@ data class ScreenState(val startColor: Long, val endColor: Long) { val colors: List = listOf(Color(startColor), Color(endColor)) } +private fun getCurrentMillis(): Long = NSDate().timeIntervalSince1970.toLong() * 1000 + @ComposeUIViewController @Composable internal fun GradientScreen(@ComposeUIViewControllerState state: ScreenState, randomize: (Long) -> Unit) { @@ -30,6 +31,4 @@ internal fun GradientScreen(@ComposeUIViewControllerState state: ScreenState, ra Text(text = "Shuffle") } } -} - -private fun getCurrentMillis(): Long = NSDate().timeIntervalSince1970.toLong() * 1000 +} \ No newline at end of file diff --git a/sample/shared/src/iosMain/kotlin/com/sample/shared/dummy/Screens.kt b/sample/shared/src/iosMain/kotlin/com/sample/shared/dummy/Screens.kt new file mode 100644 index 0000000..5d21601 --- /dev/null +++ b/sample/shared/src/iosMain/kotlin/com/sample/shared/dummy/Screens.kt @@ -0,0 +1,11 @@ +@file:Suppress("unused") + +package com.sample.shared.dummy + +import androidx.compose.runtime.Composable +import com.github.guilhe.kmp.composeuiviewcontroller.ComposeUIViewController +import com.sample.models.dummy.DummyExternal + +@ComposeUIViewController +@Composable +internal fun TestScreen(state: DummyExternal) {}