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

    Scott Kruse

    08/29/2021, 2:54 AM
    Whats the best way to put compose into a vertically scrolling tab driven via
    FragmentStateAdapter
    /
    CoordinatorLayout
    w/
    NestedScrollView
    ? Do we need to wrap it in some scrollable parent or should LazyColumn be sufficient?
    v
    • 2
    • 5
  • r

    Rekha

    08/29/2021, 6:03 AM
    Hi, Are there any samples for creating idlingresources? What is the replacement of countingidling resources from espresso. Thanks
    a
    a
    p
    • 4
    • 7
  • c

    Cristian Rosa

    08/29/2021, 1:45 PM
    [SOLVED} How do I set inside Scaffold • bottomAppBar + FAB As they are Overlapping or even better (FAB insert into bottomBar)
    • 1
    • 2
  • f

    Florian

    08/29/2021, 2:03 PM
    Compose's dark theme doesn't affect the status bar, right? How to work around this?
    k
    s
    l
    • 4
    • 4
  • d

    Dmitry Chernozubov

    08/29/2021, 2:38 PM
    Hi all. Someone can explain me why lazy column slow and skipping frames and when it will be fixed? 🙂
    a
    s
    • 3
    • 6
  • f

    Fudge

    08/29/2021, 5:50 PM
    Consider the `FancyTextField`:
    @Composable
    fun FancyTextField(value: String, onValueChange: (String) -> Unit, modifier: Modifier = Modifier) {
        Column(modifier) {
            TextField(value, onValueChange)
            Text("fancy!")
        }
    }
    While looking innocent, this code breaks the passed modifiers. If I pass for example
    Modifier.fillMaxWidth()
    , then only the
    Column
    will have expanded width, and the
    TextField
    will stay the same size, meaning that
    fillMaxWidth
    will not make
    FancyTextField
    fill max width (in practice). Obviously passing a modifier to
    TextFIeld
    (instead or in addition) won't work well. So how should
    FancyTextField
    be declared in such a way that modifiers work as expected?
    a
    z
    • 3
    • 7
  • f

    Florian

    08/29/2021, 6:27 PM
    Even tho I read the documentation, I can't wrap my head around why we need to use
    SideEffect
    here. The functionality works without the
    SideEffect
    call. Can someone tell me why we need it? https://google.github.io/accompanist/systemuicontroller/
    👍 1
    a
    • 2
    • 7
  • a

    adjpd

    08/29/2021, 7:49 PM
    To get Compose preview to work I need this dependency:
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    But then that means that library will increase the size of my production build. Is there a way around this?
    j
    s
    a
    • 4
    • 7
  • s

    Slackbot

    08/30/2021, 12:43 AM
    This message was deleted.
    d
    l
    r
    • 4
    • 26
  • d

    darkmoon_uk

    08/30/2021, 5:21 AM
    Layout Inspector bug? I have an App that starts out using UIView XML layouts, and later navigates to Compose defined screens. Layout inspector works on startup, but as soon as we navigate to the Compose screen, it shows the screen but the Component Tree is blank and no elements are clickable i.e. the inspector breaks. Using
    1.0.1
    and
    ui-tooling
    etc. same on Device / Emulator 🤷. Not even sure if the UIView/Compose mix is significant... inspector just plain doesn't work on Compose. Documentation says it should?
    n
    c
    • 3
    • 12
  • j

    Jan Skrasek

    08/30/2021, 7:21 AM
    Why is not NavController a local? I'd love to use ~ findNavController() instead of creating callbacks for every action/or passing the NavController down.
    f
    f
    +2
    • 5
    • 6
  • f

    Felix Schütz

    08/30/2021, 8:12 AM
    Is it possible to properly use the SplashScreen compat library (https://developer.android.com/about/versions/12/splash-screen-migration#splashscreen_compat_library) with Jetpack Compose? According to the examples, I would use it like so:
    class MainActivity : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            installSplashScreen()
    
            setContent {
                // ...
            }
        }
    }
    However,
    setContent
    replaces the root view when it finishes loading, so any custom splash screen animation will not play. Is there a better alternative?
    c
    • 2
    • 2
  • z

    zokipirlo

    08/30/2021, 9:12 AM
    Hi! Is there an option on
    TextField
    to prevent showing soft input similar to
    showSoftInputOnFocus
    on
    EditText
    ?
    f
    • 2
    • 3
  • a

    Alex

    08/30/2021, 9:59 AM
    Is there a way to use
    collectAsState()
    (or an equivalent) inside of a
    LazyListScope
    (outside of a
    @Composable
    )? The usecase is conditionally emitting either A or B items, depending on the content of a
    StateFlow
    f
    z
    • 3
    • 10
  • f

    Felix Schütz

    08/30/2021, 10:22 AM
    And another question: I implemented the shown navigation transition by having a upper nav host and a lower nav host. The lower nav host is wrapped inside a scaffold, which is a composable in the upper nav host. I know that it is always recommended to not use nested nav hosts and instead conditionally show the top and bottom bar in the scaffold. However, I want this specific transition, which scales in the second screen above the top and bottom bar of the first screen. As far as I'm concerned, this is not possible by using a single nav host inside a scaffold. Am I wrong / is there an alternative?
    navigation-transition.mp4
    p
    • 2
    • 4
  • i

    iamthevoid

    08/30/2021, 10:46 AM
    Does anybody develop cross platform native apps, KMM for example? Is there compose
    remember
    analog in SwiftUI?
    a
    w
    • 3
    • 3
  • m

    Marcin Środa

    08/30/2021, 12:56 PM
    Hi folks, is there a substitute for
    ViewTreeObserver.OnPreDrawListener
    in Compose? Looking for a way to delay startup due to data initialization. Was looking on https://developer.android.com/about/versions/12/features/splash-screen but can’t connect it with compose.
    ➕ 3
    n
    f
    c
    • 4
    • 8
  • w

    Walter Berggren

    08/30/2021, 1:48 PM
    Hi! I’m trying to replicate merging semantics information of a component’s children from the testing tutorial, but I’m running into different results than the tutorial. 🧵
    • 1
    • 6
  • z

    Zoltan Demant

    08/30/2021, 1:57 PM
    Is it possible to override a child composables onclick & ripple effect if its a button? In my scenario, a button is placed at the bottom of a card with padding around it; Id like the clickable area to cover the entire width of the card (similar to what could be acheived by specifying
    selectableItemBackground
    on the parent rather than child view in XML). If I specify a clickable composable around the button, the button will still grab focus (even if I mute its ripple effect through
    Modifier.clickable
    ). I can acheive it by using a
    Text
    instead of
    Button
    since it wouldnt be clickable, but then Id have to continiously mimic the button style exactly in the text composable.
    z
    f
    • 3
    • 5
  • f

    Fudge

    08/30/2021, 2:39 PM
    I imagine there are cases in which impossible constraints are specified to a
    ConstraintLayout
    . Will
    ConstraintLayout
    throw an exception in that case? Or just try to make do, ignore some constraints, etc? I'm facing a case in which I have a slightly complicated layout, and it seems like some constraints i'm specifying are being ignored
    f
    • 2
    • 4
  • r

    Rafs

    08/30/2021, 3:09 PM
    How do I load images from device storage using coil?
    rememberImagePainter
    always returns empty state when I pass a content Uri to
    data
    c
    f
    • 3
    • 2
  • l

    Lilly

    08/30/2021, 3:13 PM
    Is there any rule of thumb when to bundle multiple single states of a
    ViewModel
    into one state object (e.g.
    data class ViewState(..)
    )? In my opinion both have advantages and disadvantages. Exposing multiple states from VM keeps changes to the UI more granular but it's more cumbersome to keep track of every single state. On the other hand, exposing just one bigger state object has better maintenance because you always have to deal with just one state in your UI but in contrast when one of the fields changes, a new object is created. Imagine you have following state object:
    data class MyScreenState(
        val isLoaded: Boolean,
        val items: List<SomeType>,
        val sortedItems: List<SomeType>,
        val recommendedItems: List<SomeType>,
    )
    While
    isLoaded
    might changes quite frequently, the other fields do not and this yields to a massive unbalanced object creation. So I'm wondering if there is any rule of thumb when to use which approach?
    👀 4
    f
    c
    d
    • 4
    • 4
  • s

    Scott Kruse

    08/30/2021, 5:15 PM
    Survey: How long have you been leveraging Jetpack Compose for user-facing features in your Android production apps? follow up question, were there any gotchas / surprises in the wild that you encountered?
    m
    w
    +5
    • 8
    • 7
  • c

    Chris Johnson

    08/30/2021, 5:58 PM
    What's the consensus on providing your uiState via
    CompositionLocalProvider
    to other composables from your main composable? I assume this would be good for composables that you don't plan on re-using and are coupled tightly to that uiState. Rather than passing in my uiState to every composable that needs it. Or is this already a smell because each composable should only have things passed into it it needs? I've thought about this when let's say composable B needs to send data to composable C from composable A (from the uiState) and rather than pass in 8 things to composable B, I'd rather pass in a uiState so I have access to everything I need. (If a composable only needs 1-2 things then it makes sense to only pass those, but for composable dependencies that need 7-8 fields does this make sense to do?)
    z
    k
    a
    • 4
    • 21
  • h

    hfhbd

    08/30/2021, 6:57 PM
    What is the reason to not update the UI if you use Room directly with Compose:
    dao.get().collectAsState(emptyList())
    with
    interface Dao { @Query(...) fun get(): Flow }
    ? You have to use a ViewModel to get updates on DB changes. WA: wrap the
    collect
    in VM and emit them to the flow accessed by Compose...
    a
    • 2
    • 2
  • m

    mattinger

    08/30/2021, 7:14 PM
    Anyone know of any tutorials for managing TopAppBar actions with the nav controller? In the past, we set the supportActionBar and then within each fragment inflated a menu. I’m curious what the equivalent process would be for compose. (short of maintaining one huge view model with flags for when to enable each menu item)
    c
    • 2
    • 1
  • t

    trickybits

    08/30/2021, 7:17 PM
    This is the only way I could figure out how to tile a background image loaded by Coil. 🤔 Any thoughts on making this better/more correct?
    var tiledBackgroundImageShader by remember { mutableStateOf<ShaderBrush?>(null) }
        val imageLoader = LocalImageLoader.current
        val localContext = LocalContext.current
        LaunchedEffect(backgroundImageSrc) {
            val builder = ImageRequest.Builder(localContext).data(backgroundImageSrc)
            val result = imageLoader.execute(builder.build()).drawable?.toBitmap()
            if (result != null) {
                val shader = ImageShader(result.asImageBitmap(), tileModeX = TileMode.Repeated, tileModeY = TileMode.Repeated)
                tiledBackgroundImageShader = ShaderBrush(shader)
            }
        }
    and for the content:
    Box(
            modifier = Modifier
                .drawWithCache {
                    onDrawBehind {
                        drawRect(backgroundColor)
                        tiledBackgroundImageShader?.let { drawRect(it) }
                    }
                }
        ) {
    c
    • 2
    • 2
  • s

    Slackbot

    08/30/2021, 9:45 PM
    This message was deleted.
    b
    • 2
    • 2
  • d

    darkmoon_uk

    08/31/2021, 1:01 AM
    Has anyone successfully performed Compose UI tests on the content of a
    ComposeView
    within a traditional
    View
    hierarchy? Any examples of this?
    w
    • 2
    • 26
  • j

    jkm

    08/31/2021, 1:16 AM
    Hey again, I’m having some trouble with
    Modifier.onFocusEvent
    Say I have a scrollable list of buttons and at the very bottom of this list I have a
    OutlinedTextField
    . I’ve applied the following to the
    OutlinedTextField
    .onFocusEvent {
        if (it.isFocused) {
            scope.launch { scrollState.animateScrollTo(scrollState.maxValue) }
        }
    }
    This works as expected in that when I tap on the
    OutlinedTextField
    , my list scrolls to the bottom. The issue is that even when I tap on other elements (i.e. one of the buttons), that also scrolls the user to the bottom. Any ideas?
    w
    • 2
    • 1
Powered by Linen
Title
j

jkm

08/31/2021, 1:16 AM
Hey again, I’m having some trouble with
Modifier.onFocusEvent
Say I have a scrollable list of buttons and at the very bottom of this list I have a
OutlinedTextField
. I’ve applied the following to the
OutlinedTextField
.onFocusEvent {
    if (it.isFocused) {
        scope.launch { scrollState.animateScrollTo(scrollState.maxValue) }
    }
}
This works as expected in that when I tap on the
OutlinedTextField
, my list scrolls to the bottom. The issue is that even when I tap on other elements (i.e. one of the buttons), that also scrolls the user to the bottom. Any ideas?
w

Will Shelor

08/31/2021, 1:55 AM
I’d put a breakpoint and see if it is actually calling this method, and if so, what “it” is in this case. It’s possible that your scrollable list is reusing views, and you’ll need to qualify your “it” to make sure you’re interacting with the element you think you are.
👍 1
View count: 1