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

    Oussama Haff.

    10/28/2020, 12:19 PM
    Hello 👋 A question about Testing Compose When testing a
    LazyColumn
    with lots of items, the assertion of
    onChildren().assertCountEquals()
    counts only the displayed nodes. How can I test that the composable will actually show all
    items
    passed to the
    LazyColumn
    ?
    z
    • 2
    • 1
  • c

    Chethan

    10/28/2020, 12:25 PM
    Hello , why the UploadPhots doesn’t recompose with change in value _uploadItems , what I am missing and not understood ?
    @Composable
    fun UploadPhotos(
        viewModel: YourViewModel,
        imageAdapterClickLister: ImageAdapterClickLister
    ) {
    
        val userSelectedMediaList = viewModel.listOfSelectedImages.collectAsState()
    
    
    
        if (userSelectedMediaList.value.isEmpty())
            DefaultPlaceHolder(
                onClickOfUpload = {
                    imageAdapterClickLister.onUploadMoreButtonClick()
                   
                }
            )
        else
            SetUserSelectedMedia()
    }
    class YourViewModel @ViewModelInject constructor(
        private val repository: YourReviewRepository
    ) : ViewModel() {
    
        private val _uploadItems = MutableStateFlow(mutableListOf<UploadedItem>())
        val listOfSelectedImages: StateFlow<List<UploadedItem>> get() = _uploadItems
    
        fun addSelectedMediaToList(userSelectedUploadItem: UploadedItem) {
    
             val listWithNewlyAddedItem = _uploadItems.value.also {
                it.add(userSelectedUploadItem)
            }
    
            _uploadItems.value = listWithNewlyAddedItem
        }
    }
    z
    • 2
    • 3
  • w

    William Barbosa

    10/28/2020, 1:04 PM
    I'm trying to update to alpha05 and leakcanary is reporting that the ClipboardManager is consistently leaking in any fragment that includes Compose. I'll include the full trace in the thread, for further investigation. I doubt this is something on our end, given that after the update we simply fixed what was explicitly broken. Any hints or is this a known bug?
    a
    • 2
    • 2
  • k

    Kshitij Patil

    10/28/2020, 1:07 PM
    How to work with different screen configurations in compose? Like I've to support landscape mode on a 7-inch tablet as well as a portrait mode on regular 5-6 inch mobile phones. How should I
    @Preview
    for these configurations?
    a
    j
    j
    • 4
    • 9
  • d

    dagomni

    10/28/2020, 1:15 PM
    FYI, doing this
    val backStackEntry = navHostController.currentBackStackEntryAsState()
    and then accessing
    backStackEntry.value
    causes constant recomposition
    j
    i
    • 3
    • 3
  • k

    Kshitij Patil

    10/28/2020, 2:03 PM
    Just went through navigation-compose samples and have rather silly doubt: in sealed class for Screens, why can't we just have computed property called "route" which will call
    stringResource(resId)
    in its
    get()
    method
    j
    z
    +2
    • 5
    • 26
  • z

    zoha131

    10/28/2020, 5:03 PM
    elevation is not working for
    BottomNavigation
    bottomBar = {
                BottomNavigation(
                    elevation = 16.dp,
                    backgroundColor = MaterialTheme.colors.surface,
                    contentColor = MaterialTheme.colors.onSurface
                ) {
                    BottomNavigationItem(icon = {Icon(asset = Icons.Outlined.Home)}, selected = true, onClick = {})
                    BottomNavigationItem(icon = {Icon(asset = Icons.Outlined.Search)}, selected = false, onClick = {})
                    BottomNavigationItem(icon = {Icon(asset = Icons.Outlined.Person)}, selected = false, onClick = {})
                }
            }
    • 1
    • 1
  • n

    nickbutcher

    10/28/2020, 5:06 PM
    https://developer.android.com/jetpack/compose/navigation 👀
    🔥 16
    🍒 5
    🎉 55
    i
    c
    a
    • 4
    • 3
  • a

    Afzal Najam

    10/28/2020, 7:18 PM
    I'm having a problem with using bottom nav + Navigation compose (like in the guide) where the back button gets intercepted a few times? For example if you switch from Profile to FriendList to Profile, then press back, it should close the app but the back button doesn't do that for a few taps, instead it does nothing for a few taps then it closes the app. @Ian Lake known issue or should I create a ticket?
    i
    • 2
    • 1
  • e

    Eric Ampire [MOD]

    10/28/2020, 7:56 PM
    What will it take to pass a parcellable as an argument? @Ian Lake
    i
    a
    +4
    • 7
    • 23
  • s

    Sergey Y.

    10/28/2020, 8:04 PM
    @Ian Lake Hi. I'm very excited about the release of the
    Navigation Compose Alpha 1
    . I wanted to ask what is the state or plans of the graphical representation of the navigation graph? I know the preview of the graph works only with xml, but will it extend for composable functions? I mostly like to use Navigation Component because of the graph preview. But the android community received it underestimated and coldly. Let's say, there are some contradictory things.
    i
    c
    • 3
    • 4
  • t

    tylerwilson

    10/28/2020, 11:05 PM
    I too am excited about the navigation compose integration. Though I am wondering how to handle my current use case: I am experimenting with Compose in one Fragment in my app that already uses navigation. In my first composable I want to navigate to another composable, but have the parent navhost do the ‘right’ thing with the nav controller so it pops back to my previous composable. I would love to see an example of this in the docs. It appears to me the sample linked above assumes a fully composable app, not a ‘hybrid’, which I expect many people will be using in the short term. Thanks!
    i
    • 2
    • 5
  • v

    Val Salamakha

    10/28/2020, 11:42 PM
    I like the navigation_compose:1.0.0-alpha01. It seems to me, that an error is in the sample https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:navigation/navigation-compose/samples/src/main/java/androidx/navigation/compose/samples/NavigationSamples.kt
    @Composable
    fun Profile(navController: NavHostController) {
        Column(Modifier.fillMaxSize().then(Modifier.padding(8.dp))) {
            Text(text = stringResource(Screen.Profile.resourceId))
            NavigateButton(stringResource(Screen.Dashboard.resourceId)) {
                navController.navigate(Screen.Dashboard.route)
            }
            Divider(color = Color.Black)
            NavigateButton(stringResource(Screen.Scrollable.resourceId)) {
    //it should be            navController.navigate(Screen.Scrollable.route)
    // instead of             //navController.navigate(Screen.Dashboard.route)
            }
            Spacer(Modifier.weight(1f))
            NavigateBackButton(navController)
        }
    }
    i
    • 2
    • 1
  • a

    alorma

    10/29/2020, 7:21 AM
    Hi, is there
    RatingBar
    on Compose?
    🇳🇴 2
    a
    g
    j
    • 4
    • 12
  • j

    József Szilvási

    10/29/2020, 9:05 AM
    It seems like setting the
    ImeAction
    on TextFields stopped working. I guess it is related to this fix:
    Added single line keyboard option to CoreTextField (<https://android-review.googlesource.com/#/q/I72e6d9f84abbf4ff6a9ede5355de4c30d37c3d8c|I72e6d>)
    a
    • 2
    • 1
  • h

    harry248

    10/29/2020, 9:16 AM
    Tried to use the MdcTheme in our app but getting an “_Cannot create Typeface from ResourceFont(resId=17040217, weight=FontWeight(weight=400), style=Normal)”_ exception. Anyone experienced that before?
    n
    n
    • 3
    • 6
  • m

    manueldidonna

    10/29/2020, 10:24 AM
    How can I create a dashed divider? Could someone point me to the right solution?
    a
    • 2
    • 1
  • k

    Kshitij Patil

    10/29/2020, 11:54 AM
    I'm using the
    navigation-compose
    with bottom nav bar (basically same as the example from documentation) and the app runs fine on my device. But the
    @Preview
    is not working and shows this error
    • 1
    • 1
  • c

    Chethan

    10/29/2020, 12:10 PM
    How can I avoid network call on every recomposes , I have situation where I subscribe to MediatorLive data with saying observeAsState(). Now every time recompose, It goes and call the same network call and takes infinite loop. here is the use case - I pick the images from the gallery, every image will play linearprogress bar (multipart upload) , I have used MediatorLive data to listen two values - percentage of chunks it is sending and also to listen the final response from the server. Now the problem I have is, this particular line inside compose method calls the network for every recompose, since the network call is managed inside uploadImage, it goes end less, How can I avoid this ?
    viewModel.uploadImage(ContextAmbient.current, job, uri).observeAsState()
    @Composable
    fun SetImageUpdateProgressBar(
        job: Job,
        uri: Uri,
        viewModel: UploadViewModel = viewModel()
    ) {
    
        var result = viewModel.uploadImage(ContextAmbient.current, job, uri).observeAsState()
        result?.value?.let { data ->
    
            when (data.response.status) {
    
                Status.ERROR -> {
                    // setRetryButton()
                }
    
                Status.SUCCESS -> {
                    ShowProgressBar(value = 0, visibility = false)
                }
    
                Status.LOADING -> {
                    ShowProgressBar(data.uploadProgressValue)
                }
            }
        }
    }
    g
    z
    j
    • 4
    • 9
  • g

    Grigorii Yurkov

    10/29/2020, 1:08 PM
    How to make them the same size
    @Preview
    @Composable
    fun Test() {
        Column(
            modifier = Modifier.fillMaxSize(),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            ButtonText(
                text = "Super very large button"
                modifier = Modifier.wrapContentWidth(Alignment.CenterHorizontally)
            )
            ButtonText(
                text = "small"
                modifier = Modifier.wrapContentWidth(Alignment.CenterHorizontally)
            )
        }
    }
    
    @Composable
    fun ButtonText(text: String, modifier: Modifier = Modifier) {
        Button(onClick = {}, modifier = modifier) {
            Text(text)
        }
    }
    a
    d
    +5
    • 8
    • 14
  • z

    zoha131

    10/29/2020, 4:25 PM
    Anyone facing any issue after upgrading compose from alpha-05 to alpha-06? I am getting this fatal issue:
    r
    k
    • 3
    • 6
  • g

    Grigorii Yurkov

    10/29/2020, 6:44 PM
    What do you think, did I implement it right?
    @Composable
    val composableScope: CoroutineScope
        get() {
            val context = SupervisorJob() + Dispatchers.Main.immediate
            onDispose {
                context.cancel()
            }
            return CoroutineScope(context)
        }
    Or maybe there is out-of-the-box solution?
    l
    • 2
    • 1
  • s

    sjthn

    10/29/2020, 6:55 PM
    Just started using Compose and got this error when trying to display an image of ~500KBs. The same image when rendered using xml works fine. Something like this is what I did to display the image:
    val image = imageResource(id = R.drawable.img_123)
        val imageModifier = Modifier
            .preferredHeight(180.dp)
            .fillMaxWidth()
        Image(image, modifier = imageModifier,
            contentScale = ContentScale.Crop)
    Untitled
    r
    • 2
    • 14
  • o

    Oussama Haff.

    10/29/2020, 7:40 PM
    Hello, is it really true that viewModel parameters are not supported for Composable preview or should I fire an issue about it ? This is the Composable that I’m trying to preview
    @Preview(group = "Themed Screens", showBackground = true, heightDp = 600, widthDp = 300)
    @Composable
    fun HomeScreenThemedPreview() {
        AppTheme {
            HomeScreen(viewModel = viewModel())
        }
    }
    g
    l
    +2
    • 5
    • 9
  • b

    Bryan Herbst

    10/29/2020, 7:46 PM
    Are there recommendations for working with Composable functions in lint? Right now I’m trying to register a custom lint issue on a call to a Composable, but since the method names can be re-written (e.g.
    Button
    to
    Button-bpaW8jA
    ) it is a little tricker to find the right Composables
    😬 1
    • 1
    • 2
  • s

    Sam

    10/29/2020, 10:29 PM
    Hi, does anyone know if kotlin
    1.4.20-RC
    works with Jetpack Compose
    alpha06
    ?
    j
    c
    • 3
    • 4
  • k

    Kshitij Patil

    10/30/2020, 7:11 AM
    How to draw shapes on an image? didn't find any updated sample
    f
    p
    • 3
    • 6
  • t

    Tlaster

    10/30/2020, 7:30 AM
    Hi. I'm using compose and compose-navigation with hilt injecting my viewModel, but I got
    RuntimeException: Cannot create an instance of class MyViewModel
    . Does anyone have the same issue?
    👍 3
    j
    a
    i
    • 4
    • 13
  • j

    jannis

    10/30/2020, 9:20 AM
    I’ve tried the new Navigation Component and it really works well so far. I’m still struggling with some concepts. My App has a Bottom Navigation and a TopAppBar. My questions: 1. Can I split up the navigation? E.g. I want to open a new part of the App without the Bottom Navigation. Or should I integrate that part in my main NavHost and just decompose the BottomBar? I’m not sure if this scales well in larger projects. I’m also unsure how to model this if multiple screens are visible (e.g. some semi-transparent screen on top of the one selected by the Bottom Navigation). 2. I want to dynamically change the title of my TopAppBar from a part of my UI. Is there an elegant way to do this? Currently I’m passing in the NavController and change the title with a given Argument. But this seems not that nice, since I have to add this parameter to every route. And I’m not able to change the title dynamically afterwards. Should I create a state for the title and pass it to every Composable which can change the State?
    i
    • 2
    • 1
  • a

    Alberto

    10/30/2020, 10:03 AM
    I've tried nav component and it's pretty, but i don't understand how to pass more params like an object, can i give more example? why i can't pass bundle?
    j
    i
    i
    • 4
    • 7
Powered by Linen
Title
a

Alberto

10/30/2020, 10:03 AM
I've tried nav component and it's pretty, but i don't understand how to pass more params like an object, can i give more example? why i can't pass bundle?
j

Javier

10/30/2020, 10:05 AM
i

Irving

10/30/2020, 10:09 AM
https://kotlinlang.slack.com/archives/CJLTWPH7S/p1603915006355200
a

Alberto

10/30/2020, 10:41 AM
@Javier ok, but i wanna send more params
navController.navigate(DETAIL_SCREEN+"/${StateScreen.READ}?${note}")
i

Ian Lake

10/30/2020, 3:37 PM
More parameters are fine, just like in a restful web service
post/{postId}/comment/{commentId}
is a perfectly fine route
a

Alberto

10/30/2020, 3:55 PM
so, if one of these parameter is optional my route it should be like this:
post?postId={postId}/comment/{commentId}
i

Ian Lake

10/30/2020, 4:34 PM
Put required ones before the
?
, optional ones after
👍 1
Before the
?
is the path, after is the query parameters
View count: 1