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

    allan.conda

    10/20/2020, 12:48 AM
    Are Ambients a Service Locator / Dependency Injection API? I haven’t seen official documentation describing them as such, and I think that’s pretty much what it is. I could achieve the same thing with Dagger/Hilt, though the dependencies are scoped within the Composable Hierarchy, instead of Activities/Fragments/Application/ViewModel
    j
    l
    • 3
    • 2
  • j

    Jeremy

    10/20/2020, 3:18 AM
    Results in NPE:
    Untitled
    • 1
    • 2
  • m

    Mohamed Elfiky

    10/20/2020, 4:02 AM
    is this exception known
    Layer is redrawn for LayoutNode in state NeedsRelayout
    ?
    a
    v
    +3
    • 6
    • 18
  • h

    Hyun

    10/20/2020, 4:18 AM
    Hi, All. Jetpack Compose uses function. but, I think there were some discussion on
    function
    vs `class`(as swiftUI also based on function but also able to use struct) So, I just tried to use
    class
    for Composable if it’s meaningful. Kindly review if it’s reasonable or not. the below is the sample code with
    class
    Screen(Composable class)
    class ApiSingleScreen(private val model: ApiSingleViewModel = ApiSingleViewModel()) : Screen(model) {
        override val title: String = R.string.single_call.resourceToString()
    
        //for Composer to recognize the class
        @Composable
        override fun compose() {
            super.compose()
        }
    
        @Composable
        override fun view() {
            Column {
                Text("current value : ${+model.result}")
                SampleTextField("Input value", model.input)
                Button("update") {
                    model.onClick()
                }
            }
        }
    }
    ViewModel
    class ApiSingleViewModel(private val api: PreferenceApi = serviceLocator.preferenceApi) : BaseViewModel() {
    
    	//DataFlow will be migrated to MutableSharedFlow. as coroutine-native-mt 1.4.0 is not yet released. I customized Flow.
        val result by lazy { DataFlow<String>() }
    
        //if result is changed, input also changed.
        val input by add { DataFlow<String>().withSource(result) }
    
    
        override fun onInit() {
        	//initStatus is connected with loading, error ui. so, when call api, loading, error ui is shown by the state
            result.load(initStatus) {
                api.getString(KEY) ?: ""
            }
        }
    
        fun onClick() {
            result.load(status) {
                val text = input.value?: error("please input")
                api.setString(KEY, text)
                text//set changed text after api call is success
            }
        }
    }
    If There is something wrong on my opinion. kindly advise me to learn.🙏
    j
    v
    j
    • 4
    • 10
  • p

    P.J.

    10/20/2020, 11:11 AM
    Hey, since we won't need multiple fragments anymore with compose navigation and can go single activity, what would be the best practice for injecting viewmodels with hilt? Injecting them all in the activity and then pass them down?
    a
    • 2
    • 5
  • d

    Dmytro Bazunov

    10/20/2020, 11:30 AM
    Hi, i try to integrate compose in production project to test it. When i try to build project i got :
    Execution failed for task ':app:prepareDevDebugKotlinCompileTask'.
    > org/jetbrains/kotlin/gradle/tasks/KotlinCompile
    Exception says:
    Caused by: java.lang.NoClassDefFoundError: org/jetbrains/kotlin/gradle/tasks/KotlinCompile
    	at com.android.build.gradle.tasks.PrepareKotlinCompileTask.doTaskAction(PrepareKotlinCompileTask.kt:71)
    Maybe someone got similar issue or knows how to fix it?
    a
    • 2
    • 1
  • k

    Karthick

    10/20/2020, 1:46 PM
    Why NavControllerAmbient removed, why it is need to pass to composable functions explicitly
    a
    a
    +2
    • 5
    • 4
  • m

    Mouaad

    10/20/2020, 3:56 PM
    Hi, not sure why, but
    createBottomBarrier
    started to crash since
    1.0.0-alpha05
    with this:
    java.lang.NullPointerException: Attempt to invoke interface method 'androidx.constraintlayout.core.widgets.ConstraintWidget androidx.constraintlayout.core.state.Reference.getConstraintWidget()' on a null object reference
    . I assume something changed?
    👆 2
    d
    v
    • 3
    • 3
  • s

    Se7eN

    10/20/2020, 4:04 PM
    Any ideas on how to pause and resume a transition? I have the following transition:
    transitionDefinition<StoryState>{
        state(StoryState.START) {
            this[progress] = 0f
        }
    
        state(StoryState.END) {
            this[progress] = 1f
        }
    
        transition(StoryState.START to StoryState.END) {
            progress using tween(5000, delayMillis = 500, easing = LinearEasing)
        }
    }
    I'd like to pause and resume the transition on a certain event. I guess we can't do that so what can I do?
    y
    d
    • 3
    • 7
  • j

    jaqxues

    10/20/2020, 4:15 PM
    How stupid is it to use
    androidx.navigation:navigation-compose:1.0.0-SNAPSHOT
    I do want to avoid Fragments, but I do not want to rewrite it every day because its a snapshot
    a
    i
    +2
    • 5
    • 10
  • z

    Zach Klippenstein (he/him) [MOD]

    10/20/2020, 6:48 PM
    Looks like the thing that everyone who’s tried to write a navigation library in Compose has been waiting for is in review: https://android-review.googlesource.com/c/platform/frameworks/support/+/1425674 This looks great, it’s gonna be super handy!
    New experimental api RestorableStateHolder. It allows to save the state defined with [savedInstanceState] and [rememberSavedInstanceState] for the subtree before disposing it to make it possible to compose it back next time with the restored state.
    👍🏽 8
    h
    • 2
    • 3
  • z

    Zach Klippenstein (he/him) [MOD]

    10/20/2020, 7:14 PM
    Also, Compose sources seem to be browseable again in Android Studio 4.2 canary 14! 🎉
    🎉 37
    r
    r
    +2
    • 5
    • 8
  • n

    nickbutcher

    10/20/2020, 8:01 PM
    https://developer.android.com/jetpack/compose/state 👀
    👍 6
    ❤️ 1
    🙏🏽 1
    💥 24
    👀 18
    a
    m
    • 3
    • 3
  • g

    Gabriel

    10/20/2020, 8:40 PM
    Is anyone else using androidx.compose.navigation:navigation snapshot? Or do we have a normal alpha of it yet?
    i
    • 2
    • 1
  • m

    Mihai Hrincescu

    10/20/2020, 8:45 PM
    Hello everyone I've encountered some weird behaviour with
    .clickable()
    modifier when i scale up a
    @composable
    using
    .drawLayer()
    the hit box not only it does not scale up but it actually scales down and moves down and to the right proportionate to where the the
    @composable
    is placed inside of the available space. Should i just change the size instead or is this just a bug and scaling a
    @composable
    should also scale the hit box?
    z
    • 2
    • 6
  • s

    Sebastian Neagrau

    10/20/2020, 9:47 PM
    Hello guys, I’m new to Android and Jetpack Compose and I was wondering if there is any way of having a global state of the application? Just like React-Native has Redux? I know there’s a library called ReduxKotlin, I was wondering if anybody else used it or have any suggestions about how this can be achieved. (not necessarily through the ReduxKotlin library)
    g
    l
    +2
    • 5
    • 12
  • c

    chris-horner

    10/20/2020, 10:28 PM
    Has anyone looked into crafting shared element transitions between composables? I know Android's Transition API wasn't much loved, but I'm really missing something like it in Compose 😅
    👍 1
    v
    a
    • 3
    • 4
  • s

    Subhi Pandey

    10/21/2020, 6:02 AM
    Here you go https://github.com/yashovardhan99/ComposeNotes/ @Spikey Sanju
    👍 2
    a
    a
    • 3
    • 2
  • s

    Spikey Sanju

    10/21/2020, 9:12 AM
    Is anyone working with multiple sets of compose components & planning to launch it as a library? How was your experience? Any tips?
    a
    • 2
    • 2
  • a

    alorma

    10/21/2020, 9:38 AM
    HI! A question for compose: Is this the best way to create custom colors and shapes values?
    @Composable
    val Colors.success: Color
        get() = if (isSystemInDarkTheme()) {
            green200
        } else {
            green800
        }
    @Composable
    val Shapes.fab: Shape
        get() = RoundedCornerShape(percent = 50)
    MaterialThemes.Colors.success
    MaterialThemes.Shapes.fab
    j
    l
    • 3
    • 14
  • c

    Chethan

    10/21/2020, 11:52 AM
    How can I change the background of Radio Button ?
    n
    l
    • 3
    • 10
  • m

    Mohamed Elfiky

    10/21/2020, 12:11 PM
    when we should use key() is there like some guide to that?
    ➕ 1
    j
    a
    • 3
    • 4
  • d

    David Edwards

    10/21/2020, 1:35 PM
    What is the best way to get a composable to recalculate its own height, when a sibling forces a parent to grow? I have an issue where an image of unknown height causes a Row to grow. This in turn messes with a sibling, which has
    fillMaxHeight
    set. The sibling does not grow to fill the new height of its parent. I have made a gif to illustrate what I mean, the sibling is highlighted blue. If I set the Row to a fixed height, the issue does not happen.
    z
    • 2
    • 24
  • b

    Bryan Herbst

    10/21/2020, 2:44 PM
    I have my own typography system (i.e. not
    MaterialTheme.Typography
    ), but I’d like to lean on Material for a number of components such as
    Button
    . Specifically looking at
    Button
    , I’d like to use my own
    FancyTheme.typography.button
    instead of
    MaterialTheme.typography.button
    . My first thought was to do something like
    @Composable
    fun FancyButton(content: @Composable RowScope.() -> Unit) {
      Button {
        ProvideTextStyle(
          value = FancyTheme.typography.button,
          children = content
        )
      }
    }
    But that doesn’t quite work since
    ProvideTextStyle
    ’s content doesn’t accept a
    RowScope
    receiver. Is there a better way to do this?
    z
    a
    +3
    • 6
    • 26
  • b

    bruno.aybar

    10/21/2020, 4:58 PM
    Hey everyone, just wanted to say that I have learned a lot just by reading the questions / answers in this channel. People ask me questions about Compose every now and then and I usually say “I think someone mentioned it somewhere in the slack channel…” So I compiled a list of those remarks that I find insightful: https://collectednotes.com/brunoaybar/compose-insights I’m just referencing existing answers (not posting personal opinions), but please feel free reach out if you think any of those may be inaccurate / misleading / outdated / not helpful 😅
    😍 1
    🎉 18
    🙏🏼 9
    🙏 3
    z
    a
    a
    • 4
    • 7
  • p

    pourpre

    10/21/2020, 9:07 PM
    Hey. Does anyone know where to do a feature request for
    navigation-compose
    ? Specifically, adding a
    NavOptions?
    parameter to the
    NavController.navigate
    extension function.
    i
    a
    • 3
    • 7
  • f

    fabio.carballo

    10/21/2020, 9:26 PM
    hey, what would be the best approach to guarantee that any children that I define are always expanded to match the full width? I wanted to achieve something like this:
    VerticalButtonContainer(
        top = {
             TertiaryButton(
                text = "Tertiary",
                onClick = { },
              )
         },
         bottom = {
              PrimaryButton(
                  text = "Primary",
                  onClick = {},
              )
         }
    )
    
    @Composable
    fun VerticalButtonContainer(
        top: @Composable () -> Unit,
        bottom: @Composable () -> Unit
    ) {
        Column(
            Modifier
                .fillMaxWidth()
                .padding(16.dp)
        ) {
    
            top()
            Spacer(Modifier.height(16.dp))
            bottom()
        }
    }
    In this case both
    top
    and
    bottom
    would ideally expand to the max width of the container. However (naturally) the buttons are still wrapping the content. Any way I can tweak the internals of this
    VerticalButtonContainer
    to force the children to expand the width?
    👍 1
    a
    • 2
    • 3
  • a

    Artem Sharypov

    10/21/2020, 9:29 PM
    Has anyone had this compilation error happen when they were trying to add compose to an existing project?
    Unable to load class 'org.jetbrains.kotlin.gradle.tasks.KotlinCompile'.
    For reference it’s on kotlin
    1.14.10
    ,
    1.0.0-alpha05
    for the compose version, android gradle
    4.1.0
    , and on android studio 4.2 canary 14,
    d
    • 2
    • 1
  • g

    Guy Bieber

    10/21/2020, 11:41 PM
    So if we initialize a map partially with mutableStateMapOf and partially by adding items directly, are the added items also mutableState? What is the correct way of doing this?
    j
    • 2
    • 1
  • g

    Guy Bieber

    10/21/2020, 11:47 PM
    Example… This specific problem is a MutableList
    var pages : MutableList<PagerDataModel.Page> = mutableStateListOf()
    // is the added item also mutableStageOf
    // note there is no such thing as a MutableStateList.
    pages.add(...)
    j
    • 2
    • 1
Powered by Linen
Title
g

Guy Bieber

10/21/2020, 11:47 PM
Example… This specific problem is a MutableList
var pages : MutableList<PagerDataModel.Page> = mutableStateListOf()
// is the added item also mutableStageOf
// note there is no such thing as a MutableStateList.
pages.add(...)
j

jim

10/21/2020, 11:50 PM
The map remains an instance of SnapshotStateMap regardless of the more generalized type of reference that you assign it to.
👍 1
View count: 3