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

    Nat Strangerweather

    01/08/2021, 10:23 PM
    I'm really confused about
    .observeAsState
    . In my ViewModel I have this:
    val dynamicCallSenderCode = MutableLiveData(0)
    
         fun onSenderChanged (){
            dynamicCallSenderCode.value = broadcastReceivers.notifyCallSenderCode(context)
        }
    What I want to do is observe the broadcast receiver changes from my HomePage but I can't use
    .observeAsState
    with a function. How could I pass these changes live to my Composable?
    i
    1 reply · 2 participants
  • k

    Kshitij Patil

    01/09/2021, 9:26 AM
    Can we pass Composable function as a constructor argument of a Class ?
    a
    5 replies · 2 participants
  • a

    Archie

    01/09/2021, 10:31 AM
    Hi @Ian Lake, I was wondering if this is an intended behavior?
    @ExperimentalAnimationApi
    @Composable
    fun FillingIssues() {
        val navController = rememberNavController()
    
        val number by sampleFlow.collectAsState(initial = 0)
    
        Scaffold(
            topBar = {
                // This recomposes just fine
                // Gets 0, 1, 2, 3
                Text(text = "Top Bar: $number")
            }
        ) { padding ->
            val modifier = Modifier.padding(padding)
            NavHost(navController, startDestination = FIRST_SCREEN) {
                myNavigation(modifier, number)
            }
        }
    
    }
    
    fun NavGraphBuilder.myNavigation(
        modifier: Modifier,
        number: Int,
    ) {
        composable(FIRST_SCREEN) {
            // This Doesn't recompose
            // So it remains displaying
            // Number: 0
            // Even when 1, 2, 3 are emitted
            // This only happens when I make it
            // as an extension function
            Column(
                modifier.fillMaxSize(),
                Arrangement.Center,
                Alignment.CenterHorizontally
            ) {
                Text("Number: $number")
            }
        }
    }
    
    val sampleFlow = flow {
        emit(1)
        delay(1000)
        emit(2)
        delay(3000)
        emit(3)
    }
    
    private const val FIRST_SCREEN = "FIRST_SCREEN"
    i
    a
    4 replies · 3 participants
  • b

    buszi0809

    01/09/2021, 10:54 AM
    Hi, what you see are 2 Composables 1. Conversation - LazyColumn representing messages (I used modifier .fillMaxSize() to fill all the rest of screen) 2. UserInputBar - multiline Text Field surrounded by Surface that wraps around this text field so it increases it's size when text input goes multiline I connected these pieces with use of ConstraintLayout. Bottom of Conversation composable is constrained to top of UserInputBar, but it looks like it's actually constrained to middle of UserInputBar so composables overlap themselves. Does anyone know how repair such behaviour?
    d
    b
    12 replies · 3 participants
  • v

    Vsevolod Ganin

    01/09/2021, 3:22 PM
    Is there a way to reinstall
    pointerInput
    ? It doesn’t react on lambda changes and always use only first served lambda. Below prints only
    pointerInput 2
    and doesn’t print anything on switch toggle.
    @Preview
    @Composable
    fun PointInputTest() {
        var toggled: Boolean by remember { mutableStateOf(false) }
        Column {
            Switch(checked = toggled, onCheckedChange = { toggled = !toggled })
            Box(
                modifier = Modifier
                    .size(50.dp)
                    .background(Color.Red)
                    .run {
                        if (toggled) {
                            pointerInput {
                                println("pointerInput 1")
                            }
                        } else {
                            pointerInput {
                                println("pointerInput 2")
                            }
                        }
                    }
            )
        }
    }
    a
    4 replies · 2 participants
  • b

    Bradleycorn

    01/09/2021, 3:49 PM
    "LazyColumn/Row is the Compose equivalent of RecyclerView" ... Awesome! With RecyclerView, we can use
    ListAdapter
    and
    DiffUtils.ItemCallback
    to get automatic cool animations when items in our list change positions and are added/removed ... Is there a way to achieve this with LazyColumn?
    d
    4 replies · 2 participants
  • b

    Bradleycorn

    01/09/2021, 4:36 PM
    I wrote a little abstraction to render some content (a series of Text composables) either horizontally (Row) or Vertically (Column). Does Compose offer a better (built-in) way to do this?
    enum class Orientation {
        HORIZONTAL,
        VERTICAL
    }
    
    @Composable
    fun OrientedContent(
            orientation: Orientation, 
            modifier: Modifier = Modifier, 
            content: @Composable () -> Unit) = when (orientation) {
        Orientation.HORIZONTAL -> Row(modifier = modifier) { content() }
        Orientation.VERTICAL -> Column(modifier = modifier) { content () }
    }
    d
    a
    21 replies · 3 participants
  • n

    Nat Strangerweather

    01/09/2021, 4:50 PM
    Hi again, I was wondering why this code is not updating the color of my buttons in real time. I'd be grateful for some pointers, thanks!
    v
    3 replies · 2 participants
  • a

    Ayomide

    01/09/2021, 8:24 PM
    Hi again! I'm running into a problem with lists. I have a remembered
    mutableStateOf()
    a mutable list of strings. I'm just using a forEach inside a column to display the items.
    messageList.forEach {Text(it)}
    However, I don't seem to see any updates on the screen when the list gets a new item (The list is updated via a coroutine scope fetching data from elsewhere). I put a
    println()
    to debug, and the list definitely changes in size - so I think I must be doing something wrong
    t
    2 replies · 2 participants
  • d

    Denis

    01/10/2021, 7:55 AM
    Shouldn't
    val vm: MyViewModel = viewModel()
    always retrieve the same ViewModel object in different composables but in the same activity?
    h
    2 replies · 2 participants
  • z

    zsperske

    01/10/2021, 7:13 PM
    Hello, sometimes when I'm trying to extract a smaller composable from a larger composable using android studio's refactor "extract method" I will get error messages like this
    Function ColumnScope.weight(Float, Boolean) on Modifier will no longer be accessible after extraction
    Is there a way around this?
    a
    2 replies · 2 participants
  • r

    Rick Regan

    01/10/2021, 10:23 PM
    When I call this composable I get two messages: ... Slider onValueChange: 10.0 ... Slider onValueChange: 5.0 I was expecting only one callback, the second one.
    @Composable
    fun SliderTest() {
        val sliderValue = remember { mutableStateOf(5f) }
        Slider(
                value = sliderValue.value,
                onValueChange = {
                    Log.d("Slider onValueChange ", "$it")
                    sliderValue.value = it
                },
                modifier = Modifier.width(200.dp),
                valueRange = 0f..10f,
        )
    }
    The first message is always for the end value in valueRange, 10 in this example. (I'm using Arctic Fox 2020.3.1 Canary 4, built on Dec 23, 2020.)
    t
    2 replies · 2 participants
  • n

    Nana Vong

    01/11/2021, 2:45 AM
    When will alpha11 be released? I can't wait😝
    a
    e
    +2
    9 replies · 5 participants
  • l

    Lilly

    01/11/2021, 4:13 AM
    I would like to show a vector image within my composable for a specific period of time, e.g. 3 seconds and it should block so nothing else is done while it is displayed. Is this possible?
    a
    6 replies · 2 participants
  • s

    Shakil Karim

    01/11/2021, 7:23 AM
    I using paging with Compose but it crashes the app on orientation change, but with the normal list, it's work fine.
    --------------------- in ViewModel ---------------------------- 
    val newsSelection : MutableStateFlow<HeadlinesPagingKey> = MutableStateFlow(
                HeadlinesPagingKey())
    
    @ExperimentalCoroutinesApi
         val topHeadlines: Flow<PagingData<Article>> =
                 newsSelection.flatMapLatest {
                     newsRepository.topNewsHeadlines(it)
                 }.shareIn(viewModelScope, SharingStarted.Lazily,1)
    
    ---------------------and in Composable---------------------------- 
    
    val lazyPagingItems: LazyPagingItems<Article> =
            headlinesViewModel.topHeadlines.collectAsLazyPagingItems()
    a
    2 replies · 2 participants
  • p

    Piotr

    01/11/2021, 3:43 PM
    Hi, Is there a way to get the value of the y position while the screen is scrolling? I have a situation like this:
    LazyColumn() {
        item {
          box()
          box()
          box()
          ScrollableTabRow()
        }
        itemsIndexed {...}
    I need to know when the ScrollableTabRow moves past a certain position on y axis (for example lets say 100.dp ) I tried working with .scrollable() (something like scrollable) and with scroll gesture filter (something like gesture) and with dragGestureFilter but i cannot get it to work, am i doing something wrong, or is it just not possible?
    a
    r
    7 replies · 3 participants
  • t

    tieskedh

    01/11/2021, 3:53 PM
    Question: Do I need to call compose from the same coroutine every time? My Textfield is generating random input based upon previous entered characters. When I enter for example type "email@123456.com" then remove everything and then type "thisis" it copletes with "thisis@124356.com". I do submit my input to a multithreaded application (using MVIKotlin) but I would expect it would then complete to previous entered values instead of the characters in random order. Am I missing something?
    a
    s
    31 replies · 3 participants
  • a

    alorma

    01/11/2021, 4:45 PM
    Is mandtory that composes uses AGP 7.0.0-alpha04? It looks that it needs java 11, and jitpacks not works on my repo
    c
    2 replies · 2 participants
  • a

    alorma

    01/11/2021, 4:46 PM
    Error log: https://jitpack.io/com/github/alorma/Compose-Debug-Drawer/0.1.0-beta-06/build.log Repo: https://github.com/alorma/Compose-Debug-Drawer/
    t
    4 replies · 2 participants
  • d

    David Albers

    01/11/2021, 5:24 PM
    I have Compose code in a separate module. When I try to add the Compose module to the main module, the
    androidx
    libraries get bumped to alpha for the whole project. Anyone know what I’m doing wrong?
    j
    5 replies · 2 participants
  • g

    grandstaish

    01/11/2021, 5:37 PM
    Hi all. I’m looking to draw a composable and all of its content into a Bitmap for screenshot testing, including stuff currently scrolled outside of the bounds of the device window. Is it possible?
    j
    6 replies · 2 participants
  • k

    Kayacan Kaya

    01/11/2021, 6:52 PM
    Hello everyone. I have a question about fullscreen composables. While using Scaffold (and its bottom bar for navigation) and NavHost (attached to the bottom bar) together, opening a fullscreen composable from a content composable of Scaffold fills the content composable’s area as expected. To open them fullscreen covering the whole, another NavHost should be placed on the layer above the Scaffold in order to get rid of the scope of content composable.* However, I do not want to include all fullscreen pages in the same NavHost as it violates my architecture. In order to place fullscreen composables in their respective packages (not including them in one nav host), I have customized Scaffold whose bottom bar is stateful just like in  BottomDrawerLayout. I am hiding/showing bottom bar while navigating to fullscreen composables from the content composable of the Scaffold by the NavHosts inside the content composables. Though it supported my architecture, it feels like I am breaking the KISS principle 🙂 Do you have any other suggestions? (*One of Jetpack’s example apps Jetsnack has an example usage of Navhost used for fullscreens in git branch dedicated to navigation. You can check it out if you’re interested in the topic)
    d
    4 replies · 2 participants
  • c

    codeslubber

    01/11/2021, 9:07 PM
    Is it possible to navigate between activities? and have the bottom bar work? seems like the answer is no (for now?)…
    i
    21 replies · 2 participants
  • v

    Vipulyaara

    01/11/2021, 9:37 PM
    Is there a way to compute
    TextLayoutResult
    before the text is actually drawn? I reduce my text size until the text fits the width of the screen using
    onTextLayout
    (never thought it'd be that easy on Android) and it works fine but I'd like to do it in background without the user seeing the text get smaller.
    j
    s
    4 replies · 3 participants
  • d

    dagomni

    01/12/2021, 11:19 AM
    Did someone have any success combining Kotlin 1.4.21-2, Multiplatform, Serialization and Compose in one module? I think I tried configuring it in every possible way (known to me) and there is an issue during build
    Back-end (JVM) Internal error: Couldn't inline method call '<get-current>' into @androidx.compose.runtime.Composable
    j
    h
    8 replies · 3 participants
  • c

    Cyril Find

    01/12/2021, 11:42 AM
    Hi, about using Paging 3 with Compose and keeping the scroll state while using Navigation, I made a one-file sample and found out it works if I do the
    collectAsLazyPagingItems()
    before declaring the
    NavHost
    but it seems to me like I should be able to do it right before
    LazyColumn
    Is there something I’m missing ? (I’ll share the code in the thread :thread-please: )
    a
    10 replies · 2 participants
  • b

    Bryan Herbst

    01/12/2021, 8:04 PM
    The docs for
    AmbientAutofillTree
    note that Autofill semantics will be replacing some of the existing autofill APIs at some point, but reference an internal issue and the comment itself seems to be over a year old. Is the plan still to leverage semantics for some of the autofill support? Ref: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:co[…]compose/ui/platform/Ambients.kt;l=58-65?q=AmbientAutofillTree
    j
    r
    +2
    10 replies · 5 participants
  • b

    Bradleycorn

    01/12/2021, 9:18 PM
    Anyone used product flavors with Compose? In particular I'm curious about best practices for building out different theme colors for different product flavors
    ➕ 1
    s
    1 reply · 2 participants
  • d

    Daniele B

    01/12/2021, 9:19 PM
    Is there anything wrong in having one big state object for the whole application? I am already doing that and everything works great. I just wonder if there are any performance problems in case the app grows too big. I am defining the state of each screen as a separate data class object, which is instantiated as a property of the big state object.
    j
    c
    +1
    6 replies · 4 participants
  • l

    Lilly

    01/13/2021, 3:01 AM
    Hi, I have built a TextField composable that acts like a drop down field. I would like to place it in the
    trailing
    slot of a
    ListItem
    but due to its default minWidth of 280 dp I can't make it smaller without side effects. When I set the with of the
    TextField
    it behaves not like expected. The TextField will always fill a width of 280 dp no matter what width I apply. What options do I have here? Should I make an own version of TextField -> what basic composable would I use to build on?
    s
    a
    +1
    27 replies · 4 participants
Powered by Linen
Title
l

Lilly

01/13/2021, 3:01 AM
Hi, I have built a TextField composable that acts like a drop down field. I would like to place it in the
trailing
slot of a
ListItem
but due to its default minWidth of 280 dp I can't make it smaller without side effects. When I set the with of the
TextField
it behaves not like expected. The TextField will always fill a width of 280 dp no matter what width I apply. What options do I have here? Should I make an own version of TextField -> what basic composable would I use to build on?
s

Siyamed

01/13/2021, 3:31 AM
If you can create a ticket with repro steps, a sample code and maybe your expectation it would be awesome
What are the side effects that you mentioned?
Oh, also right now for a few releases it doesnt have a default with in dp's but in number of chars, so it would ge good to update Compose as well
l

Lilly

01/13/2021, 1:13 PM
@Siyamed I have previewed a simple TextField with a custom width. As you can see its parent container still takes its 280 dp no matter what width I have applied. It's not visivle but it still takes the space. That's the reason why in my screenshot above the TextField looks like centered but it's simple taking in the whole space which I described as side effect. I would expect that its width matches the width I have applied. I'm using alpha09
a

alorma

01/13/2021, 4:45 PM
Hey, can you share the component? 🙏 i wnt to use one in a project
l

Lilly

01/13/2021, 4:49 PM
Sure
You may have to adjust it. I'm expecting an
string array
for the possible selections
TextFieldDropDown
a

alorma

01/13/2021, 4:52 PM
Would this work (adjusted) as a clickable TextField?
l

Lilly

01/13/2021, 5:04 PM
Yes of course. You have to move the code within the
trailingIcon
slot out of the slot and remove this slot. Then you make your TextField
clickable
via the modifier. And in the clickable block you define the expanding logic. I have currently stress otherwise I would implement it for you
If you don't get it to work, write me tomorrow, then I have time again
s

Siyamed

01/13/2021, 5:29 PM
@Anastasia [G] if they have an idea in terms of min width on the material layer
hmm, yes (material) TextFields have min width defined
private val TextFieldMinWidth = 280.dp
in TextFieldImpl
@Lilly can you please create a ticket and share here? If you can share a minimal repro case it would be very helpful.
a

Anastasia [G]

01/13/2021, 5:37 PM
There is a change in review already which removes the 280dp minimum width,
So no need for a ticket
👍 1
l

Lilly

01/13/2021, 5:37 PM
As far as I know there will be a release tomorrow?
s

Siyamed

01/13/2021, 5:37 PM
it wouldnt make it to tomorrow 🙂
l

Lilly

01/13/2021, 5:37 PM
alright 🙂
s

Siyamed

01/13/2021, 5:38 PM
since the releases are cut earlier
a

Anastasia [G]

01/13/2021, 5:38 PM
and also it is not merged yet
l

Lilly

01/13/2021, 5:38 PM
what options do I have until then?
is there another TextField like component which is more based or should I build something custom with simple
Text
and
Surface
?
s

Siyamed

01/13/2021, 5:40 PM
there is a lower level component named
BasicTextField
Not sure if the error repros there or if it works for your use case
BasicTextfield has a default width if no width is defined in number of chars (afaik it was 10), but it doesnt have a min/max etc width.
👍 1
l

Lilly

01/13/2021, 5:48 PM
Thanks a lot, I will check it
View count: 1