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

    Sebastian Höbarth

    10/11/2022, 10:00 AM
    I have an Issue with
    WindowInsets
    in
    BottomAppBar
    . The
    WindowInsets
    padding are set after the transition to the new screen finishes and that results in a jump of the bottom bar. Is there a work arround for that? (video in thread)
    Scaffold(topBar = {
                ...
            }, bottomBar = {
                // Wrap the navigation bar in a surface so the color behind the system
                // navigation is equal to the container color of the navigation bar.
                Surface(
                    color = MaterialTheme.colorScheme.surface,
                    tonalElevation = 6.dp
                ) {
                    BottomAppBar(
                        modifier = Modifier
                            .windowInsetsPadding(
                                WindowInsets.safeDrawing.only(
                                    WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
                                )
                            ),
    s
    • 2
    • 14
  • o

    oday

    10/11/2022, 10:06 AM
    I’m having an issue with loading a list of items, as in when I let the execution run normally, nothing shows up, but if I debug and basically wait some time, then the items appear what I do to make them appear is set the state to Success(items) and listen to it in my composable to know whether to show Loading or the items
    z
    • 2
    • 3
  • u

    Utkarsh Tiwari

    10/11/2022, 12:56 PM
    @Adam Powell @Zach Klippenstein (he/him) [MOD] sorry to tag you guys. But I’d really appreciate if someone could look into this when you have time. 🙏
    a
    k
    • 3
    • 3
  • p

    Pedro Alberto

    10/11/2022, 2:24 PM
    Does someone know a nice way to have a layer on top of button but same shape and size as the button ? Context: I need to have a disabled state that is applied across the button.
  • m

    Marco Pierucci

    10/11/2022, 3:25 PM
    Is it possible to have several Lazy rows synced with the same
    ListState
    ? ( For example if a user scrolls al rows are scrolled at the same time)
    m
    s
    • 3
    • 5
  • c

    Chris Johnson

    10/11/2022, 9:36 PM
    Is there a way to prevent Focus on a TextField?
    Modifier.focusable(false)
    isn't doing what I expect it to do. My use case is I want to have a TextField that looks editable, but when clicked on is not focused and instead goes to a different screen. Ideally I'd like to use
    enabled = false
    but that changes the colors in an undesirable way. Currently, it still focuses the text in the TextField before navigating away
    k
    z
    +2
    • 5
    • 11
  • k

    KotlinLeaner

    10/11/2022, 11:16 PM
    Hi guys, I am trying to bind services in compose app but it always return null to me. I tried this stack overflow. But it didn't work to me. Anyone guide me on this ?
    • 1
    • 4
  • z

    zt

    10/11/2022, 11:20 PM
    I'm having some trouble thinking of how I should design the navigation in my app I've got several screens: Home, Feed, Library, Search, Channel, Playlist, Settings (with subscreens for categorization) and Player The home, feed and library screens are the first thing to show when the app is loaded, and can be navigated between using the bottom bar. The other screens are ones that are opened by other methods Any idea how I could structure this in my navhost?
    s
    p
    • 3
    • 2
  • f

    fengdai

    10/12/2022, 3:40 AM
    This is the code I’m running:
    @Preview
    @Composable
    fun Preview() = Row {
        val fontSize = 48.sp
        val modifier = Modifier.border(1.dp, Color.Blue)
        Text(text = "Function", modifier, fontSize = fontSize)
        Text(text = "功能", modifier, fontSize = fontSize)
        Text(text = "機能", modifier, fontSize = fontSize)
    }
    s
    j
    +2
    • 5
    • 15
  • o

    oday

    10/12/2022, 8:28 AM
    say for example I have an Activity which does setContent and starts a composable like EventsNavHost (has a NavHost inside and determines where to go from that screen) inside I have Events composable (the actual list of events let’s say) I am passing the callback to this EventsNavHost so that it could pass it to the Events so that it could run it on event clicked, the callback just includes opening another screen with the given event details and whatever, great but I also want it to do something that is right now sitting in the viewModel for the parent activity (the one that EventsNavHost is started from) so you got 1 part of the code i want to pass that opens a new screen, and another that does something that should belong in the viewmodel, how do I pass both to EventsNavHost > Events > onEventCLicked?
    • 1
    • 2
  • o

    oday

    10/12/2022, 10:18 AM
    how do I prevent the same
    when (state)
    to be run on each recomposition ? cause I have the state changing from the viewmodel due to some request and something happening there that will cuase it to change, and then the when gets triggered again and the actions resulting from it happen again
    e
    • 2
    • 5
  • a

    Anmol Verma

    10/12/2022, 11:06 AM
    Hi Everyone I have been writing a Jetpack Compose Kotlin Multiplatform project which is a Slack clone and uses gRPC(kotlin) as backend , will continue to maintain and improve this as I get time and share updates with the community 1. Create workspaces ✅ 2. Register ✅ 3. Login ✅ 4. Create channels ✅ 5. Send messages in channels ✅ 6. Send 1:1 messages ✅ 7. Misc bug fixes 🚧 Attached video demos for JVM and Android, (compose iOS is maintained but has issues with gRPC library) here’s the source code https://github.com/Anmol92verma/SlackComposeMultiplatform
  • a

    abu naser

    10/12/2022, 12:04 PM
    hello guys . is there any way to convert an AnnotatedString to PDF and also apply all its spanStyle and paragraph style ? or if we can transform AnnotatedString to bitmap then PDF its also works.
    z
    h
    • 3
    • 6
  • a

    agrosner

    10/12/2022, 12:59 PM
    is there a way to turn off animations for a compose hierarchy, for example, in paparazzi snapshots, i want the animation to complete immediately. I can set a property / composition local manually in my composables, but that doesnt seem ideal. 🤔
    z
    d
    • 3
    • 10
  • z

    Zach

    10/12/2022, 3:41 PM
    I have a custom text field with
    BasicTextField
    and
    OutlinedTextFieldDecorationBox
    , and when the field is tall enough for some reason, this green teardrop shaped draggable handle appears. Is there any way to remove this, or at least style it?
    z
    a
    • 3
    • 5
  • a

    Aaron Waller

    10/12/2022, 4:09 PM
    I can’t pass a drawable id (R.drawable.image) as an INT for my painterResource(). When running in release mode I get the following crash:
    java.lang.IllegalArgumentException: Only VectorDrawables and rasterized asset types are supported ex. PNG, JPG
    the image I pass as an INT is a PNG.
    a
    e
    k
    • 4
    • 7
  • j

    Jasmin Fajkic

    10/12/2022, 5:48 PM
    Hello guys. Have small issue. I have nav host with
    composable
    and
    bottomSheet
    ( from accompanist ). In my composable route i set custom BackHandler. But when i navigate from that screen to bottom sheet screen , my bottom sheet screen inherit back handler behaviour from previous screen. Any chance to solve it 😞 ?
    i
    • 2
    • 8
  • a

    Alexandru Hadăr

    10/12/2022, 7:52 PM
    How should we observe a flow to navigate to a different screen, when using @Compose and ViewModel? Suppose we wait for a
    logout
    call to finish, how should we collect the flow result in a @Composable function? The only way I could think of would be something like this:
    @Composable
    private fun ProfileScreen(
        onUserLoggedOut: () -> Unit,
        viewModel: UserProfileViewModel = viewModel()
    ) {
        LaunchedEffect(key1 = Unit) {
            viewModel.onUserLoggedOut.collect { userLoginState ->
                when (userLoginState) {
                    UserLoginState.LOGGED_IN -> Unit // do nothing
                    UserLoginState.LOGGED_OUT -> onUserLoggedOut()
                }
            }
        }
    }
    However, it seems a bit off. IS there any better solution to this?
    k
    • 2
    • 5
  • v

    v79

    10/12/2022, 9:02 PM
    Hello - probably a beginner's question. I was looking at `VisualTransformation`to add some simple transformation to a `OutlineTextField`(like adding currency formatting, or percentage % display). But as soon as I add `
    class PercentageVisualTransformation : VisualTransformation {
        override fun filter(text: AnnotatedString): TransformedText {
            TODO("Not yet implemented")
        }
    }
    The code no longer compiles with an error message:
    Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option
    - I'm not comfortable changing compiler options for what, I thought, should be a simple thing to do. Any suggestions?
    j
    a
    • 3
    • 11
  • j

    Joseph Hawkes-Cates

    10/12/2022, 9:22 PM
    We’ve run into an odd situation with orientation changes on a Galaxy Tab s6 Lite. We have the
    android:configChanges
    property set in our Activity in our AndroidManifest and one of the values we have in there is orientation. We also utilize
    LocalConfiguration.current.orientation
    to check the orientation in some places and act accordingly. This works on all of the devices we’ve tested except this Galaxy Tab s6 Lite. For some reason we are always getting ORIENTATION_LANDSCAPE as the value on the current config on that device, unless we remove “orientation” from the conifgChanges list in the manifest. Has anyone seen this before or aware of another option to work around this issue?
    a
    • 2
    • 6
  • p

    PHondogo

    10/13/2022, 8:36 AM
    Hello! How can I make image from byte array?
    m
    • 2
    • 2
  • s

    spierce7

    10/13/2022, 7:33 PM
    What other Android/Compose libraries are looking to be made multiplatform from the Android team? One of the ones that I think would be the most useful would be the navigation library.
    s
    • 2
    • 1
  • s

    Siyamed

    10/13/2022, 9:56 PM
    thanks for detailed description. the difference for letterspacing is that on compose side we use a Span (https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:text/tex[…]xt/android/style/LetterSpacingSpanEm.kt?q=LetterSpacingSpanEm) where as platform is using directly function on Paint (https://cs.android.com/android/platform/superproject/+/master:frameworks/base/graphics/java/android/graphics/Paint.java;l=1821?q=Paint.java)
    j
    • 2
    • 6
  • z

    zt

    10/14/2022, 5:21 AM
    Has anyone attempted adding picture in picture? I want to implement it eventually in my app but I'm not sure how
  • p

    pajatopmr

    10/14/2022, 6:29 AM
    I see this code in one of the Android sample apps (Jetsnack):
    @Stable class Filter(
    val name: String,
    enabled: Boolean = false,
    val icon: ImageVector? = null
    ) {
    val enabled = mutableStateOf(enabled)
    }
    which has me wondering why the “val enabled” property is not passed in the constructor and the class is not a data class. Is this some sort of compose pattern? Possibly to use in a destructured access to the “setEnabled” setter, which I do observe in Jetsnack.
    a
    • 2
    • 1
  • y

    Yoni Obia

    10/14/2022, 7:50 AM
    Hello ! I’ve created a the following class that use
    Context
    and
    Pools.SimplePool
    via Hilt I’ve made it into a Singleton. Would creating a LocalProvider for this not recommended ?
  • z

    Zoltan Demant

    10/14/2022, 8:51 AM
    Is there any meaningful difference in doing
    setContent{ LaunchedEffect(Unit){ suspend code } }
    in my activity, as compared to
    lifecycleScope.launch { suspend code }
    ? Both calls would be made in onCreate, and Im just curious really.
  • r

    reactormonk

    10/14/2022, 9:43 AM
    Is there a layout like `Row`/`Column` that makes the items flow like a text?
    y
    • 2
    • 2
  • o

    oday

    10/14/2022, 11:41 AM
    what could cause some Composable to not be recomposed when some state that’s being observed inside it has changed from the viewmodel?
    z
    • 2
    • 36
  • f

    freddiewang

    10/14/2022, 1:44 PM
    Hello, does anyone know how to keep the state of AndroidView in Compose UI correctly? I have a custom ImageView which shows a
    Path
    and some control points, I’d like to keep the same state after going back to the screen but don’t know how to keep the state in Compose UI
    c
    • 2
    • 3
Powered by Linen
Title
f

freddiewang

10/14/2022, 1:44 PM
Hello, does anyone know how to keep the state of AndroidView in Compose UI correctly? I have a custom ImageView which shows a
Path
and some control points, I’d like to keep the same state after going back to the screen but don’t know how to keep the state in Compose UI
c

czuckie

10/14/2022, 2:29 PM
this might not be easy to hear, but the best way to maintain the state of the view would be to make it extrinsic to the view, that way you can simply pass the state in via the
update
lambda that you can provide to the
AndroidView
composable. If that's not feasible, I imagine implementing onSaveInstanceState/onRestoreInstanceState may work? What have you tried?
f

freddiewang

10/14/2022, 3:38 PM
Thanks! I think I will try onSaveInstanceState to see it works or not. Because the Path and control points are the private properties in the view.
I’ve tried to use onSaveInstanceState/onRestoreInstanceState to keep the view state, but only
onSaveInstanceState
is invoked and
onRestoreInstanceState
is never invoked in Compose UI. The workaround is to export the saved state to Compose. Still finding a better solution
View count: 14