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

    andrew

    03/07/2022, 12:40 AM
    Some updates on the compose rewrite of an app from work 🤭🤭
    22-03-06-19-35-51.mp4
    👍🏼 1
    👍 4
    🎉 6
    🙌🏼 2
    :jetpack-compose: 10
    🙌 5
    s
    k
    +4
    • 7
    • 20
  • t

    Tash

    03/07/2022, 4:17 AM
    Trying to draw
    Text
    with a horizontal gradient. After much trial and error, found that this works only if I specify
    alpha = 0.99f
    in the
    graphicsLayer
    (output in 🧵) Can someone explain why? 😖
    Text(
        text = "$ 20",
        modifier = Modifier.graphicsLayer(alpha = 0.99f)
            .drawWithCache {
                val brush = Brush.horizontalGradient(listOf(StartColor, EndColor))
                onDrawWithContent {
                    drawContent()
                    drawRect(brush, blendMode = BlendMode.SrcAtop)
                }
            },
    )
    👍 1
    a
    c
    • 3
    • 6
  • m

    Mohan manu

    03/07/2022, 6:17 AM
    How do we do real time updates with jetpack compose? Example updating stock price of list of stocks in a list. Do we need to convert list to mutable list and change price each time we get a new price or is there any other ? Thanks in advance
    j
    z
    • 3
    • 2
  • r

    ritesh

    03/07/2022, 12:04 PM
    Is there any way to see compose generated code in IDE?
    👀 2
    g
    j
    • 3
    • 6
  • m

    mkrussel

    03/07/2022, 2:54 PM
    I'm looking at using
    VisualTransformation
    but the documentation for
    OffsetMapping
    is not clear. They value returned from
    originalToTransformed
    should be increasing or stay the same. So if I remove the second character the value would stay 0. What should I do if I remove the first character. Is that still 0 or is it -1?
    • 1
    • 1
  • s

    Stylianos Gakis

    03/07/2022, 3:49 PM
    I’m trying to create some UI in compose which I can’t get my head around how to do it, more in thread. 🧵
    t
    z
    t
    • 4
    • 8
  • j

    Jaime

    03/07/2022, 4:09 PM
    Hello everyone, I have a question, I am uploading the version of compose to 1.1.0 but it is generating errors when compiling with compileSdkVersion 30
    The minCompileSdk (31) specified in a
    dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
    is greater than this module's compileSdkVersion (android-30).
    Dependency: androidx.compose.ui:ui-tooling:1.1.0-rc01.
    AAR metadata file: /Users/mac/.gradle/caches/transforms-3/b8977160c1c83bc23bb78b40a0700549/transformed/jetified-ui-tooling-1.1.0-rc01/META-INF/com/android/build/gradle/aar-metadata.properties.
    s
    • 2
    • 10
  • s

    Stylianos Gakis

    03/07/2022, 5:01 PM
    If I am doing a
    Layout {}
    which may accept arbitrary composable slots, and I want to be able to add a modifier to them to add a
    layoutId
    how would I go around doing that?
    a
    • 2
    • 15
  • r

    Ryan Casler

    03/07/2022, 5:46 PM
    Using compose on Android and I can not find this in the docs any where. Had an issue where a
    Text
    composable was not getting
    MaterialTheme
    colors unless it is also wrapped in a
    Scaffold
    as shown below. Does that sound right that you need
    Scaffold
    with the
    MaterialTheme
    to get the colors to work or do i have a config issue somewhere?
    // Does not get theme colors
    MaterialTheme { Text("test") }
    
    // Gets theme colors
    MaterialTheme { Scaffold { Text("Test") } }
    c
    s
    • 3
    • 6
  • m

    mattinger

    03/07/2022, 6:47 PM
    Hi All. Looking to to create a Lazy Column where the header scrolls with the content, but there is a border only around the actual items themselves. I’ve seen some stuff about using drawWithContent and clipping, but this seems like a large amount of effort to accomplish a basic pattern.
    c
    • 2
    • 11
  • l

    Leon

    03/07/2022, 7:16 PM
    Hey all, I have this weird problem that I think might be a bug but I can't be sure. I have this
    BasicTextField
    that has a visual transformation applied to it that transforms
    # Title
    to
    Title
    and changes the size of the text (markdown). It constructs a
    TransformedText
    object with an
    OffsetMapping
    to account for the 2 characters that have been removed. However there seems to be a bug because when I type in
    # Title
    it gets transformed to
    Title
    in the text field however when I move the cursor using the arrow keys to the end of the line the application crashes with an out of bounds error. I traced this down and it looks like its an issue with the
    isLtr()
    function as it uses
    selection.end
    without performing a
    OffsetMapping
    conversion on it.
    // TextPreparedSelection.kt
    
        private fun isLtr(): Boolean {
            val direction = layoutResult?.getParagraphDirection(selection.end)
            return direction != ResolvedTextDirection.Rtl
        }
    Any ideas on how I could resolve this issue?
    👍 1
    m
    z
    z
    • 4
    • 6
  • a

    Alexjlockwood

    03/07/2022, 7:52 PM
    say i have a column like this:
    Column(Modifier.wrapContentHeight()) {
        Box(Modifier.fillMaxWidth().weight(1f).background(Color.Red)) { ... }
        Box(Modifier.fillMaxWidth().height(100.dp).background(Color.Blue)) { ... }
    }
    i was expecting the
    Modifier.wrapContentHeight()
    to compress the
    weight(1f)
    down such that both of the inner boxes would simply wrap their own content (since this was how it worked with vertical linear layouts). but i found that the
    weight(1f)
    still caused the
    Column
    to expand to fill its maximum height regardless. basically i’m wondering if there is a way for me to control whether the
    weight(1f)
    expands or not simply by passing a modifier to the parent `Column`… my current workaround is adding a
    fillMaxHeight: Boolean
    parameter to my composable function to decide whether or not the
    weight(1f)
    is applied but it felt kind of dirty
    a
    • 2
    • 1
  • r

    ritesh

    03/08/2022, 3:53 AM
    Considering a case of
    LazyColumn
    - let's say i have a conditional statement inside my composable - which can end up making a structural change
    if(loading) {
     // ShowLoader 
    } else { 
      LazyColumn {}
    }
    Every-time there is a
    State<>
    mutation of
    loading
    being
    false
    or
    true
    compose compiler will wipe away(remove it from the composition tree) and re-add it again and
    LazyColumn
    can end up composing it's all items again. One simple scenario could be - when clicked on item to delete •
    isLoading
    is set to true, removing
    LazyColumn
    from the composition tree • once any item is updated (say a server call!), when
    isLoading
    is set to false,
    LazyColumn
    gets added again This is mostly an anti-pattern i believe and i am ending up losing the
    LazyColumn
    Positional with key Memoization
    capability in this case and in scenarios like this, this should not be part of a conditional logic?
    z
    z
    • 3
    • 4
  • a

    allan.conda

    03/08/2022, 5:33 AM
    How can we scroll to a specific composable in a
    Column
    ? For example, upon TextField error, or upon focusing on one. I’m not sure if we really have to manually compute the pixels to achieve this. Wasn’t able to find existing info here.
    z
    • 2
    • 1
  • p

    prudhvi reddy

    03/08/2022, 6:24 AM
    Hi. I am trying to implement a screen with multiple tabs (accompanist - pager) so i did something like this:
    @Composable
    fun Screen() {
      val screenViewModel: ScreenViewModel = hiltViewModel()
      val pages by screenViewModel.pages.collectAsState()
      val pagerState = rememberPagerState(pageCount = pages.size)
    
      HorizontalPager(state = pagerState) { index ->
        Column(modifier = Modifier.fillMaxWidth()) {
          // this viewmodel should be created with data from the page object (e.g. id)
          val pagerViewModel: PagerViewModel = hiltViewModel() // actual: same viewmodel on every page -> expected: every page get´s its own viewmodel
          ...
        }
      }
    }
    Is it possible to get a ViewModel per page via hilt or should i use a complete different approach than ViewModels in this case?
    b
    • 2
    • 1
  • s

    Stylianos Gakis

    03/08/2022, 12:37 PM
    Working with a custom
    Layout{}
    I wanted to have all children have the exact same height. But I only get once chance to measure all of them and giving them constraints. Optimally I’d like to get a measurement of all of them, get the max height among them and have them all measure with the constraints to exactly match that height. This feels like one of the things that intrinsic layouts should be achieving, but I am not quite sure how to use intrinsics in my custom
    Layout {}
    measurePolicy
    . Any ideas of what I’m missing or an example I could look at? Currently starting off by doing something like but I can’t quite find what I want to do instead:
    Layout(
        content = content
    ) { measurables, constraints ->
        val width = (constraints.maxWidth / 2) - (horizontalSpacingInPx / 2) // I am placing 2 side by side
        val height = measurables.maxOf { it.maxIntrinsicHeight(width) } // What would I do here instead
        val placeables = measurables.map { measurable ->
            val halfWidthAndIntrinsicMaxHeightConstraint = constraints.copy(
                minHeight = height,
                maxHeight = height,
                maxWidth = width,
                minWidth = width
            )
            measurable.measure(halfWidthAndIntrinsicMaxHeightConstraint)
        }
    a
    t
    +2
    • 5
    • 12
  • m

    mattinger

    03/08/2022, 3:36 PM
    So i’m working with a layout that is drawing a custom progress ring animation. I’m having trouble figuring out how to give it an intrinsic size so that until a specific size is give, or it’s give a fillMaxWidth/FillMaxSize, it will use that size:
    BoxWithConstraints(
            modifier = modifier
                .defaultMinSize(RingDefaultMinSize, RingDefaultMinSize)
                .aspectRatio(RingAspectRatio)
                .padding(RingStrokeWidthOffset),
            contentAlignment = Alignment.Center
        ) {
            Canvas(modifier = Modifier.size(constraints.maxWidth.dp, constraints.maxHeight.dp)) {
                drawArc(
                    color = ringColor,
                    startAngle = rotation.value,
                    sweepAngle = -1f * sweepAngle.value,
                    useCenter = false,
                    style = Stroke(width = RingStrokeWidth.toPx(), cap = StrokeCap.Round)
                )
            }
        }
    The problem is that when i don’t specify any size, the Box is filling it’s entire parent. I know it’s due to my use of contraints.maxWidth, but i’m unsure how to properly figure out the size of the canvas based on the constraints.
    z
    c
    • 3
    • 6
  • a

    allan.conda

    03/08/2022, 5:06 PM
    about LazyPagingItems with
    Pager.flow.cachedIn(viewModelScope)
    I'm losing the loaded data when the last load State is Error even if I cache the flow to the Viewmodel. Let's say data is already rendered, I refresh and let it fail (turn off wifi). I go to the next screen. Now when coming back, previously loaded data is now gone and the latest loads state is error. If the latest loadstate is not error then the data is retained as I wanted. My requirement is to not clear the data if it failed to refresh. but my issue is that I lose it when navigating to another screen and going back. Is it a bug or is this expected? Also not sure if this is a Compose or Paging issue.
    • 1
    • 1
  • s

    Simon Stahl

    03/08/2022, 6:03 PM
    Reposting for visibility: is there a way to know what triggered a re-compose? If you have a complex page with many states, it gets really hard to figure out what triggered it.
    r
    c
    e
    • 4
    • 8
  • a

    andrew

    03/09/2022, 3:46 AM
    With RTL, does automirror work for vector drawables being painted in compose? I’m not seeing it forcing a config change on device, or using the LocalLayoutDirection local
    a
    c
    n
    • 4
    • 9
  • m

    Max Novikov

    03/09/2022, 5:16 AM
    Hi all! In our team we are implementing the first feature with Compose. There are ui End to End tests practice in project. When there are compose and view in one Activity we have problem with switching between Espresso and Compose matchers. It looks like compose keeps main thread.
    androidx.test.espresso.IdlingResourceTimeoutException: Wait for [Compose-Espresso link] to become idle timed out
    I created simple project to reproduce issues: https://github.com/Maksim-Novikov/ComposeUiTestsBug Just run EspressoComposeLinkTest. In real project problems arise when we go back from compose to view, but In sample it begins earlier. I found the only one similar problem, but it associated with infinity animation https://issuetracker.google.com/issues/160259537
    l
    z
    • 3
    • 5
  • s

    ste

    03/09/2022, 12:55 PM
    I have to execute async operations on button clicks. May be the following extension considered a bad practice?
    fun Modifier.clickable(
        context: CoroutineContext,
        enabled: Boolean = true,
        onClick: suspend CoroutineScope.() -> Unit
    ) = composed {
        val coroutineScope = rememberCoroutineScope()
        clickable(enabled = enabled) { coroutineScope.launch(context = context, block = onClick) }
    }
    e
    s
    e
    • 4
    • 13
  • d

    Daniele Segato

    03/09/2022, 5:11 PM
    Drag and Drop in Compose, the doc cover the dragging part but say nothing about the "dropping" part. Say you have an active area where you want to drop another content and you want to check if the item being dragged is on top of it.. Is there any better / recommended way than using
    Modifier.onGloballyPositioned
    on the source / target layouts and the drag offset to check if they are within bounds? Any API that makes the process easier? Maybe something like Flutter AnchorStrategy / DragTarget?
    z
    a
    t
    • 4
    • 8
  • a

    adjpd

    03/09/2022, 7:43 PM
    Is it possible to use any version of Compose with kotlin
    1.6.20
    ?
    s
    j
    • 3
    • 4
  • s

    Slackbot

    03/09/2022, 9:32 PM
    This message was deleted.
    j
    c
    • 3
    • 3
  • c

    Colton Idle

    03/09/2022, 9:44 PM
    Compose 1.2.0-alpha05 released today • Probably the biggest change is that
    includeFontPadding
    is turned off by default. Most of your layouts will look slightly different, but this is a welcome change IMO. Almost 18 months in the making =) • "Hooray! Compose animation now supports 'Animator duration scale' setting from Developer Options." • Bunch of things related to lazy grids 1.
    LazyVerticalGrid
    and
    LazyHorizontalGrid
    are now stable 2.
    LazyGridItemInfo.Unknown
    was replaced with separate
    LazyGridItemInfo.UnknownRow
    and
    LazyGridItemInfo.UnknownColumn
    3.`LazyVerticalGrid`/`LazyHorizontalGrid` and all related apis were moved into
    .grid
    subpackage. Please update your imports from
    androidx.compose.foundation.lazy
    to
    androidx.compose.foundation.lazy.grid
    •
    WindowInsets.toString()
    will now show the correct values. Read more here • Updated to use Kotlinx coroutines 1.6.0 • Bunch of things regarding focus 1. Added FocusGroup modifier 2. Modifier.onFocusedBoundsChanged Read more here • Update TextFieldsInScrollableDemo to enable toggling setDecorFitsSystemWindows. (happy to see more progress on text fields in a scrollable. I think we're getting close Zach!) •
    TextToolbar
    now takes lambda arguments instead of
    ActionCallback
    . • Updated nullability in core and appcompat to match Tiramisu DP2 •
    ComposeContentTestRule.setContent
    will now throw an
    IllegalStateException
    if you try to set content when there already is content.
    🙏 3
    ❤️ 13
    🙏🏼 1
    z
    a
    • 3
    • 2
  • a

    Alejandro Moya

    03/09/2022, 11:53 PM
    Hi all, quick question, tried to load downloadable fonts set on xml in the family font and got an error, leaving the stacktrace on the thread…
    c
    s
    • 3
    • 6
  • s

    Sam

    03/10/2022, 1:26 AM
    hi, just downloaded
    Android Studio Dolphin Canary 5
    and trying to use with
    Compose 1.2.0-alpha05
    , but receiving this ambiguous compile-time error:
    c
    z
    • 3
    • 10
  • t

    Todor Grudev

    03/10/2022, 7:52 AM
    Is there a build in way to achieve this (showing the error under the field, recommended by the material guidelines) with
    OutlinedTextField
    I did not manage to find one?

    https://i.stack.imgur.com/ptvLF.png▾

    p
    a
    • 3
    • 4
  • i

    Icyrockton

    03/10/2022, 8:25 AM
    https://stackoverflow.com/questions/71410351/jetpack-compose-nested-navigation-and-bottomappbar any solution with this?
    • 1
    • 1
Powered by Linen
Title
i

Icyrockton

03/10/2022, 8:25 AM
https://stackoverflow.com/questions/71410351/jetpack-compose-nested-navigation-and-bottomappbar any solution with this?
https://kotlinlang.slack.com/archives/CJLTWPH7S/p1627490432392100?thread_ts=1627477759.324500&amp;cid=CJLTWPH7S
View count: 4