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

Component generator #65

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b13baa6
Move old util module to submodule tools
RudolfHladik Apr 8, 2024
66c5eee
Update ComponentProcessor
RudolfHladik Apr 9, 2024
415f6c2
Revert usage of generated components yet
RudolfHladik Apr 9, 2024
31b8d40
update init script with new modules
RudolfHladik Apr 9, 2024
bf31c4e
Merge branch 'main' into feature/component-generator
RudolfHladik Jun 3, 2024
b31678c
Use generated component with LoginScreen
RudolfHladik Jun 3, 2024
8e829b4
Merge branch 'main' into feature/component-generator
RudolfHladik Jun 12, 2024
bbb3d7d
Merge remote-tracking branch 'origin/develop' into feature/component-…
RudolfHladik Jun 12, 2024
f5490fd
Update FirstEvent name in iOS
RudolfHladik Jun 12, 2024
b9ddb41
Update .gitignore
RudolfHladik Jun 12, 2024
edb16fe
Add support for Kotlin 2.0.0
RudolfHladik Jun 12, 2024
cfa004f
Fix typo in .gitignore
RudolfHladik Jun 13, 2024
47955c9
Update .gitignore
RudolfHladik Jun 17, 2024
418c3ab
Enable compose compiler for feature module
RudolfHladik Jun 17, 2024
b4c6c91
Bump decompose
RudolfHladik Jun 17, 2024
f5b31cd
Merge remote-tracking branch 'origin/feature/K2' into feature/K2
RudolfHladik Jun 17, 2024
6819489
Merge pull request #78 from futuredapp/feature/K2
RudolfHladik Jun 17, 2024
7861ca1
Merge pull request #79 from futuredapp/develop
Syntey Jun 19, 2024
9aaca50
Merge branch 'refs/heads/main' into feature/component-generator
RudolfHladik Oct 4, 2024
e0f5bd2
Get type for VM, ViewState in poet
RudolfHladik Oct 4, 2024
2eabea2
Merge branch 'refs/heads/develop' into feature/component-generator
RudolfHladik Oct 4, 2024
81379a5
Update gradle-wrapper.properties
RudolfHladik Oct 4, 2024
359511f
merge
RudolfHladik Oct 4, 2024
ff39892
add argument type
RudolfHladik Oct 4, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.iml
.gradle
.idea
.kotlin
.fleet
.DS_Store
build
captures
Expand Down
11 changes: 4 additions & 7 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ plugins {
id(libs.plugins.com.android.application.get().pluginId)
id(libs.plugins.kotlin.android.get().pluginId)
id(libs.plugins.conventions.lint.get().pluginId)

alias(libs.plugins.androidx.baselineprofile)
alias(libs.plugins.compose.compiler)
}

kotlin {
Expand All @@ -30,11 +32,6 @@ android {
buildConfig = true
}

composeOptions {

kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}

packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
Expand Down Expand Up @@ -92,7 +89,7 @@ android {
}

kotlinOptions {
jvmTarget = ProjectSettings.Android.KotlinJvmTarget
jvmTarget = ProjectSettings.Android.KotlinJvmTargetNum
}
}

Expand All @@ -103,7 +100,7 @@ dependencies {
implementation(projects.shared.app)
implementation(projects.shared.feature)
implementation(projects.shared.platform)
implementation(projects.shared.util)
implementation(projects.shared.util.tools)
implementation(projects.shared.resources)

implementation(platform(libs.androidx.compose.bom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.futured.kmptemplate.android.tools.arch

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import app.futured.kmptemplate.util.arch.UiEvent
import app.futured.kmptemplate.util.arch.Event
import kotlinx.coroutines.flow.Flow

/**
Expand All @@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.Flow
* @param observer Event receiver lambda.
*/
@Composable
inline fun <reified E : UiEvent<*>> EventsEffect(
inline fun <reified E : Event<*>> EventsEffect(
eventsFlow: Flow<E>,
crossinline observer: suspend E.() -> Unit,
) {
Expand All @@ -35,7 +35,7 @@ inline fun <reified E : UiEvent<*>> EventsEffect(
}
}

inline fun <reified E : UiEvent<*>> UiEvent<*>.onEvent(action: (E) -> Unit) {
inline fun <reified E : Event<*>> Event<*>.onEvent(action: (E) -> Unit) {
if (this is E) {
action(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import app.futured.kmptemplate.android.MyApplicationTheme
import app.futured.kmptemplate.android.tools.arch.EventsEffect
import app.futured.kmptemplate.android.tools.arch.onEvent
import app.futured.kmptemplate.feature.ui.first.FirstScreen
import app.futured.kmptemplate.feature.ui.first.FirstUiEvent
import app.futured.kmptemplate.feature.ui.first.FirstEvent
import app.futured.kmptemplate.feature.ui.first.FirstViewState
import app.futured.kmptemplate.resources.MR
import app.futured.kmptemplate.resources.kmpStringResource
Expand All @@ -51,7 +51,7 @@ fun FirstScreenUi(
Content(viewState = viewState, actions = actions, modifier = modifier)

EventsEffect(eventsFlow = screen.events) {
onEvent<FirstUiEvent.ShowToast> { event ->
onEvent<FirstEvent.ShowToast> { event ->
Toast.makeText(context, event.text, Toast.LENGTH_SHORT).show()
}
}
Expand Down
2 changes: 1 addition & 1 deletion baselineprofile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
}

kotlinOptions {
jvmTarget = ProjectSettings.Android.KotlinJvmTarget
jvmTarget = ProjectSettings.Android.KotlinJvmTargetNum
}

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.futured.kmptemplate.gradle.configuration

import org.gradle.api.JavaVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

object ProjectSettings {

Expand All @@ -23,7 +24,8 @@ object ProjectSettings {
val VersionName = System.getenv("VERSION_NAME") ?: "1.0.0"

val JavaCompatibility = JavaVersion.VERSION_11
const val KotlinJvmTarget = "11"
val KotlinJvmTarget = JvmTarget.JVM_11
const val KotlinJvmTargetNum = "11"

object BuildTypes {
const val Debug = "debug"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package app.futured.kmptemplate.gradle.ext

import org.jetbrains.kotlin.gradle.dsl.KotlinTargetContainerWithNativeShortcuts
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

/**
* Configures supported native iOS targets all at once.
*/
fun KotlinTargetContainerWithNativeShortcuts.iosTargets(
fun KotlinMultiplatformExtension.iosTargets(
targets: List<KotlinNativeTarget> = listOf(
iosX64(),
iosArm64(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ ksp {
arg("KOIN_CONFIG_CHECK","false")
// disable default module generation
arg("KOIN_DEFAULT_MODULE","false")

// setup for component processor
arg("viewModel", "app.futured.kmptemplate.util.arch.ViewModelComponent")
arg("viewModelExt", "app.futured.kmptemplate.util.ext.viewModel")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this configuration actually relate to Koin, or is it just a shortcut to configure KSP for different thing?

}

// https://github.com/gradle/gradle/issues/15383
val libs = the<LibrariesForLibs>()
// Enable source generation by KSP to commonMain only
dependencies {
add("kspCommonMainMetadata", libs.koin.ksp.compiler)
add("kspCommonMainMetadata", project(":shared:util:component-processor"))
// DO NOT add bellow dependencies
// add("kspAndroid", Deps.Koin.kspCompiler)
// add("kspIosX64", Deps.Koin.kspCompiler)
Expand Down
26 changes: 19 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[versions]
agp = "8.4.1"
kotlin = "1.9.24"
ksp = "1.9.24-1.0.20" # Must be compatible with: `kotlin`
# https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#version-compatibility
agp = "8.3.0"
kotlin = "2.0.0"
ksp = "2.0.0-1.0.21" # Must be compatible with: `kotlin`
desugarLibs = "1.1.5"
androidxComposeBom = "2024.01.00"
androidxActivity = "1.7.2"
composeCompiler = "1.5.14" # Must be compatible with: `kotlin`
decompose = "3.0.0"
essenty = "2.0.0"
decompose = "3.1.0"
essenty = "2.1.0"
koin = "3.5.6"
koinAnnotations = "1.3.1" # Must be compatible with: `ksp`
kotlinx-coroutines = "1.8.1"
Expand All @@ -17,14 +18,16 @@ ktlint = "1.2.1"
detektGradlePlugin = "1.23.6"
composeLint = "1.3.1"
apollo = "3.8.2"
ktorfit = "1.14.0" # Must be compatible with: `ksp`
ktorfit = "2.0.0" # Must be compatible with: `ksp`
ktorfitConverter = "2.0.0"
ktor = "2.3.11" # Must be compatible with: `ktorfit`
kotlinx-serialization = "1.6.2"
kotlinx-serialization = "1.6.3"
timber = "5.0.1"
kermit = "2.0.2"
skie = "0.8.2" # Must be compatible with: `kotlin`
buildkonfig = "0.15.1"
nsExceptionKt = "0.1.15"
poet = "1.15.0"
datastore = "1.1.1"
moko-resources = "0.24.0"
baselineProfile = "1.2.4"
Expand All @@ -33,6 +36,7 @@ espressoCore = "3.5.1"
uiautomator = "2.3.0"
benchmarkMacroJunit4 = "1.2.4"
profileinstaller = "1.3.1"
composeRuntime = "1.6.2"

# Android Namespaces
project-android-namespace = "app.futured.kmptemplate.android"
Expand All @@ -59,6 +63,7 @@ androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-toolin
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime" }
jetbrains-compose-runtime = { group = "org.jetbrains.compose.runtime", name = "runtime" , version.ref = "composeRuntime"}

# Koin
#koin-bom = { group = "io.insert-koin", name = "koin-bom", version.ref = "koin" }
Expand Down Expand Up @@ -114,13 +119,18 @@ network-apollo-normalizedCache-core = { group = "com.apollographql.apollo3", nam
network-apollo-normalizedCache-sqlite = { group = "com.apollographql.apollo3", name = "apollo-normalized-cache-sqlite", version.ref = "apollo" }
network-ktorfit-ksp = { group = "de.jensklingenberg.ktorfit", name = "ktorfit-ksp", version.ref = "ktorfit" }
network-ktorfit-lib = { group = "de.jensklingenberg.ktorfit", name = "ktorfit-lib", version.ref = "ktorfit" }
network-ktorfit-converters = { group = "de.jensklingenberg.ktorfit", name = "ktorfit-converters-response", version.ref = "ktorfitConverter" }
network-ktor-client-serialization = { group = "io.ktor", name = "ktor-client-serialization", version.ref = "ktor" }
network-ktor-client-contentNegotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
network-ktor-client-logging = { group = "io.ktor", name = "ktor-client-logging", version.ref = "ktor" }
network-ktor-client-engine-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
network-ktor-client-engine-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
network-ktor-serialization-kotlinx-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }

# KSP api
ksp-lib = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp"}
poet-interop = { module = "com.squareup:kotlinpoet-ksp", version.ref = "poet"}

# Datastore
androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences-core", version.ref = "datastore" }

Expand All @@ -134,6 +144,7 @@ gradlePlugin-ksp = { group = "com.google.devtools.ksp", name = "com.google.devto
[plugins]
com-android-application = { id = "com.android.application", version.ref = "agp" }
com-android-library = { id = "com.android.library", version.ref = "agp" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
Expand Down Expand Up @@ -167,6 +178,7 @@ apollo = [

ktorfit = [
"network-ktorfit-lib",
"network-ktorfit-converters",
"network-ktor-client-contentNegotiation",
"network-ktor-client-serialization",
"network-ktor-client-logging",
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
# https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#version-compatibility
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 3 additions & 1 deletion init_template.kts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ fun renamePackagesInShared(packageName: String) {
"persistence",
"platform",
"resources",
"util",
"util/tools",
"util/component-annotation",
"util/component-processor",
)
modules.forEach { moduleName ->
sourceSets.forEach { targetName ->
Expand Down
8 changes: 4 additions & 4 deletions iosApp/iosApp/Views/Screen/First/FirstViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import SwiftUI

protocol FirstViewModelProtocol: DynamicProperty {
var text: String { get }
var events: SkieSwiftFlow<FirstUiEvent> { get }
var events: SkieSwiftFlow<FirstEvent> { get }
var isAlertVisible: Binding<Bool> { get }
var alertText: String { get }

func onNext()
func onBack()
func showToast(event: FirstUiEvent.ShowToast)
func showToast(event: FirstEvent.ShowToast)
func hideToast()
}

struct FirstViewModel {
@StateObject @KotlinStateFlow private var viewState: FirstViewState
private let actions: FirstScreenActions
let events: SkieSwiftFlow<FirstUiEvent>
let events: SkieSwiftFlow<FirstEvent>

@State private var alertVisible: Bool = false
@State private(set) var alertText: String = ""
Expand Down Expand Up @@ -48,7 +48,7 @@ extension FirstViewModel: FirstViewModelProtocol {
actions.onBack()
}

func showToast(event: FirstUiEvent.ShowToast) {
func showToast(event: FirstEvent.ShowToast) {
alertText = event.text
alertVisible = true
}
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ include(":shared:network:rest")
include(":shared:feature")
include(":shared:persistence")
include(":shared:platform")
include(":shared:util")
include(":shared:util:tools")
include(":shared:util:component-annotation")
include(":shared:util:component-processor")
include(":shared:resources")

includeBuild("convention-plugins")
Expand Down
15 changes: 9 additions & 6 deletions shared/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)

import app.futured.kmptemplate.gradle.configuration.ProjectSettings
import app.futured.kmptemplate.gradle.ext.iosTargets
import co.touchlab.skie.configuration.DefaultArgumentInterop
import co.touchlab.skie.configuration.EnumInterop
import co.touchlab.skie.configuration.FlowInterop
import co.touchlab.skie.configuration.SealedInterop
import co.touchlab.skie.configuration.SuppressSkieWarning
import co.touchlab.skie.configuration.SuspendInterop
import dev.icerock.gradle.MRVisibility
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
id(libs.plugins.com.android.library.get().pluginId)
Expand All @@ -22,10 +26,8 @@ kotlin {
applyDefaultHierarchyTemplate()

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = ProjectSettings.Android.KotlinJvmTarget
}
compilerOptions {
jvmTarget.set(ProjectSettings.Android.KotlinJvmTarget)
}
}

Expand All @@ -36,7 +38,7 @@ kotlin {
isStatic = true

export(projects.shared.platform)
export(projects.shared.util)
export(projects.shared.util.tools)
export(projects.shared.feature)
export(projects.shared.resources)

Expand Down Expand Up @@ -76,7 +78,7 @@ kotlin {
iosMain {
dependencies {
api(projects.shared.platform)
api(projects.shared.util)
api(projects.shared.util.tools)
api(projects.shared.feature)
api(projects.shared.resources)

Expand Down Expand Up @@ -116,6 +118,7 @@ skie {
FlowInterop.Enabled(true)
EnumInterop.Enabled(true)
SealedInterop.Enabled(true)
SuppressSkieWarning.NameCollision(true)
}
}
}
Expand Down
Loading
Loading