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

    Jeff

    07/01/2021, 8:46 AM
    It's probably a simple one. What's the best way to achieve a squircle image using coil in compose. The image should have a placeholder with the initials of the user name.
    m
    b
    +2
    • 5
    • 14
  • m

    mmaillot

    07/01/2021, 12:53 PM
    I’m looking to detect if a view is other another view. I have a screen with 3 cards on the top and a placeholder at the bottom. The user can drag and drop a card in the placeholder. I didn’t find how to detect during the drag if my card is over the placeholder. Do you know a method to get this info ? Or the coordinate of the placeholder on the screen ?
    z
    • 2
    • 1
  • b

    brandonmcansh

    07/01/2021, 1:16 PM
    Having some issue getting a transition to animate, row has two main states - one with a full width button and one with two and a spacer. However the duration of the transition seems to be instantaneous and doesnt animate as I'd expect. Is there something Im missing? (Code in thread)
    :thread-please: 3
    h
    d
    • 3
    • 25
  • d

    dimsuz

    07/01/2021, 1:29 PM
    I'm writing a "custom" text field based on BasicTextField. I want to know if it's currently focused or not (to vary its UI based on this), what's the best way to do this? Add
    .onFocusChange
    modifier and set some
    State
    ?
    c
    • 2
    • 1
  • m

    miskalinn

    07/01/2021, 2:25 PM
    I'm new to Android Dev, learned enough kotlin to start a basic project. I'm confused about Jetpack and Compose. What's the difference? Can I start using compose?
    a
    c
    • 3
    • 4
  • d

    dimsuz

    07/01/2021, 2:26 PM
    What's the situation with broken `setValue`/`getValue` imports on
    State
    ? Is there some estimate when this will be fixed?
    j
    s
    • 3
    • 5
  • f

    FunkyMuse

    07/01/2021, 4:12 PM
    Hey guys, I'm trying to change the bottom sheet scaffold Z index so that the bottom sheet can be displayed over the bottom navigation view, after using accompanist insetter that's not the case anymore, the bottom sheet is displayed behind the bottom navigation ModalBottomSheetLayout for the first bottom navigation screen (code in thread)
    • 1
    • 1
  • v

    VM

    07/01/2021, 5:16 PM
    Compose v1.0.0-rc01 is here 😀
    🎉 35
    s
    c
    +6
    • 9
    • 10
  • t

    Tolriq

    07/01/2021, 5:58 PM
    Hum 😞 Seems there's some packaging issue 😞 IDE expect androidx.compose.ui.tooling.preview.ComposeViewAdapter for the previews but from RC01-sources.jar the ComposeViewAdapter is still in the normal ui.tooling package 😞
    e
    j
    +3
    • 6
    • 14
  • m

    Marko Novakovic

    07/01/2021, 6:10 PM
    am getting error for import
    androidx.compose.ui.res.animatedVectorResource
    . not found. did this got removed? can’t find another import
    c
    t
    • 3
    • 3
  • t

    Tolriq

    07/01/2021, 6:15 PM
    Ok so even after full cache invalidate and everything still
    The following classes could not be found:
    - androidx.compose.ui.tooling.preview.ComposeViewAdapter
    So the IDE (AGP 7.0.0 B4) still reference the previous package name. Will this require a new AGP / IDE build ?
    j
    c
    c
    • 4
    • 11
  • c

    Craig Citro

    07/01/2021, 6:44 PM
    With compose 1.0.0-rc01, i'm getting an error "Failed to resolve: ui-graphics-1.0.0-rc01". I haven't specified ui-graphics explicitly before today, and adding it didn't help
    👀 1
    y
    a
    +4
    • 7
    • 34
  • n

    Nat Strangerweather

    07/01/2021, 8:17 PM
    Is it possible in a LazyVerticalGrid to have a range of items rather than a count? For instance here:
    j
    a
    • 3
    • 7
  • j

    Jorge Cordero

    07/01/2021, 8:27 PM
    Does anybody know when the Google Associate Developer certification will include Compose or how can I get more information about this?
    c
    • 2
    • 2
  • o

    Orhan Tozan

    07/01/2021, 9:04 PM
    Users of LazyColumn, what's its performance compared to RecyclerView?
    y
    • 2
    • 1
  • r

    russhwolf

    07/01/2021, 11:00 PM
    Are there any built-ins to get a preview in landscape mode, or do you need to set the height and width manually?
    c
    • 2
    • 6
  • f

    Fabio

    07/02/2021, 2:48 AM
    since
    painterResource
    throws exception for some drawables and we can't write try/catch in
    @Composable
    functions, how can I work around not crashing my app?
    painterResource
    calls
    loadVectorResource
    who calls
    loadVectorResource
    private fun loadVectorResource(theme: Resources.Theme, res: Resources, id: Int): ImageVector {
        @Suppress("ResourceType") val parser = res.getXml(id)
        if (parser.seekToStartTag().name != "vector") {
            throw IllegalArgumentException(errorMessage)
        }
        return loadVectorResourceInner(theme, res, parser)
    }
    It crashes for an image such as this
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="<http://schemas.android.com/apk/res/android>">
    
    
        <item>
            <shape android:shape="oval">
                <solid android:color="@color/colorBardeenBrand" />
            </shape>
        </item>
    
    </layer-list>
    :thread-please: 3
    i
    c
    • 3
    • 9
  • t

    Tolriq

    07/02/2021, 5:26 AM
    So no solution for the preview ? 😞
    ❓ 2
    f
    a
    • 3
    • 6
  • t

    Tlaster

    07/02/2021, 7:54 AM
    Will drag&drop support for LazyColumn be included in stable 1.0?
    ➕ 1
    h
    a
    • 3
    • 2
  • t

    Tin Tran

    07/02/2021, 8:21 AM
    Hi! How do I make a
    Box
    height 2/3 of the parent box intrinsic height?
    c
    p
    c
    • 4
    • 10
  • m

    martinsumera

    07/02/2021, 8:23 AM
    I’m playing a little bit with remeberUpdatedState and I found some mechanisms that I do not fully understand. I have two composable functions. 1. The first one is using a mutableStateOf which is used within
    LaunchedEffect
    . When the state changes then the value of this state in the
    LaunchedEffect
    contains the correct updated value. 2. Second one is basically a refactoring of the first one but the state is moved outside of the composable and then is passed as the parameter. When the state change outside of the composable then the
    LaunchedEffect
    does not contain correct updated value but the initial value. I know that in the second case it can be fixed by using rememberUpdateState, but I do not understand why is this happening? Can somebody explain it to me please? The code samples are in the Thread
    a
    • 2
    • 3
  • t

    Tolriq

    07/02/2021, 9:01 AM
    Seems also the dialog change to full size was made experimental but as full size by default, breaking previous default value and require optin to experimental to return to normal status :(
    👀 1
    a
    l
    a
    • 4
    • 17
  • e

    Eric Ampire [MOD]

    07/02/2021, 11:00 AM
    Hello, after updating my project to compose rc01, every time I'm trying to run the preview I have this error, does anyone know how to fix that ?
    a
    • 2
    • 1
  • y

    Yuri Drigin

    07/02/2021, 11:44 AM
    Hi all! I just read about new class
    RelocationRequester
    and want to use it to scroll Column to focused TextField. Does anyone have example how to use it ?
    a
    • 2
    • 2
  • n

    Napa Ram

    07/02/2021, 12:48 PM
    Hello Everyone I am new in Compose today is my first day can anyone suggest me good blog, article or tutorials to get expret in Compose
    n
    • 2
    • 2
  • j

    julioromano

    07/02/2021, 2:18 PM
    How high should I hoist the value property of a
    BasicTextFiled
    ?
    More details in 🧵
    a
    c
    • 3
    • 7
  • d

    dimsuz

    07/02/2021, 2:23 PM
    Is there something like
    confirmStateChange
    for
    HorizontalPager
    planned? With bottom sheets I often use the pattern: 1. Sheet tells the State holder that it wants to change to e.g. Expanded 2. State holder decides whether to allow or disallow 3. State holder sets new state 4. Sheet uses that to run LaunchedEffect with animateTo(Expanded) Currently
    HorizontalPager
    provides no callback through which this can be done, it seems to change
    PagerState
    internally.
    • 1
    • 1
  • p

    Peter Mandeljc

    07/02/2021, 3:31 PM
    Why does Box take size of Surface?
    @Preview
    @Composable
    private fun Test() {
        Surface(
            modifier = Modifier.size(40.dp),
            color = Color.Green,
        ) {
            Box(
                modifier = Modifier
                    .size(20.dp)
                    .clip(CircleShape)
                    .background(Color.Red)
            )
        }
    }
    b
    • 2
    • 2
  • c

    curtjrees

    07/02/2021, 4:53 PM
    I’ve ran into a odd interaction with my
    NavHost
    when I add a
    .verticalScroll()
    modifier to it It seems that the composables in my NavHost can’t
    fillMaxHeight()
    anymore and fallback to wrapping the content size Has anyone else managed to have “scrollable” NavHost? (reasoning behind this is to have a scrollState in which a collapsing toolbar can react to)
    i
    d
    a
    • 4
    • 5
  • t

    Tomáš

    07/02/2021, 5:23 PM
    Hey everyone 👋 I have a surprising problem regarding TextField and its TextFieldValue state. I have this Composable with should work similarly to a typical search bar with suggestions that users can tap on and the content of that suggestion is added into Text field. So TextField's value can come either from the user typing things or from an external source (the suggestion being tapped). I propagate every selection and text change via
    onTextChange
    and persist both up somewhere in my domain logic where I 1) update the list of suggestions 2) propagate text and selection back into this composable via
    descriptionWithSelection
    parameter. As you can see from the sample code below, I use this
    descriptionWithSelection
    only to populate the initial
    textFieldValueState
    state but I don't know how to update that state later when a new description comes. See code examples in the thread 🧵 Thanks for any help.
    :thread-please: 4
    m
    • 2
    • 5
Powered by Linen
Title
t

Tomáš

07/02/2021, 5:23 PM
Hey everyone 👋 I have a surprising problem regarding TextField and its TextFieldValue state. I have this Composable with should work similarly to a typical search bar with suggestions that users can tap on and the content of that suggestion is added into Text field. So TextField's value can come either from the user typing things or from an external source (the suggestion being tapped). I propagate every selection and text change via
onTextChange
and persist both up somewhere in my domain logic where I 1) update the list of suggestions 2) propagate text and selection back into this composable via
descriptionWithSelection
parameter. As you can see from the sample code below, I use this
descriptionWithSelection
only to populate the initial
textFieldValueState
state but I don't know how to update that state later when a new description comes. See code examples in the thread 🧵 Thanks for any help.
:thread-please: 4
@Composable
fun AutocompleteTextInputEditText(
    descriptionWithSelection: TextFieldValue,
    onTextChange: (String, TextRange) -> Unit,
) {
    val textFieldValueState = remember {
        mutableStateOf(TextFieldValue(descriptionWithSelection.text, descriptionWithSelection.selection))
    }

    BasicTextField(
        value = textFieldValueState.value,
        onValueChange = { tfv ->
            textFieldValueState.value = tfv
            onTextChange(tfv.text, tfv.selection)
        }
    )
}
I couldn't find any good example of this, which is surprising given how common of a use-case this is. All samples are using a closed local loop of
TextFieldValue
without any external input.
My first idea was to remove the "local" state from the equation and simply do this:
@Composable
fun AutocompleteTextInputEditText(
    descriptionWithSelection: TextFieldValue,
    onTextChange: (String, TextRange) -> Unit,
) {
    BasicTextField(
        value = descriptionWithSelection,
        onValueChange = { tfv ->
            onTextChange(tfv.text, tfv.selection)
        }
    )
}
This doesn't work because of two things: 1. There is a third parameter in TextFieldValue called
composition
which changes every thus
onValueChange
keeps producing values. This can be solved by persisting
composition
as well or there are other hacks such as using the local state and use
copy
method to keep the
composition
value locally persisted. But even if I solve this problem, there is a second one. 2. It comes from an asynchronous nature of
onValueChange
. It can emit an "old" value while a new one is propagated at the same time which triggers the loop again and the old value overrides the new one. (I hope it makes sense) I guess I could solve this with some upstream flows with debounce or something but that just seems more complicated than it should be.
m

mattinger

07/03/2021, 12:31 AM
This seems like something that should be a basic part of compose though. There’s already a MaterialAutoCompleteTextView in the xml view world. If there’s nothing built into compose, it seems like a big gap that is missing.
PS: I’ve found a pretty good implementation of an autocomplete here: https://github.com/pauloaapereira/Medium_JetpackCompose_AutoCompleteSearchBar
it has a few odd things, that i was able to work my way through. In particular, it doesn’t repopulate the search box after you select an item and then click back in and start deleting text. But that’s fixable. Also, there’s some issues with the soft keyboard covering up the suggestion box. I tried turning on
SOFT_INPUT_ADJUST_RESIZE
but it just made it even worse.
t

Tomáš

07/03/2021, 10:39 AM
Thanks, that's a nice example but it's a simpler case in a way that everything there is kept within the local composable world whereas in my case, I need to combine the local TextFieldValue and value coming from a flowable as a result of some domain logic which lives completely outside of @Composable context.
View count: 2