https://kotlinlang.org
Join Slack
LaunchedEffect not triggered when mutableStateOf has same value? I want to display a snackbar messag...
a

Aaron Waller

over 3 years ago
LaunchedEffect not triggered when mutableStateOf has same value? I want to display a snackbar message when the user clicks on “Favorite Post” It works fine the first time but after that it is not getting triggered anymore. Here is my snackBarMessage State in ViewModel:
var snackBarMessage: MutableState<String?> = mutableStateOf(null)
    private set
and the set function:
fun setSnackbarMessage(msg: String?){
    snackBarMessage.value = null
    snackBarMessage.value = msg
}
Here is my Launcheffect which unfortunately is not getting triggered twice:
LaunchedEffect(key1 = viewModel.snackBarMessage.value){ 
    val message = viewModel.snackBarMessage.value
    message?.let {
        scaffoldState.snackbarHostState.showSnackbar(message, "Ok")
    }
}
and on Favorite button click I call:
viewModel.setSnackbarMessage("Added to Favorite")
Eventhough I set the snackBarMessage to null it is not getting retriggered, only if the string message is different from the one before. I want to show the snackbar every time the user clicks on the button and not just the first time
a
o
+3
  • 5
  • 8
  • 690
Question: How can I get a "only enter numbers" `TextField` ?
u

毛小川

over 3 years ago
Question: How can I get a "only enter numbers"
TextField
?
u
a
  • 2
  • 2
  • 690
We are trying to use paging together with sticky headers. But now instead of using `items(pagingItem...
f

Feri Nagy

over 3 years ago
We are trying to use paging together with sticky headers. But now instead of using
items(pagingItems) {}
, we have to iterate through the items manually, do
pagingItems.peek(index)
and add single
item {}
one by one:
@Composable
fun PlainPaging(pagingItems: LazyPagingItems<Item>) {
    LazyColumn {
        items(pagingItems) { item ->
            when (item) {
                is Item.Header -> Text(text = item.title)
                is Item.Data -> Text(text = item.text)
                null -> Text("placeholder")
            }
        }
    }
}

// vs

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun StickyPaging(pagingItems: LazyPagingItems<Item>) {
    LazyColumn {
        for (index in 0 until pagingItems.itemCount) {
            when (val item = pagingItems.peek(index)) {
                is Item.Header -> stickyHeader { Text(text = item.title) }
                is Item.Data -> item { Text(text = item.text) }
                null -> item { Text("placeholder") }
            }
        }
    }
}
Is this going to have some performance implications? Is there a better way to do it? Thanks
👍 1
➕ 1
f
a
f
  • 3
  • 4
  • 689
Hi :) Has anyone managed to add Firebase in a project generated by Kotlin's Wizard for Android and ...
a

Alexis Jiménez

almost 2 years ago
Hi :) Has anyone managed to add Firebase in a project generated by Kotlin's Wizard for Android and iOS? I mean, there is only one gradle file for composeApp module and the project level gradle. So, I am confused about the necessary dependencies and plugins and where to add them. Reference: https://medium.com/@niranjanky14/how-do-you-configure-your-firebase-project-for-android-app-in-compose-multiplatform-c239c8cb4d4a
a
j
  • 2
  • 33
  • 687
Hello is it possible to add `kotlin-parcelize` for Kotlin library/module (not-android) ? Can anyone...
n

neerav

almost 3 years ago
Hello is it possible to add
kotlin-parcelize
for Kotlin library/module (not-android) ? Can anyone share how as I am getting error regarding android package. ? Here is my kotlin module
build.gradle.kts
plugins {
    id("java-library")
    id("org.jetbrains.kotlin.jvm")
    id("kotlinx-serialization")
    id("kotlin-parcelize")
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
}
n
e
c
  • 3
  • 4
  • 687
```Functions which invoke @Composable functions must be marked with the @Composable annotation``` an...
c

camkadev

almost 6 years ago
Functions which invoke @Composable functions must be marked with the @Composable annotation
any workaround to change data (outside Composable) placed inside state?
c
i
z
  • 3
  • 11
  • 686
I am experiencing a strange memory leak with Compose with AnimatedNavHost from Accompanist and Andro...
v

vide

over 2 years ago
I am experiencing a strange memory leak with Compose with AnimatedNavHost from Accompanist and AndroidView. 1. Start from page A that contains an AndroidView 2. Navigate to page B (without popping page A) 3. (Page A is removed from the composition (onDispose called etc)) 4. Page B is popped off the stack, returning to A 5. Repeat indefinitely. Every time page A is displayed, a new View is created and the previous Views never get garbage collected. Any idea why this might be happening? Is it possible that a reference to the View could be accidentally stored somewhere or could this be a bug in Compose/Accompanist/Navigation? An additional possibly important detail: GC happens normally if A is popped off the navigation stack. EDIT: I managed to debug this and find the root cause. I will write an explanation in 🧵 later if anyone else experiences the same issue. Done.
👀 2
v
z
r
  • 3
  • 6
  • 685
I have this simple data class. What should I do to make it possible to use jackson to (de)serialize ...
p

Pihentagy

over 1 year ago
I have this simple data class. What should I do to make it possible to use jackson to (de)serialize from-to json? I'd prefer not to specify property names explicitly.
data class MyClass  @JsonCreator constructor (
    var changedAt: Date,
    var from: Int,
    var to: Int,
    var percentChanged: Int,
    var levelUsed: Int,
)
Untitled.txt
p
s
t
  • 3
  • 27
  • 684
hey guys, anyone encountering this error on iOS? `Uncaught Kotlin exception: kotlin.native.internal...
h

Hristijan

over 1 year ago
hey guys, anyone encountering this error on iOS?
Uncaught Kotlin exception: kotlin.native.internal.IrLinkageError: Can not get instance of singleton 'Plugin': No class found for symbol 'io.ktor.client.plugins/HttpTimeout.Plugin|null[0]'
ktor = "2.3.8"
h
t
d
  • 3
  • 6
  • 684
Is there any way, to align top of the text with my icon?
p

Peter

about 2 years ago
Is there any way, to align top of the text with my icon?
p
c
+2
  • 4
  • 19
  • 684
Previous848586Next

kotlinlang

A modern programming language that makes developers happier.

Powered by