Missing `lifecycle` parameter for `observe` function (jetbrains-compose.v020-build128)
See original GitHub issueThis is the decompose setup I use (following the guide in the readme):
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.decompose.value.observe
class WithCharacterState {
private val _value = MutableValue(mutableListOf<Character>())
val state: Value<List<Character>> = _value
fun addCharacter(character: Character) {
_value.value.add(character)
}
}
@Composable
fun WithCharacterState.render() {
state.observe { state ->
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = state.toString())
Button(onClick = { addCharacter(CharacterTemplate.DEFAULT_CHARACTER)} ) {
Text("Add Character")
}
}
}
}
However I receive the following two errors:
e: /xetra11/app/module/character/WithCharacterState.kt: (25, 11): No value passed for parameter 'lifecycle'
e: /xetra11/app/module/character/WithCharacterState.kt: (26, 9): @Composable invocations can only happen from the context of a @Composable function
my build.gradle.kts
:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.4.20"
id("org.jetbrains.compose") version "0.2.0-build128"
}
group = "com.github.xetra11"
version = "0.0.1"
repositories {
jcenter()
mavenCentral()
google()
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") }
maven { url = uri("https://dl.bintray.com/arkivanov/maven") }
}
dependencies {
implementation(compose.desktop.currentOs)
implementation("org.slf4j:slf4j-simple:2.0.0-alpha1")
val decomposeVersion = "0.1.2"
implementation("com.arkivanov.decompose:decompose:$decomposeVersion")
implementation("com.arkivanov.decompose:extensions-compose-jetbrains:$decomposeVersion")
testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
testImplementation("org.assertj:assertj-core:3.18.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0")
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "11"
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "app"
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Side-effects in Compose - Android Developers
A side-effect is a change to the state of the app that happens outside the scope of a composable function. Due to composables'...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also you may like to use
Value.asState
extension function:Probably it is worth to deprecate the
Composable
Value.observe
extension, will think about it.@arkivanov Thanks for your time but I think I mixed up some concepts here and there. Having a hard time grasping the state concepts with Compose for Desktop. Completely new to the field 😉