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

    efemoney

    09/16/2020, 9:49 PM
    I believe I know the answer but does animating text size in compose still have the same drawbacks as discussed in some conference talks cc @nickbutcher (I dont have a link handy)
    n
    s
    5 replies · 3 participants
  • g

    Guy Bieber

    09/16/2020, 10:07 PM
    Stack is causing a weird issue for me. I have a stack containing two images. If I wrap them each in column and rows that are centered (gravity) the last image only centers in one axis. Anyone else having this problem.
    z
    6 replies · 2 participants
  • p

    pardom

    09/17/2020, 1:29 AM
    Keyboard input is not working for 
    TextField
     in my emulator. Is this a known issue?
    ➕ 1
    m
    l
    2 replies · 3 participants
  • m

    Mehdi Haghgoo

    09/17/2020, 5:27 AM
    How do you manage navigation in a Compose app? I think I can make startActivity and setResult work, but tends to be quite difficult.
    i
    2 replies · 2 participants
  • b

    bodo

    09/17/2020, 5:30 AM
    I want to do a different layout for different screen sizes. Can you please tell me how it should be done? (e.g. getting screen size in composable function?)
    p
    1 reply · 2 participants
  • b

    Brett Best

    09/17/2020, 7:34 AM
    Curious how people are using a date pickers in compose? I found a library but it uses
    LocalDate
    which is API 26 and above. I need to support API 24.
    p
    2 replies · 2 participants
  • m

    Maxr1998

    09/17/2020, 8:50 AM
    Hi! Just joined the channel. I've dived into Jetpack Compose a few days ago, and it's really, reallly nice so far. I have an issue with the Popup composable however, for some reason it doesn't fill the full screen width, only about 75%, although the child has
    Modifier.fillMaxWidth()
    set. Is that a known issue, or a configuration/usage error on my part? Using Compose alpha02.
    p
    2 replies · 2 participants
  • m

    Maik

    09/17/2020, 9:06 AM
    I have a question of understanding about re-composition. I have written the following simple code example:
    @Composable
    fun StateDemo() {
    var counterOne by remember { mutableStateOf(0) }
    var counterTwo by remember { mutableStateOf(0) }
    var items = remember { mutableStateListOf<Int>() }
    Column {
    Button(onClick = { counterOne++ }) {
    Text("One")
    }
    Button(onClick = { counterTwo++ }) {
    Text("Two")
    }
    Button(onClick = { items.add(counterOne) }) {
    Text("List")
    }
    MyText(counterOne)
    MyText(counterTwo)
    MyList(items)
    }
    }
    @Composable
    fun MyText(counter: Int) {
    Text("counter: $counter (${System.currentTimeMillis()})")
    }
    @Composable
    fun MyList(items: MutableList<Int>) {
    Text("list: ${items.size} (${System.currentTimeMillis()})")
    }
    Unfortunately, the behavior in case of re-composition is not completely clear to me. If I click the button "One", the function "*MyText(counterOne)*" is re-drawn, the function "*MyText(counterTwo)*" remains completely unaffected. The behavior with the button "Two" is similar. Unfortunately in both cases the function "*MyList(items)*" is also redrawn. The behavior is not clear to me. What am I doing wrong! I want to prevent this function from being drawn, because in my opinion it is not involved in the re-composition. Many thanks in advance!
    j
    s
    +1
    7 replies · 4 participants
  • s

    Se7eN

    09/17/2020, 10:27 AM
    I'm using
    Scaffold
    with
    BottomNavigation
    and it looks like the bottom navigation bar is covering
    bodyContent
    Scaffold(
        topBar = {
            TopAppBar(
                title = { ... },
                navigationIcon = { ... },
                actions = { ... },
                backgroundColor = MaterialTheme.colors.surface,
                elevation = 0.dp
            )
        },
        bodyContent = { ChatScreen(viewModel) },
        bottomBar = {
            BottomNavigation(
                backgroundColor = MaterialTheme.colors.surface,
                elevation = if (isSystemInDarkTheme()) 0.dp else 4.dp
            ) {
                BottomNavigationItem(
                    icon = { ... },
                    selected = true,
                    onClick = {},
                    label = { ... },
                )
    
                BottomNavigationItem(
                    icon = { ... },
                    selected = false,
                    onClick = {},
                    label = { ... }
                )
            }
        }
    )
    Is this a bug or am I doing something wrong?
    t
    5 replies · 2 participants
  • s

    Se7eN

    09/17/2020, 11:58 AM
    Is there a way to specify multiple Provide composables to save indentation? Something like:
    Provide(textStyle = TextSyle(...), emphasis = EmphasisAmbient.current.medium) {
        ...
    }
    y
    l
    8 replies · 3 participants
  • m

    Marcin Środa

    09/17/2020, 12:45 PM
    Wow, did anyone notice a strange behavior in JetChat after update?
    n
    p
    3 replies · 3 participants
  • n

    Nat Strangerweather

    09/17/2020, 2:14 PM
    When making a gradient, I see quite a few examples using this, for instance:
    endY =150.dp.toPx()
    but I get "Unresolved Reference: toPx(). What am I doing wrong?
    y
    a
    7 replies · 3 participants
  • a

    Archie

    09/17/2020, 4:35 PM
    I'm really curious whether doing,
    Crossfade(key) {
        when (it) {
            is CaseA -> ComposableA()
            is CaseB -> ComposableB()
            ....
        }
    }
    Is just "similar" (effect wise not implmentation wise) as using
    AnimatedVisibilty
    such as this:
    AnimatedVisibility(
        visible = key == CaseA,
        exit = ...,
        enter = ...,
        content = content
    ) {
        ComposableA()
    }
    AnimatedVisibility(
        visible = key == CaseB,
        exit = ...,
        enter = ...,
        content = content
    ) {
        ComposableB()
    }
    z
    t
    +1
    16 replies · 4 participants
  • c

    Colton Idle

    09/18/2020, 5:44 AM
    What am I doing wrong here? Just want a simple text field that reflects in a text below it as well
    @Composable
    fun MyInput() {
        Column(Modifier.padding(16.dp)) {
            val textState by remember { mutableStateOf(TextFieldValue()) }
            TextField(
                value = textState.text,
                onValueChange = { textState = it) }
            )
            Text("The textfield says: " + textState.text)
        }
    }
    note: I'm trying to learn via little samples from https://foso.github.io/Jetpack-Compose-Playground/cookbook/textfield_changes/ but let me know if there is another resource or some more official docs with these sorts of samples. I understand theres a bunch of sample apps, but I'm just trying to learn component by component first, and not jumping into an entire application.
    m
    t
    +1
    4 replies · 4 participants
  • g

    Geert

    09/18/2020, 8:47 AM
    I was trying to make this example from youtube, but I have 2 problems. The first one is that state is deprecated, but I cant make remember work with these 2 values. The second thing is that I cannot ripple anymore from Modifier Code:
    @Composable
    fun ModifiedShape(){
        // TODO: Replace by remember?
         val (shape, setShape) = state<Shape> { CircleShape }
    
        // TODO: Fix error
        //       Destructuring declaration initializer of type Shape must have a 'component1()' function
        //       Destructuring declaration initializer of type Shape must have a 'component2()' function
        // val (shape, setShape) = remember<Shape> { CircleShape }
        Image(
            asset = imageResource(id = R.drawable.ic_launcher_background),
            modifier = Modifier
                .size(256.dp)
                .padding(16.dp)
                .drawShadow(8.dp, shape)
                .border(6.dp, MaterialTheme.colors.primary, shape)
                .border(12.dp, MaterialTheme.colors.secondary, shape)
                .border(18.dp, MaterialTheme.colors.background, shape)
                // TODO: Add ripple?
                //.ripple(color = MaterialTheme.colors.surface)
                .clickable {
                    setShape(
                        if (shape == CircleShape) {
                            CutCornerShape(topLeft = 32.dp, bottomRight = 32.dp)
                        } else {
                            CircleShape
                        }
                    )
                }
    
        )
    
    }
    y
    b
    21 replies · 3 participants
  • g

    Geert

    09/18/2020, 11:34 AM
    I just upgraded to AS 4.2 Canary 11. But I think I have lost the correct dependency versions. Build.gradle
    classpath "com.android.tools.build:gradle:4.2.0-alpha11"
    Dependencies:
    object Compose {
                const val snapshot = ""
                const val version = "1.0.0-alpha01"
    
                const val core = "androidx.compose.ui:ui:$version"
                const val foundation = "androidx.compose.foundation:foundation:$version"
                const val layout = "androidx.compose.foundation:foundation-layout:$version"
                const val material = "androidx.compose.material:material:$version"
                const val materialIconsExtended = "androidx.compose.material:material-icons-extended:$version"
                const val runtime = "androidx.compose.runtime:runtime:$version"
                const val runtimeLivedata = "androidx.compose.runtime:runtime-livedata:$version"
                const val tooling = "androidx.ui:ui-tooling:$version"
                const val test = "androidx.compose.test:test-core:$version"
                const val uiTest = "androidx.ui:ui-test:$version"
            }
    j
    s
    11 replies · 3 participants
  • s

    Se7eN

    09/18/2020, 11:54 AM
    Does
    ScrollableColumn
    not support nested scrolling? I have a
    LazyRowFor
    and a
    LazyColumnFor
    inside a
    ScrollableColumn
    and it messed up vertical scrolling. Fling scroll doesn't work.
    ScrollableColumn {
        Text(...)
        LazyRowFor(...)
        LazyColumnFor(...)
    }
    y
    a
    +1
    24 replies · 4 participants
  • s

    Se7eN

    09/18/2020, 1:19 PM
    Does android studio builds the project twice when using
    Preview
    ? It looks like sometimes I get an error saying the jar is being used by another process and the build for my emulator succeeds but the build for
    Preview
    fails.
    a
    2 replies · 2 participants
  • n

    Nat Strangerweather

    09/18/2020, 3:39 PM
    Is it possible to detect whether the device is using Gesture navigation or 3-button navigation, as I would like to organise my layout accordingly to avoid large empty areas... I am currently using
    if (ConfigurationAmbient.current.screenHeightDp >= 750) {
        Spacer(modifier = Modifier.height(40.dp))}
    but it does not appear to reflect whether there is a nav bar or not
    f
    s
    4 replies · 3 participants
  • l

    Luke

    09/18/2020, 8:45 PM
    I have some issues integrating compose in my project. I have been referring to the samples as those compile perfectly. Unfortunately, whenever I add in any of my modules :
    android {
        ...
    
        composeOptions {
            kotlinCompilerVersion = "1.4.0"
            kotlinCompilerExtensionVersion = "1.0.0-alpha3"
        }
    
        buildFeatures.compose = true
    }
    
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
        kotlinOptions {
            freeCompilerArgs += listOf(
                "-Xopt-in=kotlin.RequiresOptIn",
                "-Xopt-in=kotlin.Experimental",
                "-Xallow-jvm-ir-dependencies'"
            )
            jvmTarget = "1.8"
        }
    }
    I keep hitting:
    Execution failed for task ':my-module:prepareDebugKotlinCompileTask'.
    > Could not resolve all files for configuration ':my-module:kotlin-extension'.
       > Could not find androidx.compose:compose-compiler:1.0.0-alpha3.
    I don’t understand what could cause this error… Does someone have an idea?
    m
    e
    +1
    5 replies · 4 participants
  • m

    Mohamed Elfiky

    09/19/2020, 2:05 AM
    I have a
    LazyColumnFor
    which it's list is changed over time but when i scroll down and the list changes the
    LazyColumnFor
    does not resize i think and the white space that is left down in it is not scrollable so if no item is showing on the screen i cannot scroll up this a gist for that case: https://gist.github.com/mohamedmelfiky/28c3fbc0466b17ea96e10c8981183717
    a
    1 reply · 2 participants
  • s

    Se7eN

    09/19/2020, 10:03 AM
    Is there any way I can improve my code? I'm using compose-router
    var selectedUser: User? by remember { mutableStateOf(null) }
    
    when(currentScreen) {
        is Routing.Root.Main -> { 
            MainScreen(onChatClick = { user ->
                selectedUser = user
                // change current screen
            }
        }
        is Routing.Root.Conversation -> {
            when (val user = selectedUser) {
                null -> throw IllegalStateException("selectedUser is null")
                else -> ConversationScreen(user)
            }
        }
    }
    I don't like the way I'm handling
    selectedUser
    here
    h
    j
    5 replies · 3 participants
  • h

    Halil Ozercan

    09/19/2020, 12:25 PM
    I've taken SwipeToRefresh implementation from JetNews into my own project. However, I feel like there is an important bug in the implementation that comes to surface when the state of the UI directly starts in refreshing (loading) status.
    refreshingState: Boolean,
    is an argument to the SwipeToRefresh composable. It makes total sense that refreshing status is controlled by the parent. However, inner swipe state and this received state of refresh are combined together to call
    onRefresh
    callback inside the listener for swipe state change as follows:
    val state = rememberSwipeableState(refreshingState) { newValue ->
            // compare both copies of the swipe state before calling onRefresh(). This is a workaround.
            if (newValue && !refreshingState) onRefresh()
            true
        }
    However, something goes wrong in this lambda. Even if the
    refreshingState
    is changed from
    true
    to
    false
    by the parent, this lambda will keep reading it as the first time
    remember
    is called. If
    refreshingState
    was true at the start, it will remain true in the scope of this lambda until composition of
    SwipeRefreshLayout
    leaves the UI. As a workaround, I've changed
    refreshingState
    to a lambda that returns a boolean.
    a
    a
    4 replies · 3 participants
  • s

    Se7eN

    09/19/2020, 12:40 PM
    How to disable elevation overlays?
    y
    l
    5 replies · 3 participants
  • m

    Mohamed Elfiky

    09/19/2020, 6:36 PM
    so i have code like the below with a class represents the whole state of the screen and observing it in the root compose of that screen. is this a bad design from what i saw when i watched leland that the compose compiler is smart enough or will be to know when to recompose. second is using MutableStateFlow or mutableStateOf make any diffrence?
    enum class Sort {
        ownerName,
        taskTitle,
        size
    }
    
    sealed class UiState {
        object Loading : UiState()
        data class Success(
            val data: List<Int>,
            val sortExpanded: Boolean = false,
            val sort: Sort = Sort.ownerName,
        ) : UiState()
        object Error : UiState()
    }
    
    class UiViewModel(repo: Repo) : ViewModel() {
    
        // private val _state = MutableStateFlow<UiState>(UiState.Loading)
        // val state: StateFlow<UiState> get() = _state
        var state by mutableStateOf<UiState>(UiState.Loading)
        private set
    
        fun toggleSortDialog() {}
        ....
    }
    
    @Composable
    fun RootScreenUi() {
        val viewModel = viewModel<UiViewModel>()
        val state = viewModel.state
    
       ....
    }
    j
    a
    4 replies · 3 participants
  • s

    Se7eN

    09/19/2020, 11:07 PM
    TextField
    with
    adjustPan
    messes up the touch. The screen shifts up when text field is focused but when it shifts down, the touch doesn't work correctly. I think it's like the system thinks the screen is still shifted up or something like that. Is this a known issue?
    a
    1 reply · 2 participants
  • k

    Kyant

    09/20/2020, 1:46 AM
    How to change shape for
    OutlinedTextField
    ?
    👍 1
    m
    s
    +1
    8 replies · 4 participants
  • m

    Mehdi Haghgoo

    09/20/2020, 3:52 AM
    Why is it possible to write
    var cost by remember{mutableStateOf(0)}
    but not
    var (cost, setCost) by remember{mutableStateOf(0)}
    ?
    a
    2 replies · 2 participants
  • n

    Namig Tahmazli

    09/20/2020, 6:37 AM
    Hi All. I wonder how is it possible to get scroll x and y value for LazyColumnFor. I know that we can pass scrollState to ScrollableColumn and get scroll x value from state we passed in. But there is not such an option for LazyColumnFor.
    h
    t
    +1
    4 replies · 4 participants
  • m

    Mehdi Haghgoo

    09/20/2020, 8:33 AM
    There is an example in Kotlin docs:
    var selectedId by savedInstanceState<String?> { null }
    Why isn't remember used here? Is it OK (or recommended) to use remember before
    savedInstanceState()
    ?
    a
    f
    2 replies · 3 participants
Powered by Linen
Title
m

Mehdi Haghgoo

09/20/2020, 8:33 AM
There is an example in Kotlin docs:
var selectedId by savedInstanceState<String?> { null }
Why isn't remember used here? Is it OK (or recommended) to use remember before
savedInstanceState()
?
a

andev

09/20/2020, 8:41 AM
savedInstanceState { } already does the remember thingy internally
🎉 1
👏 1
😀 1
f

flosch

09/20/2020, 10:16 AM
For compose I would always recommend to just look into the function sources themselves inside your IDE. The source code is very well documented and most of the time fairly easy to understand on the upper levels! 👍
👍 1
☝️ 1
View count: 4