https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
compose
  • e

    elye

    11/16/2021, 11:21 AM
    Can I wrap Jetpack Compose inside an Android Custom View like below?
    class CustomView @JvmOverloads constructor(
            context: Context,
            attrs: AttributeSet? = null,
            defStyleAttr: Int = 0)
        : View(context, attrs, defStyleAttr) {
    
        // Some Jetpack Compose drawn item
    
    }
    I have also check in https://stackoverflow.com/q/69987040/3286489
    c
    d
    • 3
    • 5
  • a

    antonioleiva

    11/16/2021, 11:56 AM
    Hi! Does anyone know what's the use case for the
    parent
    argument in the 
    setContent
     extension?
    public fun ComponentActivity.setContent(
        parent: CompositionContext? = null,
        content: @Composable () -> Unit
    ) {...}
    I've never seen a sample using this argument 🤔
    a
    z
    • 3
    • 3
  • t

    Tgo1014

    11/16/2021, 1:58 PM
    Any ideas how to make a parallax like this in a LazyColumn?
    d
    • 2
    • 1
  • g

    gpaligot

    11/16/2021, 2:32 PM
    Hello here! I would like to use Compose in one of my professionnel project with a large code base but I have a huge performance impact when I’m using a LazyColumn with a pretty simple row (a Row with some texts inside). Attached to this message, you can find an example on a OnePlus 7T with the GPU usage overlay but it is worst on a Motorola G8 Plus where it is just not usable... We extracted the list on an external project where it is better but we have always a lag on some devices (Motorola G8 Plus impacted). Here the GitHub repository if some of you want to check the source code: https://github.com/adrienbusin/TestComposeLags For information, yes the build is in debug but it is clearly not better with a release version...
    21-11-16-15-16-20.mp4
    s
    a
    +5
    • 8
    • 26
  • r

    Rick Regan

    11/16/2021, 2:55 PM
    One screen (characterized mainly by an array of `Button`s) of my Compose-only app has become really sluggish on Android 12, most noticeably in the emulator (I tried a Pixel 4a and Pixel 5). I am on Compose 1.1.0-beta02/AS Bumblebee Beta 3, but I tested back to alpha-06 and with prior versions of my app and I only see the issue on API 31, not API 30. (I am running the debug version of my app, like I have been, in all cases.) Are there known performance issues before I try to narrow this down further?
    • 1
    • 1
  • p

    Pablo Reyes

    11/16/2021, 4:38 PM
    hi! does anyone know how to center vertically the Icon or trailing elements in a ListItem? ...
    j
    c
    • 3
    • 8
  • p

    Piotr Prus

    11/16/2021, 4:55 PM
    Hello! I recently experimenting a bit with Compose Canvas and I stuck at animation. I have the Row with Canvas and vertical Bars, when I click on a bar, it gets selected and background of this bar changes. What I would love to achieve is that this background will animate from bottom to top on each click, so the user will have nice click experience. Demo in 🧵 Basically, I need to use
    animateFloatAsState
    to animate height, but I do not know how to reset this on each click on next bar in the chart.
    z
    d
    • 3
    • 6
  • a

    Andrei Kovalev

    11/16/2021, 5:52 PM
    Hi folks! Is there any easy way to calculate total scroll value of the list?
    object : NestedScrollConnection {
                override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
                    totalScrolled -= available.y
    }
    if the list reaches the top and I keep scrolling up
    available.y
    will still be positive therefore scrolling back to the initial position will not make
    totalScrolled
    as 0
    a
    • 2
    • 1
  • a

    AmrJyniat

    11/16/2021, 6:06 PM
    How to call a Composable fun from coroutine while collecting a flow? compiler said you can't use Composable fun from another non Composable fun.
    z
    • 2
    • 9
  • m

    Mehdi Haghgoo

    11/16/2021, 8:08 PM
    Does BasicTextField, TextField or OutlinedTextfield have a mechanism for showing error message similar to what is achieved using TextView's setError() and getError()?
    s
    c
    • 3
    • 7
  • m

    Mehdi Haghgoo

    11/16/2021, 8:11 PM
    c
    c
    • 3
    • 2
  • i

    Isaac

    11/16/2021, 8:20 PM
    Is there a way to open a
    Composable
    screen when the app receives a notification while it’s in the foreground without using a
    PendingIntent
    ? Cc: @louiscad
    l
    i
    • 3
    • 15
  • j

    jeff

    11/17/2021, 4:03 AM
    If I pull in
    androidx.compose.ui:ui:1.1.0-alpha03
    I can view the source code in Android Studio. But if I pull in
    1.1.0-alpha04
    (or anything past that) I can't, I just get ugly decompiled .class files -- any idea why that is? Was source omitted from later builds? How could I check that?
    👀 1
    z
    • 2
    • 4
  • u

    Utkarsh Tiwari

    11/17/2021, 4:23 AM
    Hi, is there any way to add this kind of fade out effect in TextField in horizontal direction?
    a
    c
    a
    • 4
    • 3
  • a

    Abhinav Sharma

    11/17/2021, 6:19 AM
    @Pedro Gomez Is there a way to add Idling resources to Coil Image loading in compose UI for Screenshot testing? I have few cases, where I use the same Image Url but only first test does not load the image and rest all screenshots have the image @theapache64
    ➕ 2
    c
    p
    a
    • 4
    • 5
  • a

    Alex

    11/17/2021, 9:22 AM
    Why do the docs use 
    by remember { mutableStateOf(selection) }
     instead of
    rememberUpdatedState
     ? Seems like the latter is the same just more refined?
    n
    a
    • 3
    • 4
  • a

    allan.conda

    11/17/2021, 10:22 AM
    What’s the right way to deeplink into another activity (interoperability) and make it part of the
    NavHost
    backstack? I need the activity to launch from a specific destination, so that user is navigated back to that after exiting the activity.
    • 1
    • 2
  • a

    Abhinav Suthar

    11/17/2021, 10:24 AM
    I am passing
    SnapshotStateList<Char>
    to a composable function. But any changes to
    SnapshotStateList's item(s)
    doesn’t re-trigger the
    LaunchedEffect
    Any idea why? Code in thread.
    z
    • 2
    • 5
  • a

    Alex

    11/17/2021, 11:33 AM
    Does any one have any intel on when
    beta-03
    is going to be released?
    👀 1
    a
    t
    • 3
    • 5
  • m

    Matti MK

    11/17/2021, 11:52 AM
    I’ve got a problem where my VM gets re-initialized when moving between composable screens. Not quite sure on how to go about fixing it. My VM is initialized by
    Koin
    as shown below.
    import org.koin.androidx.viewmodel.dsl.viewModel
    import org.koin.dsl.module
    
    actual val myScreenModule = module {
        viewModel { MyScreen() }
    }
    The VM itself extends
    import androidx.lifecycle.ViewModel
    class. And inside my
    NavGraphBuilder.addMainGraph
    block I instantiate the screen
    composable(MyScreen.route) {
            MyScreen(
                viewModel = get(),
            )
        }
    Not quite sure how to go about things here: is this expected behaviour and I should store VM state inside or is there some other way that I could keep the state?
    c
    • 2
    • 3
  • l

    lhwdev

    11/17/2021, 1:55 PM
    I've thought it would be great if node type emitted from
    @Composable
    is defined with the annotation. (I know this can't be adopted as it is a huge breaking change) Now there are a lot of things using Compose runtime; Compose UI, Glance, Some terminal(I do not remember the name), and can be extended freely. If both Compose UI and Glance had
    Text
    , it would be a lot confusing. 🧵
    z
    • 2
    • 2
  • a

    Anastasia Rozovskaya

    11/17/2021, 1:56 PM
    Hi! I have a fragment and inside it there is a
    ComposeView
    . Could I use this composeView for two types of Composable dialogs which is shown on the screen dynamically depending on backend results? Or should I use one composeView per one type of dialogs?
    m
    • 2
    • 3
  • r

    Rizwan Minhas

    11/17/2021, 1:57 PM
    What is the best approach to play a youtube video in android jetpack compose app?
    z
    y
    • 3
    • 2
  • c

    Colton Idle

    11/17/2021, 8:03 PM
    I'm kind of going crazy on not being able to get this layout to look quite right in my app. Essentially, the top horizontal bar is a carousel made up of RedComposable's, and then there is a green composable list, which is a vertical scrolling column. The GreenComposable includes a RedComposable. The trouble I'm having is how to size the RedComposable. My design team said "The Red should be 40% of the green, and then that size of the red should be used in the horizontal scroller" How would I do that in compose?
    j
    c
    +4
    • 7
    • 43
  • a

    Andy Gibel

    11/17/2021, 8:09 PM
    I've been consuming a lot of the talks and articles about how Compose works behind the scenes, mostly from Leland but others too. I've learned a lot about slot tables, recompition phases, positional memoization etc but one piece I feel like I'm missing is this - how does actual emission of UI work? tl;dr; does anyone have good resources on the actual rendering conversion that happens behind the scenes?
    • 1
    • 1
  • d

    darkmoon_uk

    11/17/2021, 8:33 PM
    Any built-in way to determine if a
    @Composable
    is being presented in a
    @Preview
    or not? (Something in Locals?) I know it shouldn't care; but sometimes in the real world there are practical reasons. In this case the Coil SVG library is crashing in Previews for some class-loader related reason; I need some flag to suppress registering of the SVG handler in Previews so I can get on with building the rest of the View.
    a
    i
    y
    • 4
    • 13
  • m

    Marc-Antoine Fortier

    11/17/2021, 8:38 PM
    When trying to update to kotlin 1.6.0 in my project using compose, I get the following error :
    e: This version (1.0.5) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to be using Kotlin version 1.6.0 which is not known to be compatible. Please fix your configuration (or
    suppressKotlinVersionCompatibilityCheck
    but don't say I didn't warn you!).
    Is there an available version of the compose compiler that supports kotlin 1.6.0? Ours is set to
    kotlinCompilerExtensionVersion = "1.0.5"
    Thanks for your help!
    🇳🇴 2
    • 1
    • 1
  • j

    Joseph Hawkes-Cates

    11/17/2021, 9:49 PM
    I am trying to pass a test instance of one of my data classes into one of my composables in a preview and I’m getting
    java.lang.NoClassDefFoundError: Could not initialize class...
    whenever I try to create the data class instance within my preview composable function. Has anyone else run into this before?
    a
    • 2
    • 4
  • t

    Tash

    11/17/2021, 10:08 PM
    Hi all. Tivi defines a nice helper to work with the new
    flowWithLifecycle
    API. Since new lifecycle APIs are stable in 2.4.0, are there any plans to add similar helpers in Compose artifacts?
    • 1
    • 2
  • c

    Colton Idle

    11/17/2021, 10:11 PM
    I have:
    class ScreenAState {
        val people = mutableStateListOf<PersonUIWrapper>()
    }
    
    data class PersonUIWrapper(var selected: Boolean, val person: Person)
    then in an onclick of a person in my list I do
    TextButton(onClick = {
        it.selected = true
    })...
    but my code doesn't recompose, and therefore doesn't show a checkmark. Is my PersonUIWrapper supposed to use snapshot state internally for it's two fields?
    j
    n
    +2
    • 5
    • 21
Powered by Linen
Title
c

Colton Idle

11/17/2021, 10:11 PM
I have:
class ScreenAState {
    val people = mutableStateListOf<PersonUIWrapper>()
}

data class PersonUIWrapper(var selected: Boolean, val person: Person)
then in an onclick of a person in my list I do
TextButton(onClick = {
    it.selected = true
})...
but my code doesn't recompose, and therefore doesn't show a checkmark. Is my PersonUIWrapper supposed to use snapshot state internally for it's two fields?
j

Joseph Hawkes-Cates

11/17/2021, 10:15 PM
What does “it” in your onClick refer to? the onClick lambda parameter for TextButton looks like it doesn’t take an argument.
I’m assuming it’s supposed to refer to your PersonUIWrapper, but not clear on how it’s referring to it from this code snippet.
c

Colton Idle

11/17/2021, 10:16 PM
vm.state.people.forEach {
    TextButton(onClick = {
    it.selected = true
}) {
👍 1
j

Joseph Hawkes-Cates

11/17/2021, 10:17 PM
Are you passing in it.selected to the checkbox as the checked state?
or rather the PersonUIWrapper.selected value. May not be in the same forEach
c

Colton Idle

11/17/2021, 10:19 PM
if (it.selected) {
    Icon(Icons.Default.Check, null)
}
Text(text = it.person.name)
👍 1
So the full thing becomes
vm.state.people.forEach {
    TextButton(onClick = {
    it.selected = true
}) {
if (it.selected) {
    Icon(Icons.Default.Check, null)
}
Text(text = it.person.name)
}
Sorry for providing it in pieces. I was trying to be as concise as possible. 😄
j

Joseph Hawkes-Cates

11/17/2021, 10:20 PM
gotcha. That looks like it should work from my knowledge. Unfortunately, I’m fairly new at this.
My understanding is any access to the mutable state should be recorded and marked for recomposition when it changes
c

Colton Idle

11/17/2021, 10:21 PM
Yeah. Just when I thought lists in compose made sense...
j

Joseph Hawkes-Cates

11/17/2021, 10:23 PM
my only suspicion is that you may need a list of mutableState<PersonUIWrapper> instead of a mutableStateListOf
I’m thinking maybe the mutableStateList will recompose on changes to the list itself rather than changes to the internal state of the values in the list
I haven’t used mutableStateListOf, though so that’s just a hunch
n

nitrog42

11/17/2021, 10:33 PM
there is exactly your problem here : https://stackoverflow.com/questions/69718059/android-jetpack-compose-mutablestatelistof-not-doing-recomposition
mutableStateListOf
can only notify about adding/removing/replacing some element in the list. When you change any class inside the list, the mutable state cannot know about it.
👍 1
a

Alex Vanyo

11/17/2021, 10:40 PM
To partially answer your original question, if
PersonUIWrapper
was backed by state that was observable to Compose (like
mutableStateOf
), then this would work like you’d expect. And that can be preferable as an alternative to the
.copy
solution with a
data class
.
🤩 1
c

Colton Idle

11/18/2021, 1:12 AM
Cool. I moved to this with Alex's rec
class PersonUIWrapper(val selected: MutableState<Boolean> = mutableStateOf(true), val person: Person)
It kind of sucks that I can't use
by
in this case, but using
.value
isn't the worst thing!
a

Adam Powell

11/18/2021, 2:50 AM
seems you're looking for
class PersonUIWrapper(
  selected: Boolean,
  val person: Person
) {
  var selected by mutableStateOf(selected)
}
👍 1
c

Colton Idle

11/18/2021, 3:40 AM
Safe to say that I wouldn't have come up with that on my own. Thanks adam. I'm still not 100% with Kotlins constructor syntax, but I guess this just defines a constructor arg and uses that constructor arg to create a property?
a

Adam Powell

11/18/2021, 5:27 AM
Yep
If you read Kotlin's primary constructors like a function where the class body is the function body then it makes a lot of things fall into place
👍 3
View count: 6