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

    Kshitij Patil

    10/24/2020, 7:21 AM
    Should I use Compose in production if I'm okay with maintaining the code with new releases? My use-case mainly involves dealing with Camera and videos. I went through compose-samples and found comments referencing to some of the issues being tracked; could someone brief me about the things (integrations with other jetpack components) that are not yet supported in Compose? I personally found jetpack compose opening up way more possibilities to do with the UI that I wouldn't have bothered to do had I using the legacy xml based layouts, but I'm getting bit confused about the architecture patterns to follow. Any recommendations in this regard would also make things clearer for me.
    s
    g
    +2
    • 5
    • 8
  • k

    Kyant

    10/24/2020, 7:28 AM
    How to handle WebView back press event?
    WebComponent(
        url = url.value,
        webContext = webContext,
        modifier = Modifier.keyInputFilter {
            if (it.key == Key.Back) {
                if (webContext.canGoBack()) {
                    webContext.goBack()
                    true
                } else false
            } else false
        },
    )
    But I got exceptions
    Exception dispatching finished signal.
    Exception in MessageQueue callback: handleReceiveCallback
    java.lang.IllegalStateException: KeyEvent can't be processed because this key input node is not active.
    g
    a
    • 3
    • 6
  • a

    Afzal Najam

    10/24/2020, 2:38 PM
    building a plugin for this today 🙂. Still have to parse all the different formats.
    👀 15
    👍 5
    s
    k
    • 3
    • 6
  • g

    Grigorii Yurkov

    10/24/2020, 5:02 PM
    Does
    View.INVISIBLE
    analog exist?
    a
    s
    m
    • 4
    • 4
  • m

    Mouaad

    10/24/2020, 5:19 PM
    Hi, is there any way, right now, to render a String with html tag? (the string itself is coming from an API)
    a
    j
    • 3
    • 5
  • h

    Hitanshu Dhawan

    10/25/2020, 2:03 AM
    Hello everyone, I’m facing an issue where I’m updating my LiveData in ViewModel, but there is no recomposition happening after the LiveData is updated. Here, I’m changing the quantity of a menu item (
    var
    ). If I remove an item, then there is recomposition happening. How to handle such cases in compose? ViewModel
    class MenuViewModel : ViewModel() {
    
        private val data = MenuRepository.getMenuData()
    
        private val _menuItems = MutableLiveData(data.menuItems)
        val menuItems: LiveData<List<MenuItem>> = _menuItems
    
        fun incrementMenuItem(menuItem: MenuItem) {
            _menuItems.value = _menuItems.value!!.apply { find { it == menuItem }!!.quantity++ }
        }
    
    }
    In Composable function
    val menuItems by viewModel.menuItems.observeAsState()
    
            LazyColumnFor(
                items = menuItems!!
            ) { menuItem ->
                MenuItem(
                    menuItem = menuItem,
                    onIncrement = { viewModel.incrementMenuItem(menuItem) },
                    onDecrement = { viewModel.decrementMenuItem(menuItem) },
                    modifier = Modifier.padding(16.dp)
                )
            }
    m
    g
    • 3
    • 7
  • z

    zoha131

    10/25/2020, 11:33 AM
    Currently we have
    Modifier.fillParentMaxWidth()
    for
    LazyItemScope
    . I want my item to take 80% of the available width. It would be great to have similar API like
    fillMaxWidth(fraction: Float)
    a
    • 2
    • 2
  • m

    manueldidonna

    10/25/2020, 3:05 PM
    ModalBottomSheet
    doesn't support nested scroll. I can't swipe on the list to slide up the sheet
    😍 2
    a
    y
    • 3
    • 2
  • i

    Issa

    10/25/2020, 4:31 PM
    Hi everyone! It’s my first time in this community. I have a question about Jetpack compose and I am wondering if there is a channel for open questions so i can post mine? Thanks
    a
    • 2
    • 1
  • i

    Issa

    10/25/2020, 4:39 PM
    I am trying to draw a gradient on the integrity of the screen as a fixed layer, for some reason I am not getting any preview, am I doing this wrong?
    Box(modifier = Modifier.height(100.dp).width(100.dp).drawBehind {
            HorizontalGradient(
                0.0f to Color.Red,
                0.5f to Color.Green,
                1.0f to Color.Blue,
                startX = 0.0f,
                endX = 100.0f
            )
        })
    a
    s
    • 3
    • 6
  • v

    Vsevolod Ganin

    10/25/2020, 6:08 PM
    Is there a way to change internal paddings in
    TextField
    ?
    a
    • 2
    • 5
  • g

    Grigorii Yurkov

    10/25/2020, 7:35 PM
    Why not make
    @Preview
    workable with Composable functions with arguments? As I understand almost all arguments are data classes. Compiler can instantiate them using primary constructor. For example:
    data class Post(
        val title: String,
        val description: String
    )
    Default instance for this class can be
    Post("Title", "Description")
    . Same with Lists of data classes, but compiler can add index for each instance
    Post("Title №0", "Description №0")
    ,
    Post("Title №1", "Description №1")
    , etc. So in most cases you don't need to create special preview composable functions or mess around with
    @PreviewParameter
    . What do you think?
    👍 3
    👎 4
    c
    w
    • 3
    • 4
  • a

    AG

    10/25/2020, 10:13 PM
    Hi everyone, is it known issue that textfield doesn't work after closing the keyboard? i.e its becomes non clickable and not focused anymore
    👀 1
    w
    m
    d
    • 4
    • 3
  • a

    Afzal Najam

    10/26/2020, 1:42 AM
    Is the opacity of the
    drawShadow
    modifier supposed to change the opacity of the whole Box? Changing the
    0.3f
    opacity changes the opacity of the whole box and its contents. Simplified example:
    @Composable
    private fun StrangeButton() {
        Box(
            modifier = Modifier.then(
                Modifier.drawShadow(
                    elevation = 4.dp,
                    opacity = 0.3f
                )
            ).then(
                Modifier.background(
                    color = Color.Green
                )
            )
        ) {
            Image(
                asset = Icons.Default.Person,
                colorFilter = ColorFilter.tint(Color.White)
            )
        }
    }
    z
    • 2
    • 3
  • i

    Irving

    10/26/2020, 1:48 AM
    Still can't see the Compose source code in 4.2.14Canary?😢😢
    z
    j
    g
    • 4
    • 5
  • a

    Afzal Najam

    10/26/2020, 2:52 AM
    There's no way to specify duration for a spring animation spec?
    i
    • 2
    • 3
  • p

    Prashant Priyadarshi

    10/26/2020, 6:26 AM
    Using MutableState vs LiveData in compose For displaying UI using simple variable, say "name" in compose, which of the below options is better ? 1. using state in viewModel : val name = mutableStateOf<String>("") in ui : simply access it as viewModel.name 2. using live data val _name = MutableLiveData<String>("") val displayName = Transformations.map(_name){ it?: "" } in ui : val name = viewModel.displayName.observeAsState("")
    s
    g
    +3
    • 6
    • 10
  • a

    alorma

    10/26/2020, 6:46 AM
    Which modules would you like that ComposeDrawer provides by default, to help you build faster and better apps? https://github.com/alorma/ComposeDrawer
    a
    • 2
    • 3
  • i

    Irving

    10/26/2020, 9:46 AM
    Can we set any enter or exit animation with navigation-compose?
    f
    i
    • 3
    • 5
  • d

    David Wadge

    10/26/2020, 1:01 PM
    The option to run via wifi (visible in the Running Devices dropdown) has disappeared for me in Canary 4.2/14. Has anyone else experienced this?
    ➕ 2
    b
    • 2
    • 1
  • a

    alorma

    10/26/2020, 6:33 PM
    why is not possible to do a
    try
    inside a @Composable block?
    @Composable
    override fun build() {
       try {
    
       }
    }
    g
    j
    +3
    • 6
    • 12
  • a

    alorma

    10/26/2020, 6:58 PM
    And another question, how can I simulate the "onResume" behaviour?
    g
    • 2
    • 1
  • g

    Gabriel

    10/26/2020, 7:45 PM
    I keep getting this but I'm not sure why:
    e: androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.0.0-alpha07) expects a minimum runtime version of 1.0.0-alpha07. The version of the runtime on the classpath currently is 0.1.0-dev16.
    my versions are all the same
    const val COMPOSE_VERSION = "1.0.0-SNAPSHOT"
    implementation("com.github.skydoves:landscapist-glide:1.0.7")
    implementation("androidx.navigation:navigation-compose:$COMPOSE_VERSION")
    implementation("androidx.compose.runtime:runtime-livedata:$COMPOSE_VERSION")
    implementation("androidx.compose.material:material:$COMPOSE_VERSION")
    implementation("androidx.compose.ui:ui:$COMPOSE_VERSION")
    implementation("androidx.ui:ui-tooling:$COMPOSE_VERSION")
    and it's from a snapshot
    maven("<https://androidx.dev/snapshots/builds/6924113/artifacts/repository>")
    l
    a
    e
    • 4
    • 13
  • a

    Afzal Najam

    10/26/2020, 9:18 PM
    Saw a similar demo with SwiftUI and wanted to try it with Jetpack Compose. Found a couple of bugs along the way. Also wondered if shadow colour should be a thing, even though it feels like a weird concept. https://twitter.com/AfzalivE/status/1320835734782283778
    👍 11
    a
    a
    • 3
    • 3
  • j

    Jeremy

    10/26/2020, 10:14 PM
    Is there any to trigger a callback when the end of a lazycolumn scroll has been reached? aka infinite scroll?
    a
    a
    • 3
    • 4
  • j

    jean pokou

    10/26/2020, 10:21 PM
    How can I change the LinearGradient shader, I am using LinearGradientShader but I don’t know how to pass it to drawRect()?
    n
    • 2
    • 5
  • c

    Cash Hsiao

    10/27/2020, 4:53 AM
    I'm trying to use
    BottomSheetScaffold
    to implement bottom sheet behavior. In old
    BottomSheetBehavior
    we have some middle states like
    STATE_DRAGGING
    or
    STATE_HALF_EXPANDED
    , however now the
    BottomSheetValue
    have only
    Collapsed
    and
    Expanded
    . Is there any plan to implement additional states or other ways to deal with the middle states?
    m
    m
    • 3
    • 4
  • c

    Chethan

    10/27/2020, 5:29 AM
    How can I make this layout in Android compose without using constrain layout , I couldn’t done this just by simple Row , Column combination and possible option of layout alignment. I have done this using constrain layout and it goes as follows
    @Preview
    @Composable
    fun ConfirmationScreen() {
    
        ConstraintLayout(
            modifier = Modifier.fillMaxHeight().fillMaxWidth().background(Color.White)
        ) {
    
            val (topBar, confirmationText, continueButton) = createRefs()
    
           TopAppBarFlat(
                topBarTitle = "Screen Title",
                topBarColor = Color.White,
                topBarLeftIcon = R.drawable.ic_back,
                navigation = {
    
                },
                modifier = Modifier.constrainAs(topBar) {
                    top.linkTo(<http://parent.top|parent.top>)
                }
            )
    
            Column(
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center,
                modifier = Modifier.fillMaxWidth().wrapContentHeight().constrainAs(confirmationText) {
                    bottom.linkTo(<http://continueButton.top|continueButton.top>)
                    centerVerticallyTo(parent)
                }
            ) {
    
                Image(
                    asset = imageResource(id = R.drawable.test),
                    modifier = Modifier.fillMaxWidth(0.5F)
                )
    
                Text(
                    text = "Screen Title.",
                    style = TextStyle(
                        color = Color.Black,
                        fontSize = 16.sp,
                        fontWeight = FontWeight.Bold,
                        textAlign = TextAlign.Center
                    ),
                    fontSize = 14.sp,
                    color = Color.Black,
                    modifier = Modifier.padding(10.dp)
                )
    
                Text(
                    text = "Description....",
                    style = TextStyle(
                        color = Color.Black,
                        fontSize = 14.sp,
                        fontWeight = FontWeight.Normal,
                        textAlign = TextAlign.Center
                    ),
                    fontSize = 14.sp,
                    color = Color.Black,
                    modifier = Modifier.padding(start = 50.dp, end = 50.dp)
                )
            }
    
            Button(
                onClick = {
    
                },
                modifier = Modifier.fillMaxWidth().padding(10.dp).preferredHeight(40.dp)
                    .constrainAs(continueButton) {
                        bottom.linkTo(parent.bottom)
                    },
                backgroundColor = Color.Black
            ) {
                Text(
                    text = "OK",
                    style = TextStyle(
                        color = Color.White,
                        fontSize = 16.sp,
                        fontWeight = FontWeight.Bold,
                        textAlign = TextAlign.Center
                    )
                )
            }
        }
    }
    
    
    @Composable
    fun TopAppBarFlat(
        topBarTitle: String,
        topBarColor: Color = Color.Black,
        topBarLeftIcon: Int = R.drawable.ic_back,
        navigation: () -> Unit,
        modifier: Modifier = Modifier.fillMaxWidth()
    ) {
        TopAppBar(
            elevation = 0.dp,
            title = { Text(text = topBarTitle) },
            navigationIcon = {
                IconButton(onClick = { navigation() }) {
                    Icon(vectorResource(topBarLeftIcon))
                }
            },
            backgroundColor = topBarColor,
            modifier = modifier
        )
    }
    b
    • 2
    • 8
  • k

    Kshitij Patil

    10/27/2020, 6:39 AM
    How to center a text?
    Column(Modifier.fillMaxSize()) {
       Text("Dashboard will be here", Modifier.wrapContentSize(Alignment.Center))
    }
    is not working
    c
    a
    • 3
    • 9
  • p

    Prashant Priyadarshi

    10/27/2020, 7:06 AM
    I started using compose 1.0.0-alpha05
    ProvideEmphasis(emphasis = EmphasisAmbient.current.medium)
    it is giving compiler error EmphasisAmbient is not resolved How to fix it
    • 1
    • 1
Powered by Linen
Title
p

Prashant Priyadarshi

10/27/2020, 7:06 AM
I started using compose 1.0.0-alpha05
ProvideEmphasis(emphasis = EmphasisAmbient.current.medium)
it is giving compiler error EmphasisAmbient is not resolved How to fix it
solution is to use use 
AmbientEmphasisLevels
as suggested by @alorma
View count: 3