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

    nuhkoca

    09/15/2022, 11:22 PM
    Hello, Is it possible to have 2 sticky headers in a row in
    LazyList
    ?
    k
    y
    • 3
    • 7
  • a

    Aaron Waller

    09/16/2022, 12:31 AM
    Hello, is there a way to capture Composables and save them as png but with keeping the same pixel depth every time? I have a small image editor and I want to capture the composable in 512x512 everytime. Problem is whenever I use a 480x800 device it goes below 512x512.
    a
    z
    • 3
    • 4
  • a

    Asad Mukhtar

    09/16/2022, 7:19 AM
    Hi, Why it first shows image & text then show shimmer on top of that ?
    c
    • 2
    • 2
  • e

    ephemient

    09/16/2022, 9:00 AM
    use
    TextFieldValue
    instead of
    String
    which cannot hold composition state
    a
    t
    s
    • 4
    • 6
  • m

    Matti MK

    09/16/2022, 9:07 AM
    I seem to remember there being a tool that generated a “listing” of Composables defined in a project. I guess this was used as a design system representation or similar. Pretty vague description, as I’m not sure sure of the terminology. Anyone happen to know such a third party plugin/tool?
    c
    • 2
    • 2
  • k

    KotlinLeaner

    09/16/2022, 11:46 AM
    Hello, I am looking permission sample. I found two sample projects. I am little bit confused which one is correct and updated one to use. I have one inside permissions and another one is inside the samples. Anyone please help me which one we need to use and latest one. Thanks
    a
    • 2
    • 6
  • s

    Simonas Brazauskas

    09/16/2022, 1:25 PM
    Hello, it is possible to specify weight for an item in a column, but with minimum height? So item expands to fill empty space, but does not shrink below minimum height? Something like
    LottieAnimation(
        modifier = Modifier
            .fillMaxWidth()
            .weight(1f)
            .heightIn(min = 200.dp),
        composition = composition,
        progress = { progress },
        contentScale = ContentScale.Crop
    )
  • s

    Slackbot

    09/16/2022, 2:26 PM
    This message was deleted.
  • r

    reactormonk

    09/16/2022, 3:25 PM
    I'm somehow apt at producing compiler errors O.o https://gist.github.com/reactormonk/dd5904bdbeec45541bacbee4366ce05c
  • r

    reactormonk

    09/16/2022, 3:28 PM
    Ah, forgot the build feature 😄
  • a

    Aaron Waller

    09/16/2022, 3:40 PM
    Jetpack Compose isn’t updating my user state since I implemented nested navigation. After the user logs out I set my UserStateModel to null.
    private val _userStateFlow: MutableStateFlow<UserStateModel?> = MutableStateFlow(UserStateModel())
    val userStateFlow: StateFlow<UserStateModel?> = _userStateFlow
    in my MainViewModel I’m collecting this state and i’m passing the user state down the hierarchy. Before implementing nested navigation everything got updated accordingly but since I implemented nested navigation the change get’s lost somewhere inside my navigationGraph. Anyone else faced this problem?
    r
    • 2
    • 4
  • t

    Trevor Hackman

    09/16/2022, 4:19 PM
    Hi, I have a LazyVerticalGrid of images, and I want to know the size of the cells so I know what size images to fetch. How can I get the size of an individual cell? Because the size is dynamically determined by the number of columns, spacing, and contentPadding, I don't know the size ahead of time.
    c
    z
    • 3
    • 6
  • j

    Jorge Domínguez

    09/16/2022, 9:37 PM
    Is there any advantage in using remember for simply instatiating a class?
    val model = remember {
        Model(
            name = "John",
            lastName = "Doe",
            nationality = "Colombian",
            type = Type.DEVELOPER
        )
    }
    probably thinking about it too much but I'm not sure if re-instantiating the class on every recomposition has a significant cost
    c
    t
    • 3
    • 8
  • e

    Ewan

    09/17/2022, 10:44 AM
    Hi all, I'm having trouble drawing edge-to-edge when the status bar is hidden (works fine when status bar showing) - I can only draw beneath the blank area where the status bar would be when it's hidden. I'm using compose 1.3.0-beta02 and accompanist-systemuicontroller:0.26.3-beta:
    WindowCompat.setDecorFitsSystemWindows(window, false)
    setContent {
      val systemUiController: SystemUiController = rememberSystemUiController()
      systemUiController.isStatusBarVisible = false
      // draw here
    The layout inspector shows a ViewStub of height 42dp:
    DecorView
      LinearLayout
        action_mode_bar_stub - ViewStub   height 42dp
        content - FrameLayout
          ComposeView
        navigationBarBackground - View
        statusBarBackground - View
    Any ideas ? UPDATE: I've found it draws correctly on an Android 12 & 13 emulators but not on Android 12 on a Samsung S10.
    s
    a
    • 3
    • 5
  • s

    Siyamed

    09/17/2022, 5:31 PM
    Not sure if portersuff would work, it might
    m
    o
    +2
    • 5
    • 6
  • m

    mgrazianodecastro

    09/18/2022, 2:05 AM
    Any good book / material for camera applications in Android?
    a
    • 2
    • 7
  • s

    Shafayat Bin Mamun

    09/18/2022, 2:37 AM
    What is the best way to pass an object between 2 compose screens? 1. Save the object to room db and get it in the viewmodel with savestatehandle. 2. Share a single viewmodel between 2 screens pass the object in the viewmodel. 3. Convert the object to JSON and parse it on the next screen via custom NavType Well?
    m
    i
    • 3
    • 4
  • m

    Mohan manu

    09/19/2022, 8:03 AM
    how to open open bottom sheet on top of another bottom sheet ? existing implementation removes the below bottom sheet from stack
    z
    a
    • 3
    • 3
  • a

    Alex

    09/19/2022, 2:51 PM
    how do I scale a path in jetpack compose? The matrix transformations from the old android drawing api seems no longer to exist (path.transform)
  • s

    Slackbot

    09/19/2022, 2:52 PM
    This message was deleted.
  • c

    chatterInDaSkull

    09/19/2022, 6:13 PM
    Why is there such limited supported for PlatformHapticFeedback while the constants exposed through android are many? Is it because android treats
    LongPress
    as just a click?
    s
    • 2
    • 2
  • t

    Travis Griggs

    09/19/2022, 8:46 PM
    I'm trying to inject a simple Text Banner into an existing Fragment/layout. It embeds fine (per https://developer.android.com/jetpack/compose/interop/interop-apis#compose-in-fragments). But I need to hoist some state (I think) into the fragment. I have a value at the Fragment level in a LiveData. But it's unclear to me how to change my ComposeFunction to become aware of that value and recompose when it changes. I'm successfully able to pass the LiveData as an arg to the @Composable function and compose the original view. But updates to the LiveData don't cause it to recompose. I looked for
    observeAsState
    per the docs, but it doesn't seem to find that. Nor is it clear where to invoke that at...
    i
    a
    z
    • 4
    • 6
  • s

    Stylianos Gakis

    09/19/2022, 9:56 PM
    I just figured that
    Surface
    clips by default by the
    Shape
    passed into it. Plus there doesn’t seem to be any Surface which provides flexibility there. Is there some specific reason why that is the case? My use case is that I am rotating something inside a Surface (to get proper contentColor) and I am rotating that item in there meaning that while it’s at for example 45° the corners get clipped. I guess I can make my own surface overload, but curious to see if I am missing some API and if not what the reason is for
    Surface
    to always clip.
    • 1
    • 1
  • t

    Travis Griggs

    09/19/2022, 10:21 PM
    Is there a way to get Compose Texts to autodetect clickable links in their text? Looking for something like iOS TextView url data detectors basically
    e
    u
    • 3
    • 8
  • a

    Adam Brown

    09/20/2022, 6:16 AM
    I've been going in circles about this for a while, thought I should just ask, see if anyone has some ideas. So I want to add a interactive scrollbar to
    BasicTextField
    , I can add a
    verticalScroll
    modifier, but that breaks the built in scrolling. What I really want is to maintain it's built in scrolling, but be able to access that for the scroll bar. Looking in
    CoreTextField
    the
    TextFieldScrollerPosition
    isn't passed in as an argument, so it doesn't look to me like there is anyway I could access it, and I think all of the related functions and classes are marked internal. Anyone have any good ideas?
  • s

    Stylianos Gakis

    09/20/2022, 7:25 AM
    Got a class like
    @Immutable
    @JvmInline
    value class Foo(val values: Set<Int>)
    And when generating compose metrics this gets read as
    unstable
    . When removing the
    @JvmInline
    and the
    value
    from it, and keeping the
    @Immutable
    (or
    @Stable
    ) it does in fact get inferred as stable looking at the generated files. This must be a bug right?
    z
    s
    • 3
    • 6
  • m

    melihgultekin

    09/20/2022, 8:40 AM
    Hi everyone. I’m not sure if it’s asked before but I couldn’t find the exact answers I’m looking for. unstable does not necessarily mean it is not skippable, right? I read these articles https://medium.com/androiddevelopers/jetpack-compose-stability-explained-79c10db270c8 https://chris.banes.dev/composable-metrics/ and they say:
    “A composable function is ‘skippable’ if Compose determines that it can completely skip calling a function”
    “if Compose can’t be sure, it will always be recomposed when its parent composable is recomposed.”
    From those, I understand as compose will do recomposition if a parameter is defined as unstable but what I experienced was a bit different. I run compose metrics and have this output for a composable:
    restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun DummyScreen(
      stable id: String
      stable onClick: Function1<Boolean, Unit>
      stable modifier: Modifier? = @static Companion
      unstable style: DummyStyle? = @dynamic Companion.Default
      unstable viewModel: DummyViewModel? = @dynamic hiltViewModel(null, $composer, 0, 0b0001)
    )
    Even though parameters are unstable, composable itself is marked as skippable. Is this expected?
  • e

    efemoney

    09/20/2022, 8:43 AM
    Use a gradient
    Brush,horizontalGradient(
      0.0f to cyan,
      0.5f to cyan,
      0.5f to lightBrown,
      1.0f to lightBrown,
      ...
    )
    a
    • 2
    • 2
  • g

    Guillaume Lardillier

    09/20/2022, 9:04 AM
    Hello, I have a little question regarding focus management. As requested (sorry for that), everything is in the following thread 🧵
    • 1
    • 1
  • j

    Jasmin Fajkic

    09/20/2022, 12:08 PM
    One question. I have screen with few view that are rendering conditionally. Question now is that if go to View B from View A when press hardware back button want to go to View A . But if I am on View A and press back button want just to exit app. Can I apply this logic with BackHandler?
    a
    i
    • 3
    • 6
Powered by Linen
Title
j

Jasmin Fajkic

09/20/2022, 12:08 PM
One question. I have screen with few view that are rendering conditionally. Question now is that if go to View B from View A when press hardware back button want to go to View A . But if I am on View A and press back button want just to exit app. Can I apply this logic with BackHandler?
is it smart to do something like this
BackHandler() {
    if(loginState.currentView === LoginView.EMAIL_VIEW.name) {
        loginViewModel.updateView(LoginView.LANDING.name)
    }
    else {
        activity?.finish()
    }
}
a

AmrJyniat

09/20/2022, 12:30 PM
You can achieve that via onBackPressedDispatcher If you're using fragment/activity , but I don't know if these Apis exists in Compose or not.
i

Ian Lake

09/20/2022, 2:58 PM
The whole point of BackHandler (which is the Compose specific way to get to the OnBackPressedDispatcher) is to only enable it when you actually want to handle back, so your code should look like:
BackHandler(enabled = loginState.currentView === LoginView.EMAIL_VIEW.name) {
  loginViewModel.updateView(LoginView.LANDING.name)
}
As per the docs: https://developer.android.com/jetpack/compose/libraries#handling_the_system_back_button
j

Jasmin Fajkic

09/20/2022, 2:59 PM
Thx a lot mate ❤️
i

Ian Lake

09/20/2022, 4:29 PM
The other option, of course, is to put the BackHandler directly within View B - once View B is removed from composition, its BackHandler gets disposed as well.
View count: 4