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

    Michael Bichlmeier

    07/13/2022, 7:22 AM
    Hey guys. I’m having trouble with my UX when I try to display web content (AndroidView + WebView) in a List of other items (e.g. ads). Whenever the user scrolls “normal” through the content, the AndroidView is getting recomposed and the height is adjusted some milliseconds after it is already in the visible area. This leads to confusing list jumps. Has anybody of you some advices how I can improve the user experience?
    1 reply · 1 participant
  • t

    Tgo1014

    07/13/2022, 7:43 AM
    I've a ImageVector that I would like to paint dynamically changing colors by the offset, but when the offset changes it's not recomposing it, I imagine it's because I'm using
    rememberVectorPainter
    but without this I can't use the
    Image
    composable. Is there a way to achieve this?
    t
    2 replies · 2 participants
  • c

    Can Korkmaz

    07/13/2022, 7:51 AM
    I can't use some view layout to nest compose view inside right? For example LinearLayout or MaterialSmoothRefreshLayout with AndroidView to nest LazyColumn inside isn't applicable, thus I must use recycler view?
    z
    1 reply · 2 participants
  • v

    Vivek Modi

    07/13/2022, 9:16 AM
    Hey guys, I am new in compose. My supervisor told me to work on compose UI library. So can anyone suggest me how to make a compose UI library which can share in 2 different apps. So any guidance would be great. Thanks.
    c
    3 replies · 2 participants
  • c

    Can Korkmaz

    07/13/2022, 11:53 AM
    Do the lifecycle events of the composable always follow the lifecycle of the host fragment (converting Android view appliaction to compose view)? Is LocalLifeCycleOwner.current.lifecycle.Event always the same as fragment lifecycle event? If so, assuming I have code to be executed inside fragment lifecycle callbacks, say inside On_create calling viewmodel.init(), can I call it directly inside LaunchedEffect(true) or with lifeCycleObserver, when the lifecycle.Event is ON_CREATE ON_RESUME. Sorry for the least chaotic paraghraph ever.
    1 reply · 1 participant
  • o

    oday

    07/13/2022, 11:54 AM
    I would like to have a function that accepts an enum of Colors, I want the enum to look like this
    enum class StylisedIconColor(val color: Color) {
        BRAND(MaterialTheme.colors.Brand), INFO, SUCCESS, WARNING, FAILURE, INACTIVE, EARTH, TITAN, SUN, MARS
    }
    but the issue is that you cannot invoke that colors call without being in the context of Composabl;e
    4 replies · 1 participant
  • a

    Alex

    07/13/2022, 12:26 PM
    I am creating a
    MutableState
    in this way:
    var result by mutableStateOf<R?>(value = null, policy = neverEqualPolicy())
    Now I am setting an
    object
    via
    result = TheObject
    I am listening to that via
    LaunchedEffect(Unit) {
      snapshotFlow { result }.collectLatest {
        (logging here)
      }
    }
    But I am only receiving a log when the first object is set, all subsequent value changes with
    TheObject
    on
    result
    are not logged. Shouldn’t
    neverEqualPolicy()
    ensure that every value change is emitted? What am I missing here?
    s
    z
    13 replies · 3 participants
  • s

    Sebastian Kürten

    07/13/2022, 3:38 PM
    I have some `ImageBitmap`s that I'm rendering into a UI using
    Image
    . That works nicely, images appear in their natural size. However on higher density devices, images appear smaller. Is there any easy way to use the
    LocalDensity
    to render an image the same natural size independent of screen density? I've tried applying
    Modifier.scale(LocalDensity.current.density)
    and while the image seems to be rendered bigger on higher density devices, the size of the widget doesn't seem to increase, i.e. only part of the image is visible. I see that
    Image
    is using an
    ImagePainter
    under the hood, but I don't see an easy way to supply a target size for it. Any suggestions?
    k
    6 replies · 2 participants
  • b

    Berkeli Alashov

    07/13/2022, 7:21 PM
    I'm trying to understand the difference in LaunchedEffect and SideEffect in example below.
    @Composable
    fun isCompactWindow(windowSizeClass: WindowSizeClass = LocalWindowSizeClass.current) = windowSizeClass.isCompactWindow()
    
    class Fragment : ComposeFragment { // calls Route in onCreateView by returning ComposeView
    
        @Composable
        override fun Route() {
            val isCompactWindow = isCompactWindow()
            val someOtherState by remember { mutableStateOf(false) }
    
            LaunchedEffect(isCompactWindow){
                mainActivity.showFoo(isCompactWindow)
            }
            // or
            SideEffect {
                mainActivity.showFoo(isCompactWindow)
            }
        }
    }
    I think I should use the LaunchedEffect in this case. Since it makes sure that the code won't run again when
    someOtherState
    changes, right? If there was only
    isCompactWindow
    , then I could use SideEffect safely too?
    s
    1 reply · 2 participants
  • c

    Colton Idle

    07/14/2022, 5:11 AM
    Is there any way to programatically retrieve the font family applied to text? I'm building a text debug menu in my app and it seems like for each text style I can programatically access all attributes about the style, (weight, size, line height) but not the name of the Font (i.e. Roboto or my other custom font). Ideas?
    c
    z
    +1
    21 replies · 4 participants
  • n

    nlindberg

    07/14/2022, 9:08 AM
    I want to drag a specific element inside a canvas if the drag starts from touching in the region of that element. If not then I would like to scroll the canvas parents box horizontal scroll. Im currently trying to figure out how to correctly pass up the drag from the pointerInput to the horizontalScroll. The below is what I currently have, but it doesn’t take into account flings. Any ideas?
    Box(
        Modifier
            .fillMaxHeight()
            .horizontalScroll(scrollState)
    ) {
        CanvasComposable(data = chartData, settings = chartSettings, onHorizontalDrag = { dragX ->
            scrollState.dispatchRawDelta(-dragX)
        })
    Canvas(
        modifier.then(
            Modifier
                .fillMaxHeight()
                .clipToBounds()
                .pointerInput(Unit) {
                    // If drag is starting on a specific rectangle inside the canvas drag that otherwise scroll the parent horizontal 
                    // composable according to the x dragAMount and (Fling?)
                    detectDragGestures(
                        onDragStart = {},
                        onDragEnd = {},
                        onDrag = {change, dragAmount ->
                            change.consume()
                            onHorizontalDrag(dragAmount.x)
                            //dragOffsetStart += dragAmount.x
                        }
                    )
                }
        )
    z
    4 replies · 2 participants
  • j

    Jonas

    07/14/2022, 2:37 PM
    I allow myself to repost at another time. Would be really glad for any response.
  • n

    nuhkoca

    07/14/2022, 4:43 PM
    Hello, I have a list of instruments in which each of them subscribes to a websocket so they get updated frequently. How would you observe such a frequently updating set of items with Compose? I use
    subscribeAsState
    to collect the list but whenever there is an update in any element in the list, all item gets recomposed over and over so I am having flickers in the UI. I also pass a key per element down to
    LazyList
    val instruments by instrumentList.subscribeAsState(initial = emptyList())
    GIF in the thread
    z
    4 replies · 2 participants
  • j

    Jan

    07/14/2022, 6:32 PM
    Hey I have a compose multiplatform project with android and desktop. Is it normal that I can access AlertDialog and Dialog in android and desktop specific code but not in the common code?
    j
    m
    10 replies · 3 participants
  • a

    agrosner

    07/14/2022, 7:34 PM
    hey. I have a compose view inside of a
    FrameLayout
    inside of a
    CoordinatorLayout
    . The coordinator layout has also a bottom navigation on the bottom of the screen (tabs) there is an issue where the last row of items inside of a
    LazyVerticalGrid
    get cut off on the bottom. 1. On api 33 (or as I understand > API 28), it intermittently happens and only seems to happen very rarely. Then it "fixes itself" 2. On api 28 I can see it happening all of the time. I add bottom padding to the view below the last set of items to mitigate it. But when I use the
    nestedScroll
    interop connection, it still happens. anyone run into such an issue as this?
  • j

    Joseph Hawkes-Cates

    07/14/2022, 8:08 PM
    I’d like to create a text field that opens up a DatePicker when it’s selected. Would it be best to use the TextField composable and then customize the InteractionSource to show my date picker instead of the keyboard or would it be better to just create my own “field” composable which has it’s own onClick impl?
    d
    c
    3 replies · 3 participants
  • m

    Manojna Chintapalli

    07/14/2022, 9:40 PM
    Hi! Can somebody help me with using
    android:forceDarkAllowed = true
    I didn't find any useful resources on how to use this with Compose. Thanks in advance.
    c
    l
    17 replies · 3 participants
  • j

    Jasmin Fajkic

    07/14/2022, 10:01 PM
    I am trying to replicate what Instagram is doing with Feed and adding comments. So basically it is possible to add comment directly from feed on post. I am really interested to know how would you guys implement it? Show some input on top of keyboard and then scroll item in lazy column to focus post which user actually want to comment on. Also on backdrop press sheet should close. Probably it is not input on every post it is button that open keyboard and have input on top of if. I really do not know what would be optimal way to achieve it so any advice is good advice 😄 . Here is video explaining what I am trying to achieve. I do not need any coding or something just general idea how to achieve. thx https://streamable.com/nm8rlb
  • x

    xxfast

    07/15/2022, 12:00 AM
    Hi all. I have a language toggle in the settings of my app, and I want to change the app language when the users change the language here. I'm setting the language using
    LocalConfiguration.setLocale(locale)
    - this seems to have worked, but it doesn't seem to automatically trigger recomposition by itself. Is there a way to trigger recomposition manually?
  • t

    Tim Malseed

    07/15/2022, 12:15 AM
    I’ve seen this asked & answered in the #compose channel plenty of times (myself included), but I haven’t quite got my head around a good implementation. Let’s say I’m using route-based navigation, and I want to pass some complex data between routes. The suggestion is to stash that object somewhere, and then pass an identifier via navigation args, then use that identifier to retrieve the object. I’m fine with this when my data has an identifier, and exists in a repository somewhere. But, let’s say I have two Composable screens, StoreList and StoreDetails. And, let’s say each screen has its own ViewModel,
    StoreListViewModel
    and
    StoreDetailsViewModel
    StoreList lets me retrieve a list of
    Store(val name: String, val lat: Double, val long: Double)
    And StoreDetails renders some UI for a particular
    Store
    . There’s no real ‘identifier’ for a Store, though I could use the hashcode or something. And there’s currently no cache for Stores. Where do I stash this Store object? I don’t particularly want to share the
    StoreList's
    ViewModel
    with the
    StoreDetails
    screen, as it contains properties and functions that don’t relate to StoreDetails. Do I create a 3rd ViewModel for sharing between the two screens, and set the Store on that VM?
    c
    i
    17 replies · 3 participants
  • z

    Zoltan Demant

    07/15/2022, 5:13 AM
    Are multipreview annotations broken in Canary 8 of Android Studio? I keep getting
    Only composable methods can be annotated with Preview
    . Usage in 🧵
    c
    s
    +1
    6 replies · 4 participants
  • j

    Jasmin Fajkic

    07/15/2022, 9:26 AM
    I have viewmodel which I want to use in Parent composable and then few levels down in child composable. What is best way in this case it sounds very wrong that i create dependencies and that I send viremodel instance all way down to the view that actually need on click to update viewmodel. Parent also based on viewmodel value change visibility of component but on button press child component update it. Any recommendation what is best practice?
    r
    s
    5 replies · 3 participants
  • a

    Angus L

    07/15/2022, 9:46 AM
    Hello, I noticed that
    LaunchedEffect(someMutableState.value)
    will cause a custom
    Layout()
    in the same
    @Composable
    function to remeasure every time the value of the key changes. Which was not what I was expecting. This got me wondering if there is something wrong with the way
    LaunchedEffect
    is used in this case and what the ideal approach to get around this remeasure would be. Wrapping it into a separate
    @Composable
    or
    SubcomposeLayout
    would work, but that feels even worse to me.
    MinimalRemeasureExample_kt.kt
    s
    n
    +1
    21 replies · 4 participants
  • a

    Akram Bensalem

    07/15/2022, 6:43 PM
    How to make one item in LazyVerticalGrid fill all the parent width ? Scenario: LazyVerticalGrid with diffrent Lists every list should have it own header How I can implement the header to take all the width ?
    o
    c
    4 replies · 3 participants
  • n

    Nat Strangerweather

    07/15/2022, 8:07 PM
    In my application I am using
    LocalContext.Current
    for some process where I take a screenshot and share it. I have a memory leak and I think this whole process is the cause. Is there a way in which I can dispose of the context when I navigate back to the Homescreen? I thought I could use
    DisposableEffect
    but I can't seem to make it happen (I can't work out how to use it here). I'll put my code in the thread. Thanks.
    z
    3 replies · 2 participants
  • e

    elihart

    07/15/2022, 9:31 PM
    We’re using compose desktop within an Intellij IDE Plugin. It was working great up until recently and it seems like with Intelij 2022.1 (Android Studio Electric Eel build specifically) it just stopped working. Initial drawing works, but then recomposition just doesn’t seem to happen. Click and key press callbacks happen, but updating State doesn’t trigger recomposition, and things like mouse over highlights over built in components don’t show. It’s really bizarre, and I don’t see any errors in logs to point out what is going on. Debugging doesn’t give me any hints either. Anyone in a similar position?
    1 reply · 1 participant
  • e

    Emmanuel

    07/16/2022, 3:31 AM
    Any amazing devs working a full featured dataTable compose impl? filter,search,sort
    k
    m
    2 replies · 3 participants
  • d

    darkmoon_uk

    07/16/2022, 2:24 PM
    Did something happen to Android support in recent
    1.2.0-alpha01
    Compose Multiplatform Dev builds? iOS source-set is resolving dependencies as expected,
    androidMain
    is not(?)
  • j

    Jasmin Fajkic

    07/16/2022, 3:20 PM
    Is it possible with Jetpack compose when click on element to get it position relative to screen? I am coming from react native and there it is possible but can not find anything similar with Jetpack compose. I need when click on element to get it offset from bottom. Thx in advance 🙂
    z
    1 reply · 2 participants
  • v

    Vivek Modi

    07/16/2022, 7:35 PM
    Hey guys, I started jetpack compose I am getting confused in width and height. In xml we use WRAP_CONTENT/MATCH_PARENT so what we use in compose?
    a
    4 replies · 2 participants
Powered by Linen
Title
v

Vivek Modi

07/16/2022, 7:35 PM
Hey guys, I started jetpack compose I am getting confused in width and height. In xml we use WRAP_CONTENT/MATCH_PARENT so what we use in compose?
a

andrew

07/16/2022, 7:37 PM
- Modifier.size(w, h)
- Modifier.size(size)

- Modifier.width(w).height(h)

- Modifier.fillMaxWidth(weight = 1F)
- Modifier.fillMaxHeight(weight = 1F)
- Modifier.fillMaxSize(weight = 1F)
For some of the basics
The canonical layouts:
Row
,
Column
,
Box
should all shrink to fit
v

Vivek Modi

07/16/2022, 7:41 PM
great thanks a million
a

andrew

07/16/2022, 7:42 PM
The docs are very descriptive as to what each does: https://developer.android.com/jetpack/compose/modifiers-list#Size
👍 1
View count: 5