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
  • s

    Sololo

    06/01/2021, 8:22 AM
    how to get the root view instance?
    a
    • 2
    • 2
  • p

    Philip S

    06/01/2021, 8:52 AM
    I have looked at some tutorials for implementing shimmer loading in compose but can't decide the best way to set it up code wise.
    @Composable
    fun MyList(items: List<Items>, isLoading: Boolean)
    I thought about using a flag as shown above and then if-else to determine if it should show the real view or just the shimmer variant. If you have implemented shimmer loading what worked best for you? Did you perhaps find a more elegant solution?
    p
    b
    • 3
    • 7
  • v

    Vitaliy Zarubin

    06/01/2021, 9:23 AM
    I want to add a Repeat button. Is it possible to restart flow like this? It seems to work, but Composable is not updated.
    val user by viewModel.loadingUser.collectAsState(initial = null)
    when {
        user.isSucceeded -> navController.navigate(NavScreen.Home.route)
        user.isError -> ErrorConnect { viewModel.repeat() }
        else -> Splash()
    }
    k
    p
    • 3
    • 18
  • a

    Aditya Thakar

    06/01/2021, 9:49 AM
    Hi, how do we access the samples mentioned in the code documentation? When I hover over it, it’s not clickable
    s
    a
    • 3
    • 6
  • n

    Nipun Rajput

    06/01/2021, 10:28 AM
    I'm having issue with
    Accompanist
    image loading library, I am using compose pagination in combination with
    LazyColumn
    and
    LazyRow
    , But when i scroll up and down images of row which is immediate above current viewing elements got disappear and when i scroll back after sometimes items reappeared, Is this bug in accompanist or
    LazyColumn
    ? I guess this is Issue in image loading only because in that row text is visible but not the image, strange isn't it?
    m
    • 2
    • 8
  • m

    Marcin Środa

    06/01/2021, 10:35 AM
    How to test LazyColumn items? Looks like items are not wrapped. See thread …
    r
    f
    • 3
    • 8
  • a

    Albert Chang

    06/01/2021, 10:37 AM
    I'm curious why compose keeps using the old
    inline class
    syntax and suppressing the deprecated warning as shown here instead of replacing it with
    value class
    after supporting Kotlin 1.5? I tried using value classes (with snapshot version of compose) in my app and there seems no problem.
    a
    j
    • 3
    • 2
  • d

    Daniel

    06/01/2021, 10:58 AM
    Is there any way to set the width of an EditText in characters?
    h
    • 2
    • 8
  • s

    Saiedmomen

    06/01/2021, 11:20 AM
    A lot of classes and functions that we could use to build our own components are
    internal
    or
    private
    . I know the reason for limiting the public API but an optIn annotation might be enough. Right now we have to copy huge amounts of code in order to have a working custom component. Code that won't get maintained or fixed easily. If we could opt in to them, our code would break on upgrades but we would still get the benefits and fixes after fixing them.
    h
    a
    a
    • 4
    • 25
  • d

    Daniele Segato

    06/01/2021, 11:59 AM
    Testing with compose: is there a way to match a node by tag only if it's a child of another node? Hypothetical situation:
    Column: tag A
      TextField: tag field
      Text: tag error
    Column: tag B
      TextField: tag field
      Text: tag error
    Column: tag C
      TextField: tag field
      Text: tag error
    If i want to match the TextField tagged "field" inside the column tagged "B", how do I write the SemanticMatcher?
    z
    • 2
    • 3
  • p

    Paul Woitaschek

    06/01/2021, 12:21 PM
    What would be a good way to react to an mvi-style events flow within a composable? The IDE tells me I need to use a launched effect but I don't understand why and what I should use as a key.
    n
    s
    +2
    • 5
    • 11
  • i

    iamthevoid

    06/01/2021, 12:53 PM
    Did anybody meet exception [thread] on recomposition? Let me explain
    Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter
    This parameter declared as default argument in function body and not passed in calling place. If i passing exactly the same value into funtion call app works well and not crashes on recomposition. Looks like default argument of composable function stores somewhere and GC (or somethig else) remove it when composable is recomposing, but ref stay the same and i get this error.
    l
    • 2
    • 6
  • z

    Zach Klippenstein (he/him) [MOD]

    06/01/2021, 1:06 PM
    I recently tried to explain some of the APIs that compose uses to make its state management work. It’s all based on something called “snapshots”. You probably won’t ever need to actually use these they’re a bit lower level, but knowing how this works might help you reason about how your code is running. Read more here.
    👍 21
    👀 3
    👍🏼 4
    c
    e
    • 3
    • 8
  • e

    Erlan Amanatov

    06/01/2021, 1:14 PM
    Can someone explain to me how this works? First of all, everything works fine, just as I need, but I don't understand why. I have a
    composable
    function
    @Composable
    fun modified(
    object1: A,
    object2: B) : Boolean {...}
    Where
    A
    is a Data Class,
    B
    is a regular class with
    MutableState
    variables. I use this function to control the
    Button
    , so it's enabled only if there are any differences between the objects.
    Button(
    ...
    enabled = modified(object1, object2)
    ...
    )
    How does it work? Any changes to
    MutableState
    variables of
    object2
    trigger the
    modified
    function?
    z
    a
    • 3
    • 4
  • l

    len

    06/01/2021, 2:14 PM
    Is there any difference between
    LaunchedEffect
    and
    DisposableEffect
    when you don't actually need any cleanup? I've seen in the official samples some `DisposableEffect`s with an empty
    onDispose {}
    , and that makes me think
    LaunchedEffect
    should be a better option, but I'm in doubt 🤔
    a
    • 2
    • 18
  • t

    Tin Tran

    06/01/2021, 2:18 PM
    Hi guys! I’m trying to navigate to a composable using navigation compose. It’s worked fine until i tried to navigate to a screen from a button inside a
    ModalBottomSheetLayout
    , the app crashed. Has anyone had the same problem?
    • 1
    • 1
  • t

    Tiago Nunes

    06/01/2021, 2:51 PM
    Hey everyone, I have a RecyclerView with items; each item has an imagePath; in onBindViewHolder, a new coroutine is launched, to check if the image is already stored locally. If it is, it sets the image. If it isn't, it downloads and sets the image. This is the code inside onBindViewHolder:
    lifecycleScope.launch {
        val bitmap = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
            getLocalImageAsBitmap(imageName) ?: run {
                val file = requireContext().cacheDir.resolve("places").apply { mkdirs() }.resolve(imageName)
                try {
                    repository.downloadFile(imageName, file)
                    getLocalImageAsBitmap(imageName)
                } catch (e: Exception) {
                    e.printStackTrace()
                    null
                }
            } ?: return@withContext null
        }
        binding.imageView.setImageBitmap(bitmap)
    }
    How can I migrate this to Compose (LazyColumn)?
    a
    z
    • 3
    • 6
  • r

    Rodri Represa

    06/01/2021, 3:01 PM
    Hello everyone! I've finish my Item Indicator for the Accompanist
    HorizontalPager
    . The idea is extend it in the future for
    LazyRow
    . If you like you can check my Jetpack Compose animations repo here https://github.com/rodrirepresa/ComposeAnimations
    21-05-31-15-01-46.mp4
    👍🏼 1
    🙌🏻 1
    👍🏻 1
    👍🏽 1
    👍 3
    🙌 2
    c
    n
    • 3
    • 3
  • s

    Se7eN

    06/01/2021, 4:04 PM
    I'm animating the progress of this meter from 0 to 100 infinitely. When some data from the network is loaded, containing the progress value, I want it to transition to that value and stop the infinite animation. How can I achieve this? Code in thread.
    t
    d
    • 3
    • 11
  • d

    Daniel

    06/01/2021, 6:24 PM
    How do people indicate when the combination of multiple fields in a form is invalid, when it isn't clear which one specifically is invalid? I'm thinking about just marking every fields as an error with the red outline, or outlining the group of fields in red (Context is a bit esoteric. I'm making an entry form for UTM coordinates. You basically specify one of a bunch of sections of the globe, and also where in that section. Different sections have different sizes. If you specify somewhere outside the section you either specified the wrong sub-position or the wrong section or both. Also users will generally be copying all the fields from somewhere else).
    k
    • 2
    • 5
  • n

    nglauber

    06/01/2021, 8:28 PM
    I know it’s a recurrent question here… but is there a way to remove this extra padding from
    TextField
    without implement it from
    BasicTextView
    ? Or have this “LineTextField” + everything from “Material Design TextField” (label, leading icon, trailing icon, …)?
    ➕ 3
    i
    c
    l
    • 4
    • 33
  • t

    tad

    06/01/2021, 10:54 PM
    I may be doing something wrong with LazyColumn or I've triggered a bug by using this code for transition animations:
    • 1
    • 3
  • m

    Muhammad Zaryab Rafique

    06/02/2021, 3:09 AM
    Anyone have idea about this, kindly guide me. https://stackoverflow.com/questions/67793793/i-want-to-add-parallax-effect-in-jetpack-compose
    z
    • 2
    • 1
  • m

    ms

    06/02/2021, 5:46 AM
    @cb Do you have any plan to support (un)hiding status bar & navigation bar or to go full-screen in
    Insets
    API?
    c
    • 2
    • 3
  • z

    Zan Skamljic

    06/02/2021, 7:59 AM
    Why does JetSnack declare Jetsnack Theme? https://github.com/android/compose-samples/blob/main/Jetsnack/app/src/main/java/com/example/jetsnack/ui/theme/Theme.kt#L113
    a
    • 2
    • 6
  • l

    Law Gimenez

    06/02/2021, 7:59 AM
    Is Jetpack Compose backward compatible including Android 8.1?
    :yes: 3
    h
    • 2
    • 2
  • s

    Superblazer

    06/02/2021, 8:16 AM
    What is the best way to get the colors from an Image Composable? I load the image with Coil from a url. In jetcaster example, they seem to Reload the image on touch to get the colors with palette api, how do I get the colors immediately instead without calling the url again?
    a
    z
    • 3
    • 6
  • n

    Nicolas Acart

    06/02/2021, 9:38 AM
    Hello guys, I am having troubles with the animated vectors. When I launch the animation it seems that not every <objectAnimator> are launched and I don't understand why. Here is my code to launch an animated vector resource :
    val image = animatedVectorResource(id = R.drawable.avd_pathmorph_arrowoverflow_arrow_to_overflow)
    val atEnd by remember { mutableStateOf(false) }
    Image(
      painter = image.painterFor(atEnd = atEnd),
      contentDescription = null,
    )             
    LaunchedEffect(Unit) {
      atEnd = !atEnd
    }
    The drawable comes from here : https://github.com/SmartToolFactory/Animation-Tutorials/blob/master/Tutorial2-1Ani[…]/res/drawable/avd_pathmorph_arrowoverflow_arrow_to_overflow.xml When I run this code, it seems that only the first object animator is done : It moves the point but does not morph to become lines etc. Android Studio Canary's Design window can run the animation correctly but when I run it in my code it fails. Am I launching it correctly ? Do I misunderstand something ?
    d
    • 2
    • 2
  • a

    allan.conda

    06/02/2021, 10:33 AM
    I’ve been migrating our code to compose-navigation. We’re using MVVM but the navigation does not go through the ViewModel and we delegate it directly to the composable up to the navigation graph. For user interaction that does some processing before navigation (such as login) we expose a
    suspend fun
    which returns the operation’s result and navigate accordingly. Works fine so far, and now I encountered a new use-case integrating with non-Kotlin code. I use CameraX ImageCapture use case with takes a listener for successful capture, I can’t use suspend fun to wait for the result. So now I’m looking for options. I wonder if we could represent capture events from the ViewModel, and I remember discussions on SingleLiveEvents and we now prefer representing state instead of events in Compose. For example we now use state for snackbar or dialog visibility instead of SingleLiveEvent. I’m not sure how to do this for navigation events. I’ve seen articles suggesting
    StateFlow
    ,
    SharedFlow
    ,
    Channel
    for navigation events, but I’m curious what the Compose team thinks. I haven’t found an official example where the navigation is handled within the ViewModel, is it deliberate that we want to decouple ViewModels from the Views’ navigations completely (no mention of “navigation” within a ViewModel)? We’re also having internal discussions how to handle navigation in our Compose+MVVM architecture and we’re split on what we need to do about whether we should call the navigation lambda directly on user event (like onClick) or whether we should keep our Composables pure&passive.
    a
    • 2
    • 3
  • t

    than_

    06/02/2021, 11:06 AM
    Is there a way to tell compose class is
    @Stable
    or
    @Immutable
    on a class you don't own?
    🇳🇴 1
    a
    • 2
    • 2
Powered by Linen
Title
t

than_

06/02/2021, 11:06 AM
Is there a way to tell compose class is
@Stable
or
@Immutable
on a class you don't own?
🇳🇴 1
a

Adam Powell

06/02/2021, 1:19 PM
We considered it and may add something like this later
t

than_

06/02/2021, 3:17 PM
😞 Ok I'm gonna hope for the future 🙂 Thanks for reply
View count: 1