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

    Anastasia Rozovskaya

    09/20/2021, 10:27 AM
    Hi! What do you do when you need to use colors inside a mapper, which is injected to your viewModel via DI? I’ll provide details in a thread below
    c
    j
    9 replies · 3 participants
  • m

    Michal

    09/20/2021, 12:21 PM
    Have you experienced Compose memory leaks? When adding google maps (which had/maybe still has memory leaks in the view system), it will leak memory which adds up and app will be killed by system. I have found https://android-review.googlesource.com/c/platform/frameworks/support/+/1826246 which might be fixing the issue. How do I find out when this will be released?
    👀 2
    🔥 1
    z
    1 reply · 2 participants
  • z

    Zoltan Demant

    09/20/2021, 2:24 PM
    When using a
    Box
    that renders an arc with
    Canvas
    and a centered `Text`; why is the
    Box
    sizing wrong if contentAlignment is set to center? 🧵
    z
    s
    13 replies · 3 participants
  • b

    Bradleycorn

    09/20/2021, 2:56 PM
    when writing a
    @Preview
    composable, is there any way to get it to render a piece of UI with focus applied? I tried adding a
    FocusRequester
    and using a
    LaunchedEffect
    in the preview to request focus, but that doesn’t seem to work in the preview.
    l
    3 replies · 2 participants
  • n

    Napa Ram

    09/20/2021, 2:57 PM
    Hi Team, is it good to have multiple NavHost in one project
    t
    1 reply · 2 participants
  • s

    Susheel

    09/20/2021, 3:56 PM
    I heard that having R8 disabled will have a significant impact on Compose Render time. I was just reading this article about it. I was just wondering if Google recommends to enable R8 for compose?
    :yes: 5
    a
    k
    +1
    7 replies · 4 participants
  • t

    theapache64

    09/20/2021, 4:43 PM
    ✨ Animation API As per my understanding,
    MutableTransitionState
    (MTS) with
    updateTransition
    is only useful if we want to update the state within the composable. If we simply want to access the
    MTS#currentState
    ,
    MTS#targetState
    and
    MTS#isIdle
    , we can use
    Transition#currentState
    ,
    Transition#targetState
    and
    Transition#isRunning
    respectively. Please correct me if am wrong.
    d
    4 replies · 2 participants
  • e

    Ernestas

    09/20/2021, 5:55 PM
    Hi guys, I’ve just started experimenting with Compose. Any ideas how to go about implementing something like iOS calendar with Compose (the timeline on the left, and events constrained to specific times)? ConstraintLayout, custom view, something else? (picture in thread)
    c
    6 replies · 2 participants
  • p

    Piotr Prus

    09/20/2021, 7:26 PM
    I am trying to make a square card with items horizontally aligned in center, thats size is dynamic, base on the content. In my case, the height is always the leading(higher) value. It is not possible to measure twice, so I am trying to use the
    IntrinsicSize
    and
    layout.measure
    , but I cannot make it work. I managed to have a square card, but items are not in center. More in thread 👇
    5 replies · 1 participant
  • b

    Bradleycorn

    09/20/2021, 7:47 PM
    Question about
    TextField
    value and State. Can someone explain why, given the following composable:
    var text by remember { mutableStateOf("") }
    TextField(
        value = text,
        onValueChange = { newText ->
            Log.d("TEXTFIELD", "NewText: $newText")
            val editedText = newText.replace(Regex("\\D"), "")
            if (editedText.startsWith("1"))
                text = editedText
        }
    )
    If I type the number 5 into the text field four times, the result I see in LogCat is:
    D/TEXTFIELD: NewText: 5
    D/TEXTFIELD: NewText: 5
    D/TEXTFIELD: NewText: 55
    D/TEXTFIELD: NewText: 5
    I’m stumped?
    🧵 1
    s
    s
    +1
    28 replies · 4 participants
  • i

    itnoles

    09/21/2021, 12:38 AM
    So Kotlin 1.5.31 isn't compatible?
    d
    h
    +1
    5 replies · 4 participants
  • d

    dambakk

    09/21/2021, 8:18 AM
    Hi! 👋 Testing + AnimatedNavController I want to test a composable that has its own navigation. I pass in an instance of
    TestNavHostController
    as
    NavHostController
    parameter (defaults to
    rememberAnimatedNavController
    ) but get an exception when the building the navgraph:
    androidx.navigation.testing.TestNavigatorProvider$navigator$1 cannot be cast to com.google.accompanist.navigation.animation.AnimatedComposeNavigator
      at com.google.accompanist.navigation.animation.NavGraphBuilderKt.composable(NavGraphBuilder.kt:124)
    Doesnt the accompanist nav animation lib support testing yet? (code in 🧵)
    ✅ 1
    2 replies · 1 participant
  • a

    Akram Bensalem

    09/21/2021, 8:39 AM
    Hi, I integrate Google Map in one of Compose Screen but it's freeze for a bit of time, Is there any solution to prevent blocking the UI ? the freezing is because I use :
    val mapView = rememberMapViewWithLifecycle()
    b
    6 replies · 2 participants
  • r

    Roman Polach

    09/21/2021, 10:11 AM
    Hi. Is there alternative for BulletSpan in Compose? In SpanStyle, it seems, there is not parameter for this
    f
    z
    2 replies · 3 participants
  • o

    Orhan Tozan

    09/21/2021, 10:27 AM
    Getting this build error: `e: This version (1.0.2) of the Compose Compiler requires Kotlin version 1.5.21 but you appear to be using Kotlin version 1.5.30 which is not known to be compatible. Please fix your configuration (or
    suppressKotlinVersionCompatibilityCheck
    but don't say I didn't warn you!).` while my kotlin version is currently at 1.5.21, with this in my root gradle file:
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
    1 reply · 1 participant
  • j

    Jakub Doležal

    09/21/2021, 11:23 AM
    Hi, I have difficulties with
    ModalBottomSheetLayout
    . Clicking on
    Scrim
    area above the modal doesn't close it. According to a documentation a click should close it. Can you please confirm this is a bug?
    c
    3 replies · 2 participants
  • j

    Joey

    09/21/2021, 11:46 AM
    Is it possible to somehow change the minimum tab size of ScrollableTabRow which is currently linked to a private val called
    ScrollableTabRowMinimumTabWidth
    ? Or do I have to copy the full implementation to make this change?
    r
    4 replies · 2 participants
  • l

    Lilly

    09/21/2021, 3:10 PM
    [SOLVED] I try to share a FAB between the content of multiple Tab items but I'm struggling. Can someone help?
    Unbenannt.kt
    2 replies · 1 participant
  • m

    Michał Diner

    09/21/2021, 4:05 PM
    Why passing
    content: @Composable ColumnScope.() -> Unit
    in
    content: @Composable () -> Unit
    and invoking it in
    AnimatedVisibility(...) {
       content()
    }
    Cancels the ColumnScope?
    d
    1 reply · 2 participants
  • c

    carbaj0

    09/21/2021, 4:28 PM
    there are a way to "clear" a rememberLazyListState(). I want clear the state only when i perform an action, the rest of the time i want to hold the state.
    b
    d
    8 replies · 3 participants
  • a

    Ash

    09/21/2021, 11:51 PM
    think missing something. AS can't render Compose preview with CameraX Preview.🧵
    a
    r
    +1
    12 replies · 4 participants
  • o

    OG

    09/22/2021, 5:31 AM
    Hello everyone 👋 I think I've spent ~30 hours now over 3 days trying to figure out what is going on with this insanely weird compose issue. I was hoping I could share the nightmare I've found myself in and see if anyone would mind playing rubber duck here to help me get more ideas on how to tackle the problem. At a high level, here's what's going on. I work in 3 different android projects. Project 1 and Project 2 are working properly with compose and I'm migrating more and more of UI to compose and everything works flawlessly. I just added the exact same compose dependencies to project 3 and found that what I am seeing in Compose Preview is broken when I run the code in an emulator or real device. I stashed all my compose work and just made a simple screen that has a Column with verticalScroll that just loops 40 times and renders a Text component. When I deploy this code, the column DOES NOT scroll. I take this EXACT same code and copy it to Project 1 and 2, deploy, and I'm able to scroll the Column. Other things don't work as well such as clipping a Custom Shape etc but I'm positive all the issues are related. So I am just focusing on getting the simple Column with vertical scrolling to work. What. The. $@#!. Right? I'll post some of my notes/findings/additional info in thread for anyone curious or who may have insight. I sincerely apologize for the long message in this channel and really have tried avoiding bothering anyone with this as I'm trying to figure it out but I really am losing my mind at this point...
    d
    u
    +2
    28 replies · 5 participants
  • j

    james

    09/22/2021, 6:53 AM
    Should it be possible to use the interop layer of compose to use a ComposeView in ReactNative?
    z
    3 replies · 2 participants
  • j

    Joey

    09/22/2021, 7:11 AM
    In LazyColumn, is there a simple way to scroll to an item based on the key? Or do I have to keep a list of indices somewhere and use that to scroll to specific items?
    z
    2 replies · 2 participants
  • l

    Luka

    09/22/2021, 12:09 PM
    How to create button without rounded corners (can it be done without specifying border with 0.dp width)?
    p
    2 replies · 2 participants
  • c

    Cicero

    09/22/2021, 1:03 PM
    Something really unusual happened to me and I don't know where to start looking
    🆗 1
    6 replies · 1 participant
  • r

    rajesh

    09/22/2021, 2:49 PM
    My drawable resources are not displaying in original color in composable view. Color change to black (maybe due to app theme). How do I retain original view for drawable? Anything related to composition local?
    s
    s
    +1
    6 replies · 4 participants
  • o

    orangy

    09/22/2021, 3:20 PM
    I don’t quite understand relations between State<T> and Transition<T> and how to make a “composable” animations. Let’s say I have this simple data class:
    data class ShapeStroke(val width: Dp, val color: Color)
    I want to write a function
    fun <S> Transition<S>.animateShapeStroke() : State<ShapeStroke>
    so that it would just add child animations for width and color and return
    State<ShapeStroke>
    instance. What’s proper way to do this?
    z
    2 replies · 2 participants
  • a

    Alexa_Gal

    09/22/2021, 7:10 PM
    Hi guys 👩‍💻 looking for some testing advices i want to create my first
    androidTest
    and im having some problems trying to mock the ViewController of my view, maybe im doing something working but i would like to test only the view without the view controller (i already have the Unit test for my view controller) how would you do it using hilt and compose-navigation (
    HiltAndroidTest
    )
    p
    10 replies · 2 participants
  • i

    Ink

    09/22/2021, 9:19 PM
    Hi guys Why this text is not in the center? When I set
    defaultMinSize
    to e.g. 40.dp it looks good but I don't want that big Code in thread:
    c
    c
    +3
    16 replies · 6 participants
Powered by Linen
Title
i

Ink

09/22/2021, 9:19 PM
Hi guys Why this text is not in the center? When I set
defaultMinSize
to e.g. 40.dp it looks good but I don't want that big Code in thread:
c

Chris Johnson

09/22/2021, 9:31 PM
I would honestly just draw this with a canvas. It'd be 100000x easier.
c

Colton Idle

09/22/2021, 9:37 PM
@Ink can you edit your post to put the code in this thread please? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1616265877303000
👍 2
🙏🏻 1
c

Chris Sinco [G]

09/22/2021, 9:40 PM
Is there a reason you are using custom layout to place the number? This should just work with
contentAlignment = Alignment.Center
on the
Box
Composable
i

Ink

09/22/2021, 9:42 PM
Box(contentAlignment= Alignment.Center,
        modifier = Modifier
            .background(Color.Black, shape = CircleShape)
            .layout(){ measurable, constraints ->
                val placeable = measurable.measure(constraints)

                //get the current max dimension to assign width=height
                val currentHeight = placeable.height
                var heightCircle = currentHeight
                if (placeable.width > heightCircle)
                    heightCircle = placeable.width

                //assign the dimension and the center position
                layout(heightCircle, heightCircle) {
                    // Where the composable gets placed
                    placeable.placeRelative(0, (heightCircle-currentHeight)/2)
                }
            }) {

        Text(
            text = questionIndex.toString(),
            textAlign = TextAlign.Center,
            color = Color.White,
            modifier = Modifier.defaultMinSize(20.dp) //Use a min size for short text.
        )
    }

    Text(
        text = question.question,
        fontFamily = DefaultFont,
        fontWeight = FontWeight.Normal,
        fontSize = 16.sp,
        color = Color(0xFF1E1E1E),
        modifier = Modifier.padding(start = 10.dp)
    )
}
@Chris Sinco [G] There is no reason, I am just looking for the simplest solution
@Colton Idle How Can I draw Text inside that circle?
Canvas(modifier = Modifier.size(100.dp), onDraw = {
    drawCircle(color = Color.Red)
})
c

Chris Sinco [G]

09/22/2021, 9:46 PM
I see - contentAlignment is the simplest solution. Is that not working?
i

Ink

09/22/2021, 9:48 PM
It works when defaultMinSize is bigger than 30.dp but I don't want that big size
c

Chris Sinco [G]

09/22/2021, 9:50 PM
The Box is sized to content, unless you explicitly use a width/height/size modifier
So if you want a perfect circle, I’d set the size to something, e.g. 100.dp
This code
@Preview
@Composable
fun SlackTest() {
    Box(
        contentAlignment= Alignment.Center,
        modifier = Modifier
            .background(Color.Black, shape = CircleShape)
            .size(20.dp)
    ) {
        Text(
            text = "1",
            textAlign = TextAlign.Center,
            color = Color.White,
        )
    }
}
produces this
👍 3
i

Ink

09/22/2021, 9:56 PM
Works fine. Thank you
c

Chris Sinco [G]

09/22/2021, 9:56 PM
If you really want to use
Canvas
to do it, you can use
drawText
j

Jeff

09/23/2021, 12:59 PM
Will this accommodate larger text like 99+
c

Chris Sinco [G]

09/23/2021, 6:33 PM
Likely not so you'd have to either change the text size or circle size on that condition
t

Tin Tran

09/24/2021, 8:28 AM
You can use padding on the text instead of setting fixed size on the box
View count: 3