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

    Sahruday

    06/23/2022, 11:23 AM
    Is there any way for fast scroll for
    LazyLazyState
    ?
    animateScrollToItem
    for long distance scroll, it animates all the way to the index, which takes too long time. Need to animate the scroll at initial, teleport to some nearest index and animate from there to the index.
    s
    e
    • 3
    • 4
  • a

    allan.conda

    06/23/2022, 12:36 PM
    Does Compose generate a baseline-profile by default if you plug the profileinstaller library even without generating your own
    baseline-prof.txt
    file?
    c
    b
    • 3
    • 5
  • k

    kotlinforandroid

    06/23/2022, 12:44 PM
    Any idea why the dropdown menu gets moved to the top-left of the screen instead of being right below the
    ExposedDropdownMenuBox
    ? Code in thread.
    ✅ 1
    • 1
    • 2
  • j

    julioromano

    06/23/2022, 1:24 PM
    What is the “touch slop” ? I’ve encountered this term in
    PointerInputScope.detectTransformGestures()
    docstring but I can’t make sense of what it means.
    ✅ 1
    j
    a
    • 3
    • 4
  • z

    Zoltan Demant

    06/23/2022, 1:38 PM
    I cant recall the article, but I recently read about how lambdas are grouped in classes in compose (and thats one of the reasons why release builds are so much faster than debug). Does the same thing happen if the lambda is wrapped inside a value class? Example in thread 🧵
    • 1
    • 1
  • p

    Paul Woitaschek

    06/23/2022, 1:44 PM
    Where is the code located that is responsible for the IDE preview creation?
    a
    • 2
    • 1
  • t

    Tolriq

    06/23/2022, 3:01 PM
    Anyone got clue about what parameters allows to fix text overlapping when using very large fontSize?
    f
    h
    +2
    • 5
    • 21
  • b

    Billy Newman

    06/23/2022, 3:06 PM
    Hello all, wondering if someone can help me understand LayColumn’s contentPadding and its relation to ListState.layoutInfo.viewportStartOffset. Example code in reply
    • 1
    • 2
  • f

    farmerbb

    06/23/2022, 4:02 PM
    Has anyone else had trouble with their Compose app crashing on release builds with R8 enabled? Running into a weird crash on one of the screens in my app that seems to be related to the number of composables being drawn on screen at once. For example, if I comment out a few of my composables on that screen, the crash doesn't occur (doesn't matter which ones I comment out). Happens on both 1.1.1 and 1.2.0-rc02. Are there any ProGuard / R8 rules specific to Compose that I'm missing?
    c
    m
    • 3
    • 7
  • z

    zsperske

    06/23/2022, 4:32 PM
    I’m trying to make the scroll position of my Composable available in the View world, but I’m having trouble.
    //I create a scroll state in my view model and pass it here to be used
    val scrollState = rememberSaveable(saver = ScrollState.Saver) { viewModel.state.scrollState }
    
    //Add to my column
    Modifier.verticalScroll(scrollState)
    
    //In on save instance state of an Android View I grab the state and save it to a bundle
    savedState.scrollPosition = viewModel.state.scrollState.value
    However, the scroll state’s value is always 0. Am I going about this all wrong?
    c
    • 2
    • 13
  • r

    Ryan Simon

    06/23/2022, 5:00 PM
    Hello :android-wave: , I'm currently trying to wrap some text around an image like the screenshot below. Does anyone have an idea if there's an API that exists in Compose to do this? Or is this a custom Canvas thing that I need to look into?
    h
    c
    +2
    • 5
    • 19
  • t

    Tolriq

    06/23/2022, 8:05 PM
    What is the proper way to scroll a lazy list so that the item is centered with items of different sizes? If the item is not visible yet we don't have the size yet.
  • d

    Daniel Okanin

    06/23/2022, 8:40 PM
    Hi everyone! Can you explain me what is the different between the codes below ? And on LaunchedEffect block, if the key is changed during the block the LaunchedEffect is re launched again before the block is finished? @galex @Mor Amit
    LaunchedEffect(shouldLoadMore) {
            if (shouldLoadMore.value) {
                lastTotalItems = state.layoutInfo.totalItemsCount
                onEndReached()
            }
        }
    
    =========================
    
     LaunchedEffect(shouldLoadMore) {
            snapshotFlow { shouldLoadMore.value }
                .collect { shouldLoadMore ->
                    if (shouldLoadMore){
                        lastTotalItems = state.layoutInfo.totalItemsCount
                        onEndReached()
                    }
                }
        }
    s
    • 2
    • 27
  • m

    mattinger

    06/23/2022, 11:22 PM
    Does anyone know of 1.2.0 will break binary compatibility or not with 1.1.1? I know from 1.0 to 1.1 i had a few issues as some function signatures changed. Also, will it force me into updating my target sdk? We're still in the process of getting ready to update to 31 (though we compile with 31, we still target 30)
    a
    • 2
    • 2
  • z

    zt

    06/24/2022, 2:11 AM
    I'm using the exoplayer lib and a problem I have is that fading doesn't work, so it just pops in and out. Is there some way to fix this?
    @Composable
    fun Player(
        modifier: Modifier = Modifier,
        player: Player,
    ) = DisposableEffect(
        AndroidView(
            modifier = Modifier
                .aspectRatio(16f / 9f)
                .then(modifier),
            factory = { context ->
                PlayerView(context).apply {
                    this.player = player
                    useController = false
                    useArtwork = true
                    resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
                }
            }
        )
    ) {
        onDispose(player::release)
    }
    g
    m
    f
    • 4
    • 4
  • r

    Rafs

    06/24/2022, 7:11 AM
    Is it advisable to create inner functions in compose, is there any performance hit to doing something like this or should inner functions be strictly remembered?
    @Composable
    fun App(){
        fun someInnerComputationFunction(input: Int): Int{
           //do some computation and return an integer
        }
     
     Box(modifier = Modifier.fillMaxSize()){
    
     }
      
    }
    c
    • 2
    • 1
  • c

    Christoph Wiesner

    06/24/2022, 7:18 AM
    I want to “reveal” a bottom sheet like content once the user scrolls beyond the end of a
    LazyColumn
    Showing that content should behave like a bottom sheet (collapsing or expanding if too little/enough drag) Using
    nestedScroll
    and
    swipeable
    seems the way to go but I’m struggling as the List also needs to be full-height and nesting vertically scrollable maxHeight layouts is disallowed. Any ideas?
    j
    a
    c
    • 4
    • 8
  • n

    Ngọc Nguyên Nguyễn

    06/24/2022, 7:36 AM
    Hello every one!!, I have a useCase return flow of list<item>, I want to emit this data two times from one useCase. Return data is correct but my lazy column just recompose 1 time, and the next data is update after scroll… Code in thread:
    s
    • 2
    • 2
  • a

    allan.conda

    06/24/2022, 8:45 AM
    Is there a more concise way to notify on stop events than this?
    val lifecycleOwner = LocalLifecycleOwner.current
        DisposableEffect(lifecycleOwner) {
            val observer = LifecycleEventObserver { _, event ->
                if (event == Lifecycle.Event.ON_STOP) {
                    viewModel.onStop()
                }
            }
    
            lifecycleOwner.lifecycle.addObserver(observer)
            onDispose {
                lifecycleOwner.lifecycle.removeObserver(observer)
            }
        }
    c
    • 2
    • 1
  • l

    Loney Chou

    06/24/2022, 10:45 AM
    Hello, I'm having a base class like this:
    abstract class Scene : JavaScene() { // JavaScene is a Java class
        private var composition: Composition? = null
    
        fun setContent(content: @Composable () -> Unit) {
            composition = Composition(/* ... */).apply { setContent(content) }
        }
    }
    and a subclass like this:
    class MyScene : Scene() {
        override fun init() { // From JavaScene
            setContent { /* ... */ }
        }
    }
    Nothing complains during the compile time, but at the runtime when
    init
    gets called,
    Scene.setContent
    throws an error:
    androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function0
    . How to fix that?
    o
    • 2
    • 8
  • v

    vide

    06/24/2022, 11:13 AM
    I feel like am missing something fundamental from my mental model of how compose works 😅, could anyone point me to the right direction? I am trying to use a value from LocalConfiguration in a heavy-ish calculation like this:
    val calculationResult by remember { derivedStateOf {
        val primaryLocale = LocalConfiguration.current.locales.get(0) // error
        // Some filtering, calculations, etc.
    } }
    Obviously this doesn't work, since CompositionLocal.current is @Composable and results in an error. If I store the Configuration outside of the derivedStateOf block, it won't work either since it doesn't observe that State is being read and won't update.
    val configuration = LocalConfiguration.current
    val calculationResult by remember { derivedStateOf {
        val primaryLocale = configuration.locales.get(0)
        // Some filtering, calculations, etc.
    } }
    // Doesn't update
    What would be an idiomatic/correct way to achieve what I'm trying to do here?
    o
    s
    • 3
    • 6
  • k

    Kamesh Yadav

    06/24/2022, 1:12 PM
    https://issuetracker.google.com/179203700 Is there a workaround available for this issue?
  • b

    Bino

    06/24/2022, 3:01 PM
    I’m trying to use the
    swipeable
    modifier in a CoordinatorLayout but it is only working Horizontal but not Vertical https://gist.github.com/thebino/4c95e46cca53ec1d9baa29953f0ccb20#file-mainactivity-kt-L79
    01.mp402.mp4
    j
    • 2
    • 4
  • v

    Vinay Gaba

    06/24/2022, 3:45 PM
    Wrote an article talking about the lint rules that Compose ships with by default and where to even find these lint rules. Finally, I talk about how you can update the severity of some of the default rules if it makes sense for your codebase. Read here - https://www.jetpackcompose.app/articles/which-lint-rules-does-jetpack-compose-ship-with
    👍🏼 1
    👍 6
    :thank-you: 1
    l
    g
    • 3
    • 5
  • c

    chatterInDaSkull

    06/24/2022, 4:57 PM
    Its weird that there’s a BottomSheetScaffold but not a
    ModalBottomSheetScaffold
    🤔 why is that? just the case of yet to be created?
    ✅ 1
    i
    • 2
    • 8
  • z

    zt

    06/24/2022, 8:47 PM
    I'm using compose destinations for navigation in my app, and when navigating between screens on my bottom bar, it loses the scroll position in a lazy column I have placed. My navigation code:
    navController.navigate(destination.direction) {
        popUpTo(navController.navGraph.startRoute) {
            saveState = true
        }
        launchSingleTop = true
        restoreState = true
    }
    j
    i
    • 3
    • 17
  • j

    Ji Sungbin

    06/25/2022, 5:40 AM
    Hi, I’m studying the inside of a compose SlotTable. Is the
    invalidateGroupsWithKey(key: Int)
    function in SlotTable only used for testing? I followed the final call of invalidateGroupsWithKey and arrived at the invalidateGroupsWithKey function with @TestOnly attached, and this function is not used. I figured out that the only use case of the
    findEffectiveRecomposeScope(group: Int)
    function, which is i think an important function of SlotTable, is invalidateGroupsWithKey, and I wanted to know where invalidateGroupsWithKey is called.
    @TestOnly
    fun invalidateGroupsWithKey(key: Int) = HotReloader.invalidateGroupsWithKey(key)
    And in the process of reaching final TestOnly function, I saw a function like the one below.
    fun invalidateGroupsWithKey(key: Int) {
        val compositions: List<ControlledComposition> = synchronized(stateLock) {
            knownCompositions.toMutableList()
        }
        compositions
            .fastMapNotNull { it as? CompositionImpl }
            .fastForEach { it.invalidateGroupsWithKey(key) }
         }
    }
    knownCompositions
    is already a MutableList, but why change MutableList to MutableList?
    ➕ 2
    a
    • 2
    • 2
  • t

    Tolriq

    06/25/2022, 8:25 AM
    Is there some documentation about dynamic size layout more advanced than just the BoxWithConstraint? Typically I'd like to take in account the system font zoom to be able to decide what to show or not, or update the font size or layout accordingly.
    j
    • 2
    • 10
  • o

    oday

    06/25/2022, 9:03 AM
    so I’m injecting a couple of dependencies into my ViewModel like so
    @HiltViewModel
    class AuthenticationViewModel @Inject constructor(
        private val determineAuthStatus: DetermineAuthStatus,
        private val populateUserPrefs: PopulateUserPrefs
    ) : ViewModel() {
    and I want to use the viewmodel in a composable like so
    val viewModel : AuthenticationViewModel = hiltViewModel()
    but I get that the viewmodel does not have any zero-argument constructors, I’ve already created the module for these 2 deps to be provided this composable that i’m using the viewmodel in, is started inside an Activity which I’ve set @AndroidEntryPoint on, what am I missing ?
    c
    b
    +2
    • 5
    • 23
  • k

    kotlinforandroid

    06/25/2022, 1:32 PM
    Is compose smart enough to only re-compose UI elements that use fields from a data class that are partially updated? In the example below, if I change the username in the
    TextField
    does compose only update
    NameUI
    or does it also re-compose
    AgeUI
    since state updated and it includes the value for
    AgeUI
    .
    private data class State(
        var name: String = "",
        var age: Int = 0,
    )
    
    @Composable
    fun UI() {
        val state = remember { State() }
    
        NameUI(name = state.name, onNameChange = { state.name = it })
        AgeUI(age = state.age, onAgeChange = { state.age = it })
    }
    
    @Composable
    private fun NameUI(name: String, onNameChange: (String) -> Unit) {
        TextField(value = name, onValueChange = onNameChange)
    }
    
    @Composable
    private fun AgeUI(age: Int, onAgeChange: (Int) -> Unit) {
        TextField(value = age.toString(), onValueChange = { onAgeChange(it.toInt()) })
    }
    ✅ 1
    s
    a
    g
    • 4
    • 5
Powered by Linen
Title
k

kotlinforandroid

06/25/2022, 1:32 PM
Is compose smart enough to only re-compose UI elements that use fields from a data class that are partially updated? In the example below, if I change the username in the
TextField
does compose only update
NameUI
or does it also re-compose
AgeUI
since state updated and it includes the value for
AgeUI
.
private data class State(
    var name: String = "",
    var age: Int = 0,
)

@Composable
fun UI() {
    val state = remember { State() }

    NameUI(name = state.name, onNameChange = { state.name = it })
    AgeUI(age = state.age, onAgeChange = { state.age = it })
}

@Composable
private fun NameUI(name: String, onNameChange: (String) -> Unit) {
    TextField(value = name, onValueChange = onNameChange)
}

@Composable
private fun AgeUI(age: Int, onAgeChange: (Int) -> Unit) {
    TextField(value = age.toString(), onValueChange = { onAgeChange(it.toInt()) })
}
✅ 1
s

ste

06/25/2022, 2:42 PM
You need to make both
name
and
age
a
MutableState
first. After doing so, the answer is yes, e.g.
AgeUI
wont't recompose if
name
changes (
UI
and
NameUI
will), because it doesn't read
name
and it's
Stable
:kotlin-intensifies-purple: 2
✅ 2
However, you can verify the recompositions yourself using the layout inspector provided by android studio electric eel
👀 2
k

kotlinforandroid

06/25/2022, 3:00 PM
Thanks!
a

Advitiay Anand

06/26/2022, 6:59 AM
As ste said, the fields need to be MutableState so that they can recompose their composable. What I'm curious about is whether placing MutableState fields inside a data class is a good practice or not. Are such data classes restricted to be used in only compose? Are there any other common issues?
g

Grégory Lureau

06/27/2022, 7:39 AM
Also is recomposition means relayout and rerender ? If the Compose tree is partially recomputed but only one textview is invalidated/redrawn, then it's a question of UI hyper-performance vs code simplicity (for a case where a data class contains just a few fields that doesn't change every seconds).
👀 1
View count: 4