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

    Kshitij Patil

    01/06/2021, 8:14 AM
    How to make
    TextField
    pre-focused when a Composable is loaded for the first time?
    v
    • 2
    • 1
  • g

    gpaligot

    01/06/2021, 8:16 AM
    Hi all, I have an architecture issue with a composable and a Kotlin Flow from a ViewModel. In my ViewModel, I have a flow which observes any changes in a room database to emit a data with a delay. Here a small example of my ViewModel:
    fun myFunc(input: Input) = flow {
      myDao.get().collect {
        it.forEach {
          emit(it.data)
          delay(it.delayTime)
        }
      }
    }
    In my composable, I have something like this:
    @Composable
    fun MyComposable(input: Input) {
      val myViewModel: MyViewModel = viewModel()
      val data = myViewModel.myFunc(input).collectAsState()
      AnotherComposable(data = data.value)
    }
    The issue is: When I emit new data from my flow, compose collect the data and recompose itself because the state has been updated but due to this recomposition, it recall
    myFunc
    function, cancel the previous execution of the flow, collect data from database, emit values and loop a long time like this. How can I change my code to avoid this loop? There is any good practice for my usecase? Thanks in advance!
    k
    • 2
    • 3
  • t

    TheMrCodes

    01/06/2021, 11:32 AM
    Upfront: Sry if this it the 101. time asking that question but I didn't find one for my use case. How can i fit the height of the Box around the "X"-Text to the height of its Parent (the Row with the gray background) The Problem is that fillHeight would fill the whole screen not just the Parent Code im Thread
    ➕ 1
    l
    j
    d
    • 4
    • 8
  • v

    Vitor Prado

    01/06/2021, 2:01 PM
    does anyone have examples of architecture using compose? My entire app is using databinding + presenters (BaseObservable).. but now I change it to use viewmodels + livedata (compose views only) .. my old presenters describe all formatted values in variables.. and bind it to views.. now my composables use the data object to populate the view.. should I build a presenter/helper to format values for composables? how can I unit test it? Is it strange to use viewmodels for screen state and presenters for data formatting?
    t
    s
    • 3
    • 16
  • m

    Mehdi Haghgoo

    01/06/2021, 5:07 PM
    Does anyone have problem running the Jetpack Sample on Android Studio Arctic Fox 2020.3.1 Canary 3? Error is "The project is using an incompatible version (7.0.0-alpha02) of the Android Gradle plugin." and it cannot be resolved automatically by Android Studio.
    z
    • 2
    • 2
  • j

    Jakub Ledwon

    01/06/2021, 6:45 PM
    Hello everyone, I'm trying a compose in a simple app, and I wonder what is a proper way to create ViewModels for composable screens. Atm there are two screens in an app, both of them in one Activity. Navigation is implemented with NavHost. Each screen should have its ViewModel. Should I create both ViewModels in my single Activity or may be create many Activities? Each Activity for one composable screen? I'm using the first approach now, but it can be problematic if for example I would need to pass a runtime arguments to second ViewModel and those arguments should come from first VM. The 'many-activities' approach doens't seem to be correct either, so what is a correct pattern for that?
    i
    m
    • 3
    • 8
  • l

    Logan Knight

    01/06/2021, 7:36 PM
    I asked this in #compose-desktop yesterday but didn't get an answer. I think because it wasn't specifically a compose desktop question, but rather a compose question in general and better asked here. Detail are in the thread.
    d
    a
    • 3
    • 12
  • k

    Kshitij Patil

    01/06/2021, 7:53 PM
    Looks like there's new AS Arctic Fox canary release (Canary 4). Has anyone used it and could share if everything is working fine?
    b
    • 2
    • 3
  • p

    Piotr

    01/06/2021, 8:32 PM
    Is there some easy way to achieve something like sticky header behavior? I have a scrollable tab row inside lazy column and the screen needs to stop scrolling when that tab row reaches the top of the screen but couldn’t find anything, that would resemble it
    k
    • 2
    • 1
  • n

    Nurseyit Tursunkulov

    01/07/2021, 2:28 AM
    Can someone help me with this question: https://stackoverflow.com/questions/65605272/java-util-concurrentmodificationexception-compose-jetpack
    👍 1
    g
    • 2
    • 1
  • n

    Nurseyit Tursunkulov

    01/07/2021, 10:03 AM
    how to change the status bar color? https://stackoverflow.com/questions/65610216/how-to-change-statusbar-color-in-jetpack-compose
    p
    s
    • 3
    • 5
  • s

    Se7eN

    01/07/2021, 1:17 PM
    @Composable
    fun Main() {
        val state = remember { PaletteState(...) }
        Scaffold(
            topBar = { TopBar(onSave = { viewModel.save(state.toPalette()) } }
        ) {
            ColorWheel(state)
        }
    }
    
    @Composable
    fun ColorWheel(state: PaletteState) {
        val colorWheel = rememeber { ColorWheel(...) }
        state.colors = colorWheel.getColors()
    
        Content(colorWheel)
    }
    I have a
    state
    that needs to be updated by a child composable. Is this the right way to do it?
    s
    l
    j
    • 4
    • 17
  • m

    Mehdi Haghgoo

    01/07/2021, 1:45 PM
    Is there a technical reason Compose is not supported on stable A.S. versions?
    s
    j
    a
    • 4
    • 9
  • a

    alorma

    01/07/2021, 2:26 PM
    Hi. How can add bold to a part of a text? (the
    @nosferatu95
    part
    v
    s
    • 3
    • 3
  • h

    Halil Ozercan

    01/07/2021, 2:57 PM
    I'm experiencing an issue while using navigation-compose. I have a very simple setup.
    HomePage
    composable receives a
    HomeViewModel
    and a
    HomeState
    object (caller passes
    state.value
    ) as its arguments.
    HomePage
    also hosts a NavHost which includes 2 different routes(
    SettingsPage
    ,
    ProfilePage
    ) When I pass a field from HomeState like
    homeState.username
    to one of the composables defined in NavHost, it does not work. State changes do not reflect on children pages of
    HomePage
    . However, carrying
    homeViewModel
    and
    homeState
    directly into
    HomePage
    composable, fixes this issue.
    a
    i
    • 3
    • 7
  • a

    alorma

    01/07/2021, 3:23 PM
    How To change ripple color of a Card?
    f
    • 2
    • 4
  • t

    tylerwilson

    01/07/2021, 4:44 PM
    Curious about drag and drop story in Compose, if any.
    f
    j
    • 3
    • 4
  • b

    buszi0809

    01/07/2021, 5:43 PM
    How to force text field to lose focus? I can't exit edit state after ime action etc
    ➕ 4
    r
    • 2
    • 1
  • m

    Marcin Środa

    01/07/2021, 6:04 PM
    Is it possible to use layer-list drawable with Image?
    vectorResource
    is showing empty image
    • 1
    • 1
  • s

    Shakil Karim

    01/07/2021, 7:01 PM
    Is there any existing API through which we can achieve a flow-like layout, Where items shift to the next line if there is not enough space available?
    d
    v
    +3
    • 6
    • 9
  • t

    Thomas

    01/07/2021, 9:05 PM
    Is there a way to show a Snackbar with a custom Text but using the default positioning of the Scaffold SnackbarHost? When using
    scaffoldState.snackbarHostState.showSnackbar
    you can only set a String, but I would like to set a Text so I can style the text using annotated string builder. When just including a Snackbar without using Scaffold it appears at the top of the screen, which is not what I want (I would like it at the bottom how it is supposed to be). Looks like the Scaffold/SnackbarHost is setting the correct positions.
    m
    f
    • 3
    • 15
  • c

    Chethan

    01/08/2021, 6:01 AM
    how to make single line true in OutlinedTextField?
    s
    j
    +3
    • 6
    • 14
  • s

    Se7eN

    01/08/2021, 11:04 AM
    I'm using
    SnapshotStateList<SnapshotStateList<MyObject>>
    as a state but when I change it, the composables aren't getting recomposed. However, if I wrap it with a mutable state
    MutableState<SnapshotStateList<SnapshotStateList<MyObject>>
    it's working fine. Is this intended?
    data class MyStateHolder(
        val name: MutableState<String>,
        val list: SnapshotStateList<SnapshotStateList<MyObject>>
    )
    
    var state = remember { MyStateHolder(...) }
    ...
    MyComposable(onSomeEvent = { newList -> state = state.copy(list = newList) })
    SomeOtherComposable(state.list) // not getting recomposed when I change state with a new list
    I'm not sure but I think it works fine if I just change an item of the list as opposed to copying the whole state for a new list. This works fine:
    data class MyStateHolder(
        val name: MutableState<String>,
        val list: MutableState<SnapshotStateList<SnapshotStateList<MyObject>>>
    )
    
    val state = remember { MyStateHolder(...) }
    ...
    MyComposable(onSomeEvent = { newList -> state.list = newList })
    SomeOtherComposable(state.list)
    d
    • 2
    • 5
  • a

    aiidziis

    01/08/2021, 2:33 PM
    Hey! Has anyone else encountered issues with AndroidView and WebView? WebView is totally unresponsive.
    AndroidView(
        viewBlock = ::WebView,
        modifier = Modifier.fillMaxSize()
    ) { webView ->
        with(webView) {
            settings.javaScriptEnabled = true
            webViewClient = WebViewClient()
            loadUrl("<https://google.com>")
        }
    }
    Screen Recording 2021-01-08 at 16.23.43.mov
    j
    j
    +2
    • 5
    • 13
  • a

    alorma

    01/08/2021, 4:12 PM
    Hi. Using navigation:
    NavHost(
                        navController = navController,
                        startDestination = "splash"
                    ) {
                        composable(Navigation.ROUTE_SPLASH) { InitScreen(navController) }
                        composable(Navigation.ROUTE_LOGIN) { LoginScreen(navController) }
                        composable(Navigation.ROUTE_USER) { UserScreen(navController) }
                        composable(Navigation.ROUTE_GO_WALK) { GoWalkScreen(navController) }
                    }
    From splash I navigate to login or user..., but when I hit the back button of the devices it goes again to splash. How can avoid that, and if I'm at login, or User close the app when back button is hit
    i
    a
    • 3
    • 8
  • b

    buszi0809

    01/08/2021, 4:24 PM
    Is there a way to place items in column starting from the bottom? In my case I have a bottom bar and content that has to fill all the rest of the screen, but when I put them into column starting content the this content fullfil a whole screen and bottom bar is not visible, how to layout it properly? Use ConstraintLayout?
    a
    • 2
    • 2
  • o

    orangy

    01/08/2021, 5:11 PM
    Is there any tutorial/manual/samples/docs on lazy components, like how
    LazyVerticalGrid
    works internally. I want to implement
    LazyTileMap
    (a big table of cells into which one looks through a small viewport, I need it for a game-like experience) which would only compose tiles that are visible and will allow scrolling and (optionally) zooming. But I’m currently lost in all these layout stuff, subcomposition, measurements, etc. What is the best guide into this? I’ve read Custom layouts section, but it seems it’s a tiny fraction of the underlying machinery.
    j
    • 2
    • 3
  • o

    orangy

    01/08/2021, 6:20 PM
    Is there a reason
    Layout
    composable function has
    content
    parameter first and not last, so it would allow for container-like invocation?
    z
    j
    a
    • 4
    • 6
  • c

    Cyril Find

    01/08/2021, 6:47 PM
    So about the Keyboard not opening on tapping text fields, seems like I have reproductible scenarii: • it never happens if I tap exactly inside the text field • it always happens if I tap on the bound between the text field and the nearest component I think that’s why my workaround kinda work: it makes the safely tappable zone bigger It also seems like only the first time I tap a textfield matters: afterwards, it works or doesn’t work until I restart the app
    s
    a
    • 3
    • 4
  • r

    Rafs

    01/08/2021, 9:25 PM
    What is the newest way of positioning a composable at an exact pixel position on the screen. It seems
    Modifier
        .offset(x = { offset.x }, y = { offset.y })
    has been removed from
    alpha09
    l
    a
    • 3
    • 6
Powered by Linen
Title
r

Rafs

01/08/2021, 9:25 PM
What is the newest way of positioning a composable at an exact pixel position on the screen. It seems
Modifier
    .offset(x = { offset.x }, y = { offset.y })
has been removed from
alpha09
l

Luke

01/08/2021, 9:51 PM
I just ran into this myself. The deprecation message says:
Please use offset with lambda parameters instead
but it's not in the library
r

Rafs

01/08/2021, 9:58 PM
@Adam Powell What do you think about this?
a

Adam Powell

01/08/2021, 10:02 PM
Modifier.offset { IntOffset(...) }
looks like the
replaceWith
on the old method was stale
r

Rafs

01/08/2021, 10:39 PM
var boxPosition by remember { mutableStateOf(Offset.Zero) }

Box(
    modifier = Modifier
        .fillMaxSize()
) {
    Box(
        modifier = Modifier
            .dragGestureFilter(dragObserver = object : DragObserver {
                override fun onDrag(dragDistance: Offset): Offset {
                    boxPosition += dragDistance

                    return dragDistance
                }
            })
            .offset {
                IntOffset(boxPosition.x.toInt(), boxPosition.y.toInt())
            }
            .background(color = Color.Black)
            .preferredSize(100.dp)
    )
}
Thx. In this code snippet, the drag observer rarely get's called. It was working fine on alpha08 @Adam Powell
a

Adam Powell

01/08/2021, 10:42 PM
Please don't @-mention me personally on every question in here, there are others who can answer them too and I don't need that many notifications 🙂
😂 5
View count: 2