https://kotlinlang.org logo
Docs
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

    Sam

    10/26/2022, 8:50 PM
    Hi folks, I’m drawing an image at “wider than full screen width”, but then panning it to the left as the user swipes in a ViewPager. However, the image gets cut off on the right once the negative offset is applied. Is there a quick way to prevent this?
    m
    2 replies · 2 participants
  • u

    ursus

    10/26/2022, 8:57 PM
    Hey, is there a know bug where the
    onX
    colors have some sort of weird tint when used implcitly? I have a parent surface whose color is set to
    MaterialTheme.colors.primary
    , and then just a simple
    Text
    where its inferred text color should be
    onPrimary
    and it some off-white, when it should be pure white
    If I have another
    Text
    on top of it which color explicitly set to
    onPrimary
    then it is white as it should. compose version 1.2.1
    Snippet in the thread
    f
    m
    19 replies · 3 participants
  • p

    PHondogo

    10/26/2022, 9:03 PM
    Hello! How to propagate detectTapGestures events to parent elements?
    j
    1 reply · 2 participants
  • r

    Ryan Smith

    10/27/2022, 2:03 AM
    Hi all, I'm x-posting this from #compose-desktop since it's relatively generic to get a little more exposure. Could anyone try to help me understand something with
    Flow
    and
    Compose
    ? One of the predominant lessons I've been learning is "make your composables stateless by hoisting". I'm trying to adhere to this by exposing as much state as makes sense through properties on my view models. For example, my data layer has an in-memory Repository that exposes a collection of items through a
    Flow
    . My view model is meant to
    collect
    that flow as state, and expose that state to my
    Table
    composable to be displayed on the screen. But since
    collectAsState
    is marked as
    @Composable
    I can't call it from my view model. As I see it I could either pass the
    Flow
    directly through my view model to my
    Table
    composable or stick with
    mutableStateOf
    and collect the
    Flow
    internally to the view model and just expose the
    MutableState
    to my
    Table
    . More generally, though, it feels like the two ideas "state through the view model" and "collectAsState is Composable-only" are at odds here, which makes me think there's "the way" to do this sort of thing that I'm not seeing right now.
    b
    m
    6 replies · 3 participants
  • z

    zt

    10/27/2022, 3:18 AM
    I have a LazyColumn in my UI that I want to become a LazyRow when the device is in landscape mode, the easy solution is just copy and paste the code but use LazyRow instead of LazyColumn, but there's probably a more optimized solution for this type of problem. Any ideas?
    a
    j
    2 replies · 3 participants
  • z

    zt

    10/27/2022, 3:23 AM
    How can I make it so pressing the enter key produces the same behavior as pressing the IME action on the on-screen keyboard?
    m
    z
    3 replies · 3 participants
  • z

    Zoltan Demant

    10/27/2022, 5:17 AM
    When using downloadable fonts, theres a slight delay before the downloaded font shows up. This looks odd, but Ive managed to work around it by using
    FontFamily.Resolver.preload(...)
    and only showing my content after the call finishes. Is this a really bad idea? Considering cases where the user has no/bad connectivity, etc. Would I potentially be blocking them from accessing my app for a long time? And if thats the case, is there an alternative?
    a
    s
    3 replies · 3 participants
  • d

    dambakk

    10/27/2022, 5:41 AM
    I've made this component using SubcomposeLayout. How would I implement a good talkback experience for it? By default it iterates left to right on each row, but top to bottom on each column and then right would be better, and reading out a whole column at a time would be even better. I see that the semantics docs uses a calendar as example but does not give any further guidance on how to properly implement semantics for such complex composables.
    j
    2 replies · 2 participants
  • h

    Hasan Nagizade

    10/27/2022, 5:45 AM
    how to clear backstack with navigation compose library?
    m
    e
    +1
    5 replies · 4 participants
  • s

    svenjacobs

    10/27/2022, 7:29 AM
    Hello, what is the best “Compose way” to repeat an animation just a specific number of times? For instance I want to highlight a specific item on my screen by shortly flashing the background. Would the following (pseudo) code be okay or are there any better solutions?
    enum class BackgroundState { Normal, Highlighted }
    
    @Composable
    fun Item() {
        var backgroundState by remember { mutableStateOf(BackgroundState.Normal) }
        val backgroundColor by animateColorAsState(
            targetValue = when (backgroundState) {
                BackgroundState.Normal -> Color.Transparent
                BackgroundState.Highlighted -> Color.Yellow
            },
            animationSpec = tween(),
        )
    
        LaunchedEffect(Unit) {
            delay(250)
            backgroundState = BackgroundState.Highlighted
            delay(250)
            backgroundState = BackgroundState.Normal
            delay(250)
            backgroundState = BackgroundState.Highlighted
            delay(250)
            backgroundState = BackgroundState.Normal
        }
    
        Box(modifier = Modifier.background(backgroundColor)) {
            Text("Hello World")
        }
    }
    Thanks for your help!
    y
    f
    +2
    13 replies · 5 participants
  • r

    rcd27

    10/27/2022, 9:36 AM
    Hello, guys. The idea is to implement some kind of interactive onboarding flow: to highlight different buttons/fields/etc right on the screen, making the background darker (for example). Any thoughts/examples about that? Can we get constraints of a particular Compose element (x,y,width,height) from the parent?
    z
    c
    4 replies · 3 participants
  • j

    Jasmin Fajkic

    10/27/2022, 9:42 AM
    I have scrollable tab row. Need to put loading indicator full width bellow it. Is this achievable?
    o
    10 replies · 2 participants
  • h

    Hassaan

    10/27/2022, 11:26 AM
    my first day in compose, so bear with me. There are two ways to alter color or size of text, first by directly using Text parameters and second by using TextStyle parameters, how do they differ or what type should we use often to set color or textSize ? eg in the below given code snippet i have set fontsize twice:
    Text(
        text = "Hello world!",
        fontSize = 44.sp, // ist time
        style = TextStyle(
            fontSize = 24.sp,  // ist time
            shadow = Shadow(
                color = Color.Magenta,
                offset = offset,
                blurRadius = 3f
            )
        )
    )
    s
    p
    +2
    6 replies · 5 participants
  • d

    dambakk

    10/27/2022, 1:11 PM
    What do I use the SemanticsProperty indexForKey for? What effect does it have?
    b
    2 replies · 2 participants
  • a

    andrew

    10/27/2022, 2:20 PM
    3 years ago!! w/ compose!
    device-2019-10-27-191915.mp4
  • p

    Pedro Alberto

    10/27/2022, 2:29 PM
    Is there a way to not resize the button content when we simply place a CirculerProgress inside ?
    s
    c
    32 replies · 3 participants
  • l

    Luis Daivid

    10/27/2022, 2:51 PM
    I’m trying to make a new app with maps. I’m even thinking about actual distribution. Is it ok to implement with 100% compose? In other apps being developed by the company, it has not been completely converted due to compose navigation.
    c
    s
    +1
    5 replies · 4 participants
  • j

    Jasmin Fajkic

    10/27/2022, 3:36 PM
    Hey guys do you use paging library if you have long list with load more or jetpack compose own implementation? I hit a little bit wall as i have quite simple task that starts to be hard with paging library. I create new post in app and need to add it on top of list. Very simple. And with paging lib it seems it is not easy at all
    i
    7 replies · 2 participants
  • z

    zt

    10/27/2022, 5:01 PM
    I wanna make my compose app more user friendly on android tv, is there a way to get my UI to layout slightly different, and be able to check in code if it's running on TV so I can show stuff thats not needed on mobile?
    a
    c
    +1
    50 replies · 4 participants
  • e

    efemoney

    10/27/2022, 8:09 PM
    How would I scroll to an item in a lazy list by key? I don’t have the item index unfortunately. My current (bad) idea I’m toying with is copying the entirety of
    LazyListState.animateScrollToItem
    and making _modifications_™️ but that method will take me a ‘minute’ to understand enough to update.
    m
    2 replies · 2 participants
  • c

    chatterInDaSkull

    10/27/2022, 10:41 PM
    In compose testing, how does one assert for text color? This answer works but seems slightly old and can’t find somethign newer
    o
    1 reply · 2 participants
  • x

    xxfast

    10/27/2022, 11:50 PM
    Hi all. Trying to use interop with a pre-written
    RecyclerView
    within a
    @Composable
    like this
    @Composable
    fun ComposeRecyclerView(items: Items) {
      
      val adapter: RecyclerView.Adapter by remember { mutableStateOf( RecyclerView.Adapter()) }
    
      AndroidView(
        modifier = Modifier.fillMaxSize(),
        factory = { context -> RecyclerView(context) },
        update = { recyclerView ->
          if (recyclerView.adapter == null) {
            recyclerView.adapter = adapter
            recyclerView.adapter?.stateRestorationPolicy =
              RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY
          }
      
          adapter.set(animatedState.items)
        }
      )
    }
    This doesn't seem to work. Is this the right way to use a legacy
    RecyclerView
    within Compose? Google is failing me because it keep showing me
    LazyColumn
    APIs which is not what I'm trying to achieve here 😅
    c
    b
    11 replies · 3 participants
  • z

    zt

    10/28/2022, 4:54 AM
    Using a selection container is it possible at all to only allow selecting the complete text and block partial selection? I'm displaying a code to the user, so it needs to be copied completely
  • k

    Kenneth Leong

    10/28/2022, 9:12 AM
    Are we supposed to use
    remember
    in a composable which observes a mutableState from a viewModel? e.g.
    val state = remember { viewModel.someState }
    p
    j
    2 replies · 3 participants
  • p

    PHondogo

    10/28/2022, 9:58 AM
    Hello! Does Stable annotation apply also on subclasses/subinterfaces? Or I need to annotate each subclass manually?
    s
    1 reply · 2 participants
  • d

    Daniele Segato

    10/28/2022, 12:58 PM
    I'm trying to create a modifier to "layout stuff vertically" EDIT: what I mean is: rotated 90 degree. But the composable take the space actually used (if you just rotate it takes the space as if you did not rotate it)
    fun Modifier.layoutVertically() =
        rotate(-90f).layout { measurable, constraints ->
            val swappedConstraints = constraints.copy(
                minWidth = constraints.minHeight,
                maxWidth = constraints.maxHeight,
                minHeight = constraints.minWidth,
                maxHeight = constraints.maxWidth,
            )
            val placeable = measurable.measure(swappedConstraints)
            layout(placeable.height, placeable.width) {
                placeable.place(
                    x = -(placeable.width / 2 - placeable.height / 2),
                    y = -(placeable.height / 2 - placeable.width / 2)
                )
            }
        }
    If I have a layout with this modifier inside I can't use Intrinsic sizing, I get this error:
    java.lang.IllegalArgumentException: Can't represent a size of 2147483515 in Constraints
    r
    5 replies · 2 participants
  • l

    Luis Daivid

    10/28/2022, 2:40 PM
    About the bottomBar, is there a way to avoid the view to recompose when switching between tabs ? Let’s say I have a BottomBar with Tab A being a list, and a Tab B being a mapView. In Tab A I scroll the list, then open Tab B and I move the map. Then switch to Tab A, I would like my list to have the position as it where before. Same if I go back to the mapView, I don’t want to lose the map moved by the user.
    p
    s
    6 replies · 3 participants
  • o

    orangy

    10/28/2022, 2:57 PM
    I wonder if there exists a list of videos and blogs that one should watch/read in order to understand Compose better? Preferably not very Android-centric, but rather how the whole Compose system works from snapshots and states, through groups to slot table, then to build LayoutNodes, and how to properly use it all. Not very deep, like compose compiler plugin, but also not very shallow.
    f
    j
    +4
    14 replies · 7 participants
  • i

    igor.wojda

    10/28/2022, 6:25 PM
    Hey I am struggling to apply
    Material You Dynamic Colors
    (Material You) across whole app. They are working for the
    BottomNavBar
    (in the Activity) but not for the Fragments content inside this Activity (see attached image) 🤔 I did:
    DynamicColors.applyToActivitiesIfAvailable(this)
    inside custom Application class
    onCreate
    method This is the Fragment code
    class FavouriteFragment : BaseFragment() {
    
        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            return ComposeView(requireContext()).apply {
                setContent {
                    FavouriteScreen()
                }
            }
        }
    }
    Here is my android-showcase project demonstrating this issue. Any idea why this may be happening? What am I missing here?
    a
    1 reply · 2 participants
  • r

    Rafs

    10/28/2022, 7:13 PM
    I am trying to create an icon that will fade into the screen for a few seconds and fade itself out. When the icon is replaced the previous one immediately disappears paving way for the new one to animate itself in and out. Here’s what I’ve come up with but I have a feeling there’s a better way of doing this. Code in 🧵
    f
    m
    7 replies · 3 participants
Powered by Linen
Title
r

Rafs

10/28/2022, 7:13 PM
I am trying to create an icon that will fade into the screen for a few seconds and fade itself out. When the icon is replaced the previous one immediately disappears paving way for the new one to animate itself in and out. Here’s what I’ve come up with but I have a feeling there’s a better way of doing this. Code in 🧵
/**
 *  This icon fades in and out after a delay whenever [icon] is changed
 *  but disappears immediately [icon] is replaced in the middle of an animation
 */
@Composable
private fun DisappearingIcon(
    icon: ImageVector,
    modifier: Modifier = Modifier,
    contentDescription: String,
    delay: Long
) {
    val alpha = Animatable(0f)

    val animationSpec = tween<Float>(500)

    LaunchedEffect(icon) {
        alpha.animateTo(1f, animationSpec = animationSpec)
        delay(delay)
        alpha.animateTo(0f, animationSpec = animationSpec)
    }

    Icon(
        imageVector = icon,
        modifier = modifier
            .graphicsLayer {
                this.alpha = alpha.value
            },
        contentDescription = contentDescription
    )
}
f

Francesc

10/28/2022, 7:30 PM
looks like you could use
Crossfade
https://foso.github.io/Jetpack-Compose-Playground/animation/crossfade/
sorry, I sent to channel by mistake, didn't intend to
r

Rafs

10/28/2022, 7:39 PM
I don’t want to crossfade all the time. I want to preempt the currently running animation when a new icon arrives midway.
m

mattinger

10/29/2022, 2:56 AM
I don't see anything wrong with what you are doing here. I think i prefer to use the animate function instead:
var alpha by remember { mutableStateOf(0f) }

LaunchedEffect(icon) {
    animate(
        initialValue = 0f,
        targetValue = 1f,
        animationSpec = tween(500)
    ) { value: Float, _: Float ->
        alpha = value
    }

    delay(delay)

    animate(
        initialValue = 1f,
        targetValue = 0f,
        animationSpec = tween(500)
    ) { value: Float, _: Float ->
        alpha = value
    }

}
But if you're going to use Animatable, you should probably put it in a remember.
i don't know if there's an advantage of your approach over mine, but either way I think is reasonable.
r

Rafs

10/29/2022, 7:09 AM
Is the
animate
function new cos I’ve never seen it before. It looks very clean, I’ll try that out
View count: 12