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

    alorma

    12/23/2020, 6:20 PM
    Hi! Is there a DatePicker / TimePicker for compose?
    g
    • 2
    • 4
  • l

    Lauren Yew

    12/23/2020, 9:08 PM
    Attempting the Jetpack Compose Layouts Demo https://developer.android.com/codelabs/jetpack-compose-layouts?continue=https%3A%2F%2Fd[…]developer.android.com%2Fcodelabs%2Fjetpack-compose-layouts. Anyone know what to use instead of
    Layout(
            modifier = modifier,
            children = children
        ) { measurables, constraints ->
           ...
        }
    My Android Studio (on Compose alpha 9) is saying that API isn't available.
    a
    • 2
    • 6
  • v

    Vsevolod Ganin

    12/23/2020, 10:06 PM
    Is there a precompiled converter from vector drawable (or svg) to `ImageVector`’s builder code? I doubt that material icons from library are done by hand. I have a svg and I want to avoid converting to vector drawable altogether since it will convert to
    ImageVector
    in runtime anyway
    👍 2
    m
    b
    +2
    • 5
    • 11
  • m

    Manuel Lorenzo

    12/23/2020, 10:19 PM
    hey everybody! how do you guys create a SearchView in Compose, you know, the one that is in the top bar? is there a native function for this?
    r
    s
    +2
    • 5
    • 14
  • c

    Chethan

    12/24/2020, 8:55 AM
    How to set drawable left in android compose Text ?
    r
    a
    • 3
    • 6
  • c

    Chethan

    12/24/2020, 9:14 AM
    What I am missing here in this layout arrangement, I want to bring Central Text to very next Dot , not in the center ? Here is my code :
    ConstraintLayout(modifier = Modifier.fillMaxWidth()) {
    
        val (dot, title, deleteButton) = createRefs()
    
        Image(
            asset = vectorResource(id = if (!notifications.readFlag) R.drawable.ic_ellipse_red else R.drawable.ic_ellipse_white),
    
            modifier = Modifier
                .constrainAs(dot) {
    
                    linkTo(
                        start = parent.start,
                        end = title.start
                    )
                    centerVerticallyTo(parent)
                }
        )
    
        Text(
            text = notifications.title,
            style = TextStyle(
                color = black33,
                fontSize = 14.sp,
                fontWeight = FontWeight.Bold,
                textAlign = TextAlign.Start
            ),
            modifier = Modifier.fillMaxWidth(0.9F).constrainAs(title) {
    
                linkTo(
                    start = dot.end,
                    end = deleteButton.start
                )
            }.padding(start = 10.dp)
        )
    
        Image(
            asset = vectorResource(id = R.drawable.ic_icon_delete_gray),
            modifier = Modifier.wrapContentSize()
                .clickable(
                    onClick = {
                        showPopUpToDelete.value = true
                    }
                ).constrainAs(deleteButton) {
                    end.linkTo(parent.end)
    
                    linkTo(
                        start = title.end,
                        end = parent.end
                    )
                }
        )
    }
    This is how presently looking
    r
    • 2
    • 9
  • g

    Geert

    12/24/2020, 10:06 AM
    Is there an working example from Google for implementing the BottomNavigationBar which includes navigation between multiple screens including onbackpress listener? For now i’ve only found these examples: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:na[…]in/java/androidx/navigation/compose/demos/BottomBarNavDemo.kt
    j
    i
    • 3
    • 8
  • k

    Kshitij Patil

    12/24/2020, 10:56 AM
    I had prepared a
    AutoCompleteTextField
    few days ago but with the latest compose (alpha09) it seems like it's a bad idea to put a TextField inside a
    LazyColumn
    as one of its
    item
    , especially when its other items are decided based on what we type in the TextField, as I found my current implementation just gets stuck in an infinite loop of recomposition, freezing the textfield. Any best practices, guidelines to follow in this regard? What should we keep inside a LazyColumn and what we shouldn't?
    d
    r
    a
    • 4
    • 14
  • b

    Bradleycorn

    12/24/2020, 4:17 PM
    Hi All! I'm working with
    derivedStateOf
    and wondering if there is any difference between the following 2 examples? Is one approach "better" than the other? Are there problems with one approach or the other? Is there an advantage to one over the other (other than just the amount of code)? Is example 2 a proper use of
    derivedStateOf
    ? Am I likely to run into concurrency issues?
    EXAMPLE 1
    
    var UiState by mutableStateOf(MyCompositeDataClass(value1 = null, value2 = null))
       private set
    
    init  {
        viewModelScope.launch {
            getValue1Flow().collect { UiState = UiState.copy(value1 = it) }
        }
    
        viewModelScope.launch {
            getValue2Flow().collect { UiState = UiState.copy(value2 = it) }
        }
    }
    EXAMPLE 2
    
    private var state1 by mutableStateOf<String?>(null)
    private var state2 by mutableStateOf<String?>(null)
    
    val UiState by derivedStateOf {
        UiState(value1 = state1, value2 = state2)
    }
    
    init  {
        viewModelScope.launch {
            getValue1Flow().collect { state1 = it }
        }
    
        viewModelScope.launch {
            getValue2Flow().collect { state2 = it }
        }
    }
    a
    • 2
    • 5
  • k

    Kshitij Patil

    12/24/2020, 5:08 PM
    I sometimes get warning of putting
    modifier
    as first optional argument. May I know why? I've some Custom Composables like
    HeaderText
    which used to have first parameter the text itself so I didn't need to write parameter names explicitly, but putting modifier as first parameter makes me lose this power.
    a
    • 2
    • 3
  • r

    rsktash

    12/24/2020, 6:35 PM
    Hey, anybody encountered an issue with the keyboard. It’s happening rarely. Textfield is not activating keyboard automatically when focused. Navigated to another screen and tapped to any other text field. No change. Then I restarted app
    k
    • 2
    • 1
  • b

    birdsofparadise

    12/24/2020, 6:43 PM
    Hi I've been doing a deep dive into Compose these last few days. Am I correct in my understanding that
    eventually
    Compose will replace Fragments? Looking at the Compose navigation feature it leads me to believe that.
    r
    a
    k
    • 4
    • 11
  • b

    birdsofparadise

    12/24/2020, 11:47 PM
    class MyActivity: AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            setContent {
                val navController = rememberNavController()
                NavHost(navController, startDestination = "") {
                    composable("") { TestCompose() }
                    composable("test") { TestCompose() }
                }
            }
        }
    }
    
    @Composable
    fun TestCompose(vm: TestViewModel = viewModel()) {
    
    }
    Reading about the API viewModel it seems like using it in the manor I am, it's lifecycle gets attached to
    MyActivity
    and thus if I navigate multiple
    TestCompose
    views it will leak my ViewModel
    z
    a
    i
    • 4
    • 8
  • b

    Brady Aiello

    12/25/2020, 1:20 AM
    Since Composables will eventually replace Fragments, I was wondering if we'll be able to scope ViewModels to Composables, or Composable destinations within Compose Navigation? Keeping lots of ViewModels all scoped to a single Activity, or keeping one god-ViewModel would both hold data for every page in memory concurrently, and that seems like a bad idea. Am I wrong, or is there another strategy the Compose folks are considering?
    a
    s
    i
    • 4
    • 12
  • s

    Shakil Karim

    12/25/2020, 11:00 AM
    Do we have short syntx for remember in Compose?
    var imageBitmap by remember { mutableStateOf<ImageBitmap?>(null) }
    SwiftUI syntx read so much better @State var someValue = ""
    p
    a
    t
    • 4
    • 7
  • m

    Marko Novakovic

    12/25/2020, 11:06 AM
    Hello. Am looking into
    JetNews
    compose sample. It's still not migrated to navigation component nor does it use
    LazyColumn
    , it uses
    ScrollableColumn
    instead.
    JetSurvey
    doesn't implement navigation component too. Is there any sample that is up to date with everything, not just navigation and
    LazyColumn
    ?
    s
    • 2
    • 2
  • m

    Marko Novakovic

    12/25/2020, 11:08 AM
    How to animate composable transitions when using
    Navigation Component
    ?
    k
    i
    • 3
    • 2
  • s

    Shakil Karim

    12/25/2020, 11:22 AM
    Does using rememberSavedInstanceState always instead of remeber has any drawback? val list = rememberSavedInstanceState { mutableListOf<Int>() }
    d
    a
    +2
    • 5
    • 8
  • g

    georgiy.shur

    12/25/2020, 9:52 PM
    Hello, I'm struggling a bit with using Compose + Hilt ViewModel + Navigation component together. I took this code as an inspiration and at some point I'm calling the
    viewModel
    extension, which should use the Hilt factory underneath and create my
    ViewModel
    from it. Everything works fine, but when I'm adding the Compose
    NavHost
    to the mix, the composable inside it that calls
    viewModel
    just uses the generic factory instead the one generated by Hilt. I think it has something to do with this code from the source:
    public fun NavHost(navController: NavHostController, graph: NavGraph) {
        var context = AmbientContext.current
        val lifecycleOwner = AmbientLifecycleOwner.current
        val viewModelStore = AmbientViewModelStoreOwner.current.viewModelStore
        ...
    }
    What is the right way to make them work together? I'm still not sure that I'm getting the Ambient concept right.
    i
    • 2
    • 2
  • h

    Halil Ozercan

    12/25/2020, 10:07 PM
    I'm receiving
    java.lang.IllegalArgumentException: Invalid slot table detected
    and I'm pretty sure it has nothing to do with using incompatible versions together. My setup is complicated, which means it would be very hard for me to isolate the issue. However, involved pieces are
    AnimatedVisibility
    and a button click listener. I would like to give more information if these ring any bells.
    d
    • 2
    • 5
  • s

    Sinan Gunes

    12/26/2020, 2:13 PM
    How can I combine 2 or more LazyRow/LazyVerticalGrid calls? I am trying to create a gridlayout with sections. Without compose I used
    ConcatAdapter
    once and it was very easy.
    d
    k
    +2
    • 5
    • 19
  • f

    frankelot

    12/26/2020, 6:46 PM
    ❤️ 1
    😂 5
    :rubber_duck: 11
    • 1
    • 2
  • p

    Philip Dukhov

    12/27/2020, 3:26 AM
    Hello! I’m trying to use webrtc with compose. I’ve created the following wrapper:
    data class SurfaceViewContext(
        val eglBase: EglBase,
        val videoTrack: VideoTrack,
    )
    
    @Composable
    fun SurfaceView(
        surfaceViewContext: SurfaceViewContext,
        modifier: Modifier,
    ) {
        val context = AmbientContext.current
        val customView = remember {
            SurfaceViewRenderer(context).apply {
                init(surfaceViewContext.eglBase.eglBaseContext, null)
                setEnableHardwareScaler(true)
                setMirror(true)
            }
        }
    
        AndroidView(
            { customView },
            modifier = modifier
        ) {
            surfaceViewContext.videoTrack.addSink(it)
        }
        onDispose {
            surfaceViewContext.videoTrack.removeSink(customView)
        }
    }
    And using it like this:
    @Composable
    fun TestView(context: SurfaceViewContext?) =
            Column(
                    modifier = Modifier
                            .fillMaxWidth()
            ) {
                context?.let {
                    SurfaceView(
                            it,
                            modifier = Modifier
                                    .weight(1F)
                    )
                }
                Box(
                        modifier = Modifier
                                .size(40.dp)
                                .background(Color.Red)
                )
                Text("hello",
                        color = Color.White,
                        modifier = Modifier
                )
                Box(
                        modifier = Modifier
                                .background(Color.Red)
                                .aspectRatio(1080F/1920)
                                .align(Alignment.End)
                                .padding(10.dp)
                                .weight(1F)
                ) {
                    context?.let {
                        if (counter % 2 == 0) {
                            SurfaceView(
                                    it,
                                    modifier = Modifier
                                            .fillMaxSize()
                            )
                        }
                    }
                }
                Text(
                        "hello again",
                        color = Color.White,
                        modifier = Modifier
                                .align(Alignment.End)
                )
            }
    But there’s a bug. All views above SurfaceView, except an other SurfaceView, becomes invisible. I’ve added a counter and update the view once a second to add/remove a second SurfaceView. When it’s presented, the container containing it disappears, as well as other Box and Text. Text below is visible all the time. If I use Box instead of a Column as a main container, problem is the same. sample project: https://github.com/PhilipDukhov/ComposeWebRTCTest
    🙌 1
    r
    • 2
    • 3
  • p

    Prashant Priyadarshi

    12/27/2020, 2:56 PM
    Preview toolbar is not appearing for my compose function, is there any setting which I may be missing. PS I restarted android studio , it doesn't work As of now I am using compose alpha09 and its an existing project also consisting of non compose code for UI @Preview @Composable fun PreviewTopBar(){ SamplePreviewFunction() }
    a
    c
    +2
    • 5
    • 9
  • f

    frankelot

    12/27/2020, 4:34 PM
    This message got lost in the noise, can anyone experienced with compose can give me a hand? Not sure if this is a but I should report or something I’m doing wrong
    t
    a
    • 3
    • 65
  • t

    tylerwilson

    12/27/2020, 10:20 PM
    I am using a ScrollableColumn in an embedded ComposeView in a Fragment, but it is not scrolling all the way to the bottom as it should. I am sure it is sized properly, since I inserted the same way as the RecyclerView it replaces, and that works fine. Here is an example: the ‘time views’ are all locked to a constant height, so I would expect this to be okay. Has anybody else seen any issues with the ScrollableColumn like this?
    j
    c
    • 3
    • 12
  • n

    Nat Strangerweather

    12/27/2020, 10:22 PM
    Hello, I made a list of toggles but when I toggle them they are all moving at the same time instead of moving independently of each other. Any ideas how I can toggle them individually?
    val checkedState = remember { mutableStateOf(true) }
    
        VerticalGrid(modifier = Modifier.padding(start = 30.dp, end = 30.dp)) {
            listOf(
                "Alarms",
                "Media",
                "Touch",
                "Reminders",
                "Events",
                "Repeat Callers"
            ).forEachIndexed { index, string ->
                Column(
                    Modifier.fillMaxWidth().padding(20.dp),
                    horizontalAlignment = CenterHorizontally,
                    verticalArrangement = Arrangement.Center
                ) {
                    CustomToggle(
                        color = accentColor,
                        selected = checkedState.value,
                        onClick = {
                            checkedState.value = !checkedState.value
                            toggleAtIndex(index)
                        }
                    )
                }
            }
        }
    }
    
    fun toggleAtIndex(index: Int) {
        when (index) {
            0 -> println(0)
            1 -> println(1)
            2 -> println(2)
            3 -> println(3)
            4 -> println(4)
            5 -> println(5)
        }
    }
    t
    b
    • 3
    • 7
  • j

    John O'Reilly

    12/28/2020, 11:10 AM
    Has anyone by chance tried using
    GoogleMap.InfoWindowAdapter
    in a Compose app? I tried returning a
    ComposeView
    from
    getInfoContents()
    but getting
    java.lang.IllegalStateException: Composition view not present for measure!
    a
    • 2
    • 3
  • k

    Kshitij Patil

    12/28/2020, 12:04 PM
    I want to display list of items spanning multiple rows based on number of items, I'm tried putting
    LazyRow
    inside
    FlowRow
    but doesn't seem to work
    • 1
    • 1
  • c

    Cyril Find

    12/28/2020, 1:33 PM
    About this previous message…I think I found a pattern in which if I first tap on a parent of my text field then the bug occurs (more specifically a direct
    Row
    parent in my case)
    • 1
    • 1
Powered by Linen
Title
c

Cyril Find

12/28/2020, 1:33 PM
About this previous message…I think I found a pattern in which if I first tap on a parent of my text field then the bug occurs (more specifically a direct
Row
parent in my case)
Apparently it’s a know issue, but maybe not this precision…anyone knows if I can add this info somewhere ? (maybe a bug ticket ?)
View count: 8