https://kotlinlang.org logo
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
  • h

    Halil Ozercan

    07/27/2020, 1:54 PM
    Hello everyone, I built a youtube-like videoplayer using 100% Compose. This was my initial challenge to get a hang of Compose for the first time. Foremost, I want to thank everyone in this channel who created a very welcoming and helpful environment. It was a blast getting to understand some fundamental concepts like states, ambients, and composition callbacks. Also, implementing a SeekBar sent me down a very low level journey on gesture detection in compose. I'm planning to open source the app when I'm confident with the code (best practices were not applied all the time 🙂 )

    https://youtu.be/1Drhi5JM5Q4▾

    ❤️ 13
    👍 13
    😲 6
    e
    • 2
    • 2
  • b

    brandonmcansh

    07/27/2020, 3:36 PM
    Above snippet is the drawerContent in the BottomDrawerLayout)
    m
    • 2
    • 4
  • f

    Fudge

    07/27/2020, 3:53 PM
    Is there any way to rotate a component?
    z
    • 2
    • 2
  • h

    Horv

    07/27/2020, 4:02 PM
    Are the source code for
    1.4.0-dev-withExperimentalGoogleExtensions-20200720
    kotlin-compiler available online anywhere?
    j
    • 2
    • 1
  • g

    galex

    07/27/2020, 4:12 PM
    Can I make a composable function that will show up some content on top of its children?
    f
    • 2
    • 3
  • r

    romainguy

    07/27/2020, 4:18 PM
    @Horv The plugin itself or the extensions in the compiler?
    h
    j
    • 3
    • 5
  • v

    Vinay Gaba

    07/27/2020, 4:44 PM
    I am trying to make a child composable non-interactive under certain conditions. I don’t know anything about the child composable and can’t change its definition either(so can’t simply pass a modifier to it). So I was trying to wrap it inside a Box and then applying the
    rawPressStartGestureFilter
    to it. This actually works but it also ends up interfering with the scroll of the screen that these composables are on (this is expected as this is how you’d expect this gesture filter to work). Is there a better way to accomplish this? Just using
    tap
    or
    clickable
    on the parent composable still propagates the touch to the child composable so I need a better way to intercept the touch while keeping the scroll functionality intact.
    g
    z
    • 3
    • 14
  • s

    spierce7

    07/27/2020, 5:51 PM
    I noticed that there isn’t a
    Modifier.margin
    in compose. Is there a way to achieve something similar to margin?
    a
    v
    b
    • 4
    • 5
  • f

    Fudge

    07/27/2020, 7:05 PM
    Consider the Box:
    Box(backgroundColor = Color.Blue) {
       Text("Foo")
    }
    Without specifying any height or width constraints, the
    Box
    will automatically size to be the size of the Text (picture 1). Now, consider picture 2. The text
    Foo
    is not a child of the left box, or the right one. Therefore a possible implementation of that would use a
    Stack
    .
    Stack {
            Row {
                Box(Modifier.weight(1f).fillMaxWidth(), backgroundColor = Color.Blue)
                Box(Modifier.weight(1f).fillMaxWidth(), backgroundColor = Color.Red)
            }
            Text(text = "foo", textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth())
        }
    The problem now though, is that
    Box
    has no children, and would have a height of 0. Here's another attempt using `ConstraintLayout`:
    ConstraintLayout {
        val (left,right,text) = createRefs()
        Box(backgroundColor = Color.Blue, modifier = Modifier.weight(1f).constrainAs(left){
            linkTo(start = parent.start, end = right.start)
        })
        Box(backgroundColor = Color.Red,modifier = Modifier.weight(1f).constrainAs(right){
            linkTo(start = left.start, end = parent.end)
        })
    
        Text(text = "foo", modifier = Modifier.constrainAs(text){
            linkTo(start = left.start, end = right.end, bottom = left.bottom, top = left.top)
        })
    }
    This has the same reult as the
    Stack
    approach, with the boxes not showing at all. So how do I communicate to compose that the boxes should be at least the size of the text? The aim is to not hardcode constraints such as
    Modifier.height()
    .
    m
    s
    • 3
    • 8
  • t

    Taras Koshkin

    07/27/2020, 10:24 PM
    Do the
    Preview
    functions get stripped out during compile or does it just rely on r8/proguard to strip the unused code?
    👀 1
    l
    z
    +2
    • 5
    • 9
  • v

    Val Salamakha

    07/28/2020, 3:49 AM
    Does kotlin 1.4.0-rc support Compose 0.1.0-dev15?
    v
    g
    • 3
    • 4
  • m

    Mohamed Elfiky

    07/28/2020, 7:15 AM
    is preview working in dev15?
    m
    • 2
    • 1
  • d

    Dima Avdeev

    07/28/2020, 10:10 AM
    Is it possible to use multiplatform gradle plugin to try @Composable functions ?
    plugins {
        id("com.android.library")
        kotlin("multiplatform")
    }
    instead of
    plugins {
        id("com.android.library")
        id("kotlin-android")
    }
    j
    a
    +2
    • 5
    • 10
  • f

    Fudge

    07/28/2020, 10:48 AM
    What should I do if displaying a few items in a
    LazyColumnItems
    lags the screen for like 0.5 seconds when displayed? Is this perhaps because this is a preview, or do I have some way of profiling where the device spends its time?
    t
    h
    • 3
    • 17
  • f

    Fudge

    07/28/2020, 1:50 PM
    var state by savedInstanceState{0}
    Button(onClick ={state++}) {
        Text(text = "Increase $state")
    }
    Am I right in thinking
    state
    should be saved when I restart the app? Because it doesn't do that
    a
    t
    j
    • 4
    • 31
  • d

    David Mcrae Jr

    07/28/2020, 1:58 PM
    class UserViewModel : ViewModel() {
        private val _username = MutableLiveData<String>()
        val username: LiveData<String>
            get() = _username
    
        private val _password = MutableLiveData<String>()
        val password: LiveData<String>
            get() = _password
    
        init {
            setUsername("")
            setPassword("")
        }
    
        fun setUsername(username: String) {
            _username.value = username
        }
    
        fun setPassword(password: String) {
            _password.value = password
        }
    
    }
    
    @Composable
    fun LoginView(userViewModel: UserViewModel) {
        val context = ContextAmbient.current
    
        Column(
            modifier = Modifier.fillMaxWidth().padding(top = Dp(50.0F)),
            horizontalGravity = Alignment.CenterHorizontally
        ) {
            FilledTextField(
                value = userViewModel.username.toString(),
                onValueChange = { it: String ->
                    userViewModel.setUsername(it)
                },
                label = { Text(stringResource(id = R.string.username_label)) },
                backgroundColor = Color.Transparent,
                placeholder = { Text(stringResource(id = R.string.username_placeholder)) },
                keyboardType = KeyboardType.Email,
                activeColor = colorResource(id = R.color.mastery_main)
            )
    
            FilledTextField(
                value = userViewModel.password.toString(),
                onValueChange = { it: String ->
                    userViewModel.setPassword(it)
                },
                label = { Text(stringResource(id = R.string.password_label)) },
                backgroundColor = Color.Transparent,
                visualTransformation = PasswordVisualTransformation(),
                keyboardType = KeyboardType.Password,
                activeColor = colorResource(id = R.color.mastery_main)
            )
        }
    }
    I have something like this for my login view and believe I’m using the LiveData correctly but I am seeing the object reference in the field and not the string value of username or password, thoughts?
    j
    • 2
    • 3
  • w

    Wajahat Karim

    07/28/2020, 2:04 PM
    I have been trying to play around
    state
    in Compose dev15. So, if create a state like
    val numState by state { 0 }
    , and use this in any composable like Text, it works good and fine. On doing
    numState++
    , the Text updates. But, if I use some custom data class like this below code:
    data class Point(val x:Int = 0, val y:Int = 0)
    And using this class to create state like
    val pointState by state { Point(3,4) }
    , and now if I update this like
    pointState.x++
    , then the Composables using this state aren't recomposed and updated. I don't understand how am I supposed to use state?
    a
    t
    • 3
    • 22
  • h

    Horv

    07/28/2020, 2:31 PM
    Just getting into Compose, struggling a bit with styling and themes. What's the best practice way to set text color? I'd imagined Text-komponent would pick some color from my Theme's colors but that doesn't seem to be the case?
    v
    p
    n
    • 4
    • 7
  • b

    brandonmcansh

    07/28/2020, 2:42 PM
    Does anyone have a Flow<> example with Compose for observing a list?
    z
    j
    • 3
    • 33
  • b

    Brett Best

    07/28/2020, 3:03 PM
    My Android Studio Kotlin plugin updated however now I’m getting errors for all my Compose code saying it was compiled using a pre-released version of Kotlin. Perhaps related to https://kotlinlang.slack.com/archives/CJLTWPH7S/p1595908172474900 🤔
    z
    f
    +3
    • 6
    • 14
  • f

    Fudge

    07/28/2020, 7:45 PM
    Maybe I’m misunderstanding the first parameter of
    state
    but it seems like it makes it so writes to the variable somehow get ignored, so I would change the value but after the recomposition the value is the same as it was before. I can’t really give a complete example since its in a middle of a lot of things and this only happens in exactly the second instance of this state variable. But the magical nature of remember {} and such make it impossible to debug. At this point it seems it would be easier to roll out my own implementation of state.
    t
    z
    l
    • 4
    • 25
  • z

    Zach Klippenstein (he/him) [MOD]

    07/28/2020, 9:23 PM
    Pulling this out of the thread to avoid derailing it… What does this mean for
    savedInstanceState
    ? Looks like it’s stuck around for now?
    l
    b
    +3
    • 6
    • 58
  • p

    Patrick Yin

    07/29/2020, 12:03 AM
    About
    @Preview
    , will the @Preview marked method be removed (or changed) when assembling release build?
    j
    g
    k
    • 4
    • 22
  • h

    Horv

    07/29/2020, 4:08 PM
    I'm creating a "Sign in with Google"-button for my Android app and looking at https://developers.google.com/identity/branding-guidelines for guidence. However, when adding the icon it seems the image get's some sort of border/shadow. How do I remove that?
    Button(
                        onClick = {
                            Log.d("Login", "ButtonClicked!")
                            handleLoginButtonPress(loginFragment, context)
                        },
                        backgroundColor = Color.White,
                        padding = InnerPadding(8.dp)
                    ) {
                        Image(
                            asset = imageResource(id = R.drawable.btn_google_light_normal_hdpi),
                            modifier = Modifier.height(40.dp)
                                .padding(0.dp)
                                .absolutePadding(0.dp, 0.dp, 0.dp, 0.dp)
                                .drawShadow(0.dp),
                            contentScale = ContentScale.Inside
                        )
                        Text(
                            "Sign in with Google",
                            color = Color(75, 75, 75),
                            fontFamily = fontFamily(listOf(font(R.font.roboto_medium))),
                            modifier = Modifier.padding(24.dp, 0.dp, 0.dp, 0.dp)
                        )
                    }
    a
    • 2
    • 3
  • c

    CLOVIS

    07/29/2020, 5:36 PM
    Hi! I have heard a lot about Jetpack Compose from Google's devs, and it really seems to me like it's going to be a big change to how we view UI, as developers. Google has hinted multiple times that it was technically possible to run it on other platforms (web, desktop) but they're not planning (at least at the moment) on making that leap. I guess it's quite a big commitment and they'd rather be sure that it's working perfectly before adding a lot of work on their plates ^^ Well, I think that probably means it should be a community effort. I'd like to know if there's already an open source project working on this, or some other way I can contribute to make this a reality. I think Compose and Kotlin Multiplatform are the perfect blend that will finally make it possible to write a UI once for everything :)
    f
    z
    a
    • 4
    • 5
  • l

    louiscad

    07/29/2020, 5:39 PM
    Isn't
    Modifier
    the new
    LayoutParams
    in a way?
    v
    z
    +2
    • 5
    • 11
  • v

    Vinay Gaba

    07/29/2020, 5:58 PM
    Random q: UI Components, Widgets, Views Is there anything on the list or elsewhere that you’ll use interchangeably with “Composable function”? I personally like “UI Component” when I’m speaking about a Composable function but wondering what this group thinks.
    z
    r
    +3
    • 6
    • 11
  • f

    Fudge

    07/29/2020, 7:07 PM
    What was the function to check if we are currently in a
    @Preview
    ? I remember there was one but I can't find it. Something like
    Something.isInPreview()
    🤔 1
    j
    i
    +4
    • 7
    • 30
  • g

    galex

    07/29/2020, 7:28 PM
    How do we load images from the web? I thought I saw a Composable to do that, with a temporary image (placeholder)…
    a
    • 2
    • 2
  • r

    romainguy

    07/29/2020, 8:00 PM
    launchInComposition()
    ➕ 6
    g
    l
    a
    • 4
    • 3
Powered by Linen
Title
r

romainguy

07/29/2020, 8:00 PM
launchInComposition()
➕ 6
g

galex

07/29/2020, 8:05 PM
Thank you Romain !
➕ 1
l

Leland Richardson [G]

07/29/2020, 8:58 PM
for some other use cases,
rememberCoroutineScope
is what you want
☝️ 1
a

Adam Powell

07/29/2020, 9:25 PM
yes, the above. If you have something roughly actor-like that you want to run, use
launchInComposition
. If you want to be able to launch jobs as a result of other events and have that scope managed/cleaned up for you, use
rememberCoroutineScope
.
View count: 2