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

    Lucien Guimaraes

    07/16/2021, 4:12 PM
    Is there any recommendation to handle UI as State ? I currently have a Flow<UIState>, UIState being a sealed class. In my Screen with a when(uiState) depending of the value I display different Composable. The thing is, I crash when a different value is pushed (for example Loading -> Success is fine, but Success -> Error I crash). Any idea why ? 🤔 Code is in thread
    b
    c
    +1
    25 replies · 4 participants
  • r

    raenardev

    07/16/2021, 5:25 PM
    Is there a way to ensure some element center themselves by some text center?
    @Composable
    fun TextVerticalCenter() {
        Row(verticalAlignment = CenterVertically, modifier = Modifier.background(Color.Black)) {
            Box(
                Modifier
                    .size(8.dp)
                    .background(Color.White)
            )
            Text(text = "Hello", color = Color.White, fontSize = 24.sp)
        }
    }
    If you look at screenshots, you can see that the box is slightly off center to the top (Even when all letters are same height). It is even more evident when looking at numbers. Sorry if i missed it while searching slack, but so far it seems that we have to wait for some way to turn off font padding for that: https://stackoverflow.com/questions/66126551/jetpack-compose-centering-text-without-font-padding
    a
    3 replies · 2 participants
  • d

    Dominaezzz

    07/16/2021, 9:41 PM
    What is the use case for
    detectDragGestures
    ? Given that
    onDragStart
    's
    position
    parameter is not the one from the user's mouse down and instead the one after the "slop" movement. This makes is such that in any draggable region with multiple elements (
    LazyColumn
    ) you cannot determine which element the user intended to drag from.
    a
    9 replies · 2 participants
  • c

    Colton Idle

    07/16/2021, 11:07 PM
    Is there a compose navigation video from the Android Developers youtube account? I could have sworn I had one bookmarked from around Google I/O time, but I can't find it. Now I don't know whether I'm just going crazy or my google search is failing me.
    i
    1 reply · 2 participants
  • m

    ms

    07/17/2021, 2:55 AM
    I'm having a strange bug, when I try to show BottomSheet using
    BottomSheetScaffold
    it closes right away
    BottomSheetScaffold(
                    scaffoldState = bottomSheetScaffoldState,
                    sheetContent = {
                        LazyColumn {
                            items(count = 10) {
                                Text(
                                    text = "Item $it",
                                    modifier = Modifier.padding(vertical = 8.dp)
                                )
                            }
                        }
                    },
                ) {
                    Box(
                        modifier = Modifier.fillMaxSize().padding(it),
                        contentAlignment = Alignment.Center
                    ) {
                        Button(
                            onClick = {
                                coroutineScope.launch {
                                    bottomSheetScaffoldState.bottomSheetState.expand()
                                }
                            },
                        ) {
                            Text(text = "Open sheet")
                        }
                    }
                }
    a
    7 replies · 2 participants
  • j

    Jason Inbody

    07/17/2021, 3:11 AM
    I'm trying to build a background video player and copying from this code https://github.com/takahirom/jetpack-compose-exoplayer-sample/blob/master/app/src/main/java/com/github/takahirom/composeexoplayer/MainActivity.kt. But I'm trying to track down imports that have changed. I can't seem to find
    import androidx.compose.runtime.savedinstancestate.savedInstanceState
    and I didn't see any name changes from the update logs. Did this name change? The android studio also cant find it...
    c
    a
    4 replies · 3 participants
  • m

    Mjahangiry75

    07/17/2021, 7:16 AM
    Is there a way to have a shared
    viewmodel
    between two `composable`s ? and inject them using
    dagger-hilt
    i
    1 reply · 2 participants
  • a

    Abhishek Dewan

    07/17/2021, 7:45 AM
    anybody recently noticing that android stuido wont deploy latest changes to the emulator/device and if you uninstall and install the app again everything just works
    d
    n
    +2
    6 replies · 5 participants
  • p

    Peter Mandeljc

    07/17/2021, 1:47 PM
    is it currently possible to set up theme, without using xml-theming at all? For example, I currently have to use xml theme with statusBarColor and primaryColor stuff set, otherwise colors are different, before activities start. I'm using accompanist to set up system bar colors tough
    a
    6 replies · 2 participants
  • a

    Alexander Suraphel

    07/17/2021, 3:12 PM
    body { font-family: .AppleSystemUIFont; font-size: 13;} ul li {list-style-type:circle;}androidx.compose.ui.tooling.preview.PreviewActivity is not an Activity subclass or alias
    🔂 1
    p
    2 replies · 2 participants
  • j

    Jason Inbody

    07/17/2021, 5:01 PM
    struct SignInView : View {
        @State var createAccount = false
        @State var forgotPassword = false
        
        var body: some View {
            ZStack{
                VStack(alignment: .center, spacing: 15) {
                if(!createAccount && !forgotPassword){
                    Text("Sign In").font(.title).bold().foregroundColor(.white)
                    TextField("Email Address", text: self.$email)
                }
                if(createAccount){
                    Text("Create Account").font(.title).bold().foregroundColor(.white)
                    TextField("Email Address", text: self.$email)
                    SecureField("Password", text: self.$password)
                    SecureField("Confirm Password", text: self.$confirm)
                    Button(action: {self.createUserAccount()}) {
                        Text("Create Account")
                    }
                } else if (forgotPassword) {
                    Text("Forgot Password").font(.title).bold().foregroundColor(.white)
                    TextField("Email Address", text: self.$email)
                    Button(action: {self.sendResetCode()}) {
                        Text("Email Reset Code")
                    }
                    TextField("Reset Code", text: self.$code)
                    Button(action: {self.resetPassword()}) {
                        Text("Reset Password")
                    }
                }
            }
        }
    }
    a
    e
    13 replies · 3 participants
  • j

    Jason Inbody

    07/17/2021, 5:03 PM
    Is there a state variable equivalent in compose? Sorry if this stupidly obvious, just started learning compose.
    k
    1 reply · 2 participants
  • j

    Jason Inbody

    07/17/2021, 5:46 PM
    I'm trying to follow the examples in here https://developer.android.com/jetpack/compose/state
    var signInState by rememberSaveable { mutableStateOf("login") }
    if(signInState == "login") {
        Login(state = signInState)
    }
    I want to switch states by clicking the button like below
    @Composable
    fun Login(state: String) {
                TextButton(
                    onClick = { state = "signup" },
                    colors = ButtonDefaults.textButtonColors(
                        backgroundColor = Color(0x00FFFFFF),
                        contentColor = Color.White,
                        disabledContentColor = Color(0x00FFFFFF),
                    ),
                ) {
                    Text("Create Account")
                }
    }
    and then I get an error on
    onClick = { state = "signup" },
    that says
    Val cannot be reassigned
    i
    d
    8 replies · 3 participants
  • j

    James Black

    07/17/2021, 5:58 PM
    I am trying to use model-view-intent but have something not certain how to do. Basically I have Row { Button(onClick = { Log.d("UpvoteView", "heart pressed") }) { Text("+❤️") } I have this. fun View.clicks(): Flow<Unit> = callbackFlow { val listener = View.OnClickListener { this.trySend(Unit).isSuccess } setOnClickListener(listener) awaitClose { setOnClickListener(null) } } How can I get ‘clicks’ to work in the onclick function for the button? ‘This’ is for rowscope I learned. I would like to do something like this in a way that works with compose. override fun viewEvents(): Flow<MainViewEvent> { val flows = listOf( heartButton.clicks().map { MainViewEvent.LoveItClick }, thumbButton.clicks().map { MainViewEvent.ThumbsUpClick }, cloudButton.clicks().map { MainViewEvent.CloudClick(scope) } ) return flows.asFlow().flattenMerge(flows.size) }
    :thread-please: 4
    m
    5 replies · 2 participants
  • s

    Stylianos Gakis

    07/17/2021, 10:21 PM
    I was trying to recreate one of SwiftUI tutorial UIs for practice in Compose and I would like to get some feedback on how this could be done easier, more in the thread 🧵
    n
    5 replies · 2 participants
  • d

    Dominaezzz

    07/18/2021, 12:04 AM
    Is there a better way to write this?
    val someBoolean = true // this is calculated
    val translationSize = 100f // this is calculated
    
    val animatedDelta by animateFloatAsState(if (someBoolean) 0.0f else 1.0f)
    val value = if (someBoolean) {
        animatedDelta * -translationSize
    } else {
        (1 - animatedDelta) * translationSize
    }
    a
    l
    20 replies · 3 participants
  • c

    Colton Idle

    07/18/2021, 2:18 AM
    For anyone that wasn't aware. accompanist coil and glide are deprecated. https://github.com/google/accompanist/releases I moved to coil directly since it added support for compose and the apis seem to be easier to work with, I don't need a weird crop type anymore, and the intermittent image loading failures are all gone. Great job coil team and of course thanks to accompanist team for paving the way.
    🚀 1
    ➕ 1
    🔝 1
    ❤️ 1
    :thank-you: 2
    🎉 8
    s
    3 replies · 2 participants
  • j

    Jason Inbody

    07/18/2021, 3:00 AM
    Is there anything in compose like SwiftUI observable objects. The observable objects can be used as singletons and there values, when changed can update UI states across the app. Other wise it looks like I have to place callback all over my app. Is there any way over snaking callbacks all over then place?
    n
    s
    4 replies · 3 participants
  • j

    Jason Inbody

    07/18/2021, 3:03 AM
    or maybe even binding variables? In swiftui you could create binding variables you could send down into code and when it changed inside a couple layers down in some functions it would still signal a state change and update the UI state
    a
    1 reply · 2 participants
  • j

    Jeff

    07/18/2021, 5:11 AM
    After I click login once (and it fails for example), if I later change the value of email or password, the code in
    onClick
    gets called every time without a click on the button 🤷🏾
    var userEmail by remember { mutableStateOf("") }
    var userPassword by remember { mutableStateOf("") }
    Button(
        text = "Log in",
        onClick = {
            viewModel.login(userEmail, userPassword)
        }
    )
    a
    a
    16 replies · 3 participants
  • a

    Abhishek Dewan

    07/18/2021, 6:56 AM
    can someone please help me understand why my bottom navigation composable causes the screen to reset when I moved between the bottom navigation tabs. Code in thread
    i
    m
    8 replies · 3 participants
  • a

    AG

    07/18/2021, 7:48 AM
    can someone help me to understand why changing bottomSheetScaffoldState value inside launchedeffect not updating bottom sheet, with coroutinescope.launch everything works right, code in a thread
    m
    5 replies · 2 participants
  • g

    Gagandeep

    07/18/2021, 12:08 PM
    Hello All, Facing an error while trying to use compose java.lang.NoSuchMethodError: No static method setContent$default(Landroidx/activity/ComponentActivity;Landroidx/compose/runtime/CompositionContext;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V in class Landroidx/activity/compose/ComponentActivityKt; or its super classes (declaration of 'androidx.activity.compose.ComponentActivityKt' appears in /data/app/~~BzN_IRidzKvmf62uFiBXDw==/com.graymatrix.did-sS4KMabqpUrHzNaHQrYCaA==/base.apk) at com.zee5.ComposeActivity.onCreate(ComposeActivity.kt:13) at android.app.Activity.performCreate(Activity.java:8006) at android.app.Activity.performCreate(Activity.java:7990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3584) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2246) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:233) at android.app.ActivityThread.main(ActivityThread.java:8010) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978) ******************************************************************************************** build.gradle
    buildFeatures {
        compose = true
        buildConfig = true
        viewBinding = true
    }
    
    compileOptions {
        isCoreLibraryDesugaringEnabled = true
        sourceCompatibility = Versions.java
        targetCompatibility = Versions.java
    }
    
    kotlinOptions {
        jvmTarget = Versions.java.name
    }
    composeOptions {
        kotlinCompilerExtensionVersion = Versions.kotlinCompilerExtension
        kotlinCompilerVersion = Kotlin.version
    }
    kotlin version 1.5.20 compose version 1.0.0-rc02
    :thread-please: 5
    l
    d
    +1
    14 replies · 4 participants
  • p

    Peter Mandeljc

    07/18/2021, 4:25 PM
    are there any bad ideas, that you should not use
    CompositionLocal
    for? Would it be a bad idea, to make a provider for
    ViewModel
    ?
    a
    1 reply · 2 participants
  • a

    Alexander Suraphel

    07/18/2021, 4:46 PM
    LazyColumn(modifier = modifier) {
        for (name in names) {
            Greeting(name = name)
            Divider(color = Color.Black)
        }
    }
    p
    c
    23 replies · 3 participants
  • p

    Peter Mandeljc

    07/18/2021, 4:56 PM
    I'm theory crafting how to approach callback hell in compose. Let's say I have code like below. How would you avoid passing callback down to the child?
    @HiltViewModel
    class WorldViewModel @Inject constructor(): ViewModel() {
        fun hello() {
        }
    }
    
    @Composable
    fun World(vm: WorldViewModel = hiltViewModel()) {
        Continent(onClick = vm::hello)
    }
    
    @Composable
    fun Continent(onClick: () -> Unit) {
        Country(onClick)
    }
    
    @Composable
    fun Country(onClick: () -> Unit) {
        State(onClick)
    }
    
    @Composable
    fun State(onClick: () -> Unit) {
        Button(onClick = onClick) { }
    }
    👍 1
    c
    a
    +1
    55 replies · 4 participants
  • m

    ms

    07/18/2021, 5:32 PM
    STATE MANAGEMENT & ARCHITECTURE DISCUSSION 🧵 1. What kind of architecture are you using other than
    ViewModel
    ? 2. Are there any plans for a library which suits better for Compose? 3. What is the recommended approach in your opinion?
    i
    1 reply · 2 participants
  • a

    Alexander Suraphel

    07/18/2021, 5:33 PM
    Why is
    by
    used instead of assignment at
    var isSelected by remember { mutableStateOf(false) }
    I’m following Google’s codelab
    m
    1 reply · 2 participants
  • a

    Alexander Suraphel

    07/18/2021, 5:39 PM
    looks like a way to skip the
    .value
    getter …
    a
    1 reply · 2 participants
  • r

    rsktash

    07/18/2021, 8:06 PM
    Hello! Does the new
    transition.AnimatedContent
    feature support child element animation/transition?
    d
    2 replies · 2 participants
Powered by Linen
Title
r

rsktash

07/18/2021, 8:06 PM
Hello! Does the new
transition.AnimatedContent
feature support child element animation/transition?
@Doris Liu
d

Doris Liu

07/20/2021, 6:44 PM
Did you mean shared element transition, i.e. an element shared across different content? Or different enter/exit transition for children? The former is not yet supported, but will be added to AnimatedContent later. The latter is already available. 🙂
View count: 3