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

    Abhishek Dewan

    03/08/2021, 2:42 AM
    For anyone trying to use compose and hilt to inject viewModels along with compose nav host composable, here is a github issue to be aware of https://github.com/google/dagger/issues/2166#issuecomment-769162910. In short, if you have a navHost that defines routes then viewModel inject stops working in those routes. For e.g
    NavHost(navController = navController, startDestination = "splash") {
                composable("splash") {
                    SplashScreen(navController)
                }
                composable("home") {
                    HomeScreen()
                }
            }
    and you SplashScreen was defined somewhat like this
    @Composable
    fun SplashScreen(navController: NavHostController) {
        
        val viewModel: SplashViewModel = viewModel()
    The injection will not work if your SplashScreenViewModel takes non zero constructor params. In order to fix this you need to inject the viewModel somewhat like this
    val viewModel: SplashViewModel = viewModel(
            factory = HiltViewModelFactory(
                LocalContext.current,
                navController.getBackStackEntry("splash")
            )
        )
    and this is possible by using the
    androidx.hilt:hilt-navigation:1.0.0-alpha03
    library. I spent the last hour trying to debug why despite everything being right, the injection wouldn’t work 😄
    i
    • 2
    • 1
  • n

    Neal Sanche

    03/08/2021, 4:08 AM
    Does Jetpack Compose have a concept of providing
    systemGestureExclusionRects
    for gesture navigation? Alternatively, is it possible to obtain the screen bounds of a particular composable so I can use it to set these?
    a
    • 2
    • 3
  • i

    Indu

    03/08/2021, 6:56 AM
    Just wanted to clarify whether my understanding of LaunchedEffect and rememberUpdatedState is correct. This is an example from Android developer site @Composable fun NotificationHost(state: NotificationState, onTimeout: (Notification) -> Unit) { val currentOnTimeout by rememberUpdatedState(onTimeout) state.currentNotification?.let { currentNotification -> LaunchedEffect(currentNotification) { // We should not restart this delay if onTimeout changes, but we want to call // the onTimeout we were last recomposed with when it completes. delay(NotificationTimeout) currentOnTimeout(currentNotification) } } // ... } -- LaunchedEffect will be executed during initial composition. -- And after that the effect will only run if the effect's parameters change. -- Sometimes the effect refers a value or event callback in its code block which is not passed as a parameter to the effect.( We don't want to restart the effect when the value or the event callback changes) . But we need to remember them during recomposition. Also they need to be updated with the new value or callback during recomposition. So we use rememberUpdatedState. This way if the effect is relaunched when one of its key is updated it will get the updated value or callback which is referred in the effect. -- LaunchedEffect will survive recompositions Thanks
    👍 1
    l
    a
    z
    • 4
    • 13
  • j

    Jason Ankers

    03/08/2021, 7:44 AM
    How could I prevent scroll gestures from a
    LazyColumn
    inside a bottom sheet from dismissing the sheet? is it possible to disable the sheet swipe gestures within a certain boundary? (in my case I want to disable them over the
    LazyColumn
    )
    m
    • 2
    • 4
  • p

    pawegio

    03/08/2021, 8:37 AM
    BackHandler
    seems to not intercept system back presses on
    AppCompatActivity
    restart in my case (in nested
    NavHost
    composables). Is it a known issue? 🤔
    a
    i
    • 3
    • 5
  • r

    Ravi

    03/08/2021, 9:04 AM
    SharedElement transition in Jetpack Compose is possible? Can any one please share sample project. I've found one but its not updated from a long time https://github.com/mobnetic/compose-shared-element
    a
    • 2
    • 1
  • z

    zhuinden

    03/08/2021, 9:38 AM
    I'm trying to make SaveableStateProvider work - I have Parcelable immutable data classes as keys (so hashCode/equals) and ensure SavedStateProviders exist while the keys are added, yet I'm still losing the saved state. What am I missing?
    a
    • 2
    • 24
  • p

    Piotr Prus

    03/08/2021, 9:40 AM
    Compose AndroidView with GoogleMap has an issues on devices with android 6 & 7 (didn’t test android 5 tho). I used sample project Crane for reproduction. You can check below GIF and issueTracker. Anyone has a workaround until fix? https://issuetracker.google.com/issues/182063556
    a
    • 2
    • 2
  • s

    Sinan Gunes

    03/08/2021, 12:12 PM
    I think I am doing something really bad here. Is there a way to see which part of my code effects performance so bad?
    a
    m
    • 3
    • 5
  • o

    Olivier Patry

    03/08/2021, 12:42 PM
    I can't make a 1.dp height linear progress bar
    LinearProgressIndicator(Modifier.fillMaxWidth().height(1.dp))
    The implementation hard codes its size it seems:
    Canvas(
        modifier
            .progressSemantics()
            .size(LinearIndicatorWidth, LinearIndicatorHeight)
            .focusable()
    Any solution?
    o
    a
    l
    • 4
    • 8
  • j

    julioromano

    03/08/2021, 12:53 PM
    Is it possible to apply a tint to an
    ImageBitmap
    ?
    n
    • 2
    • 6
  • s

    Sinan Gunes

    03/08/2021, 2:14 PM
    1.4.31 is not compatible.
    d
    j
    z
    • 4
    • 8
  • l

    Lauren Yew

    03/08/2021, 3:01 PM
    Hi all! If I use jetpack compose in my android library, does an app that uses my library also have to use jetpack compose? (With the non-stable gradle plugin setup, etc.)? I'd like to use jetpack compose in my libraries, but some of my apps cannot use the non-stable gradle plugin setups required for jetpack compose in production.
    a
    • 2
    • 1
  • d

    Daniele B

    03/08/2021, 3:04 PM
    I upgraded to
    1.0.0-beta01
    , and the
    preferredSize
    modifier gives an error. What is the new modifier for that?
    d
    t
    • 3
    • 3
  • t

    than_

    03/08/2021, 3:41 PM
    Hi, I'm trying to update my state with reducer. The only way I was able to achieve that was by using
    ViewModel
    and
    collectAsState
    but by doing that I lost the ability to change state in the interactive mode in android studio. Is there something I'm missing?
    z
    • 2
    • 12
  • i

    izyaboi

    03/08/2021, 3:44 PM
    I have one question. how can i handle rember state on bottomnavigation switch. I have a home screen with a composable that has a
    var isPlayingState by remember { mutableStateOf(false) }
    and set it in clickable (Box)
    isPlayingState = if (player.isPlaying) {
        player.pause()
        false
    } else {
        player.play()
        true
    }
    If i navigate to the second tab and navigate back the value ist false and not the last state i set ?why?
    d
    j
    • 3
    • 4
  • i

    Igor Brishkoski

    03/08/2021, 3:44 PM
    Can I build and run jetpack compose project with stable AS version?
    🇳🇴 1
    g
    • 2
    • 2
  • d

    Deepak Gahlot

    03/08/2021, 4:24 PM
    Hello I'm trying to implement a bottom-sheet which will launch on the icon click on the top bar. But i'm getting a weird result below are the details
    • 1
    • 4
  • h

    Halil Ozercan

    03/08/2021, 4:31 PM
    Although everyone is working on countdown challenge, I went back to my old video player project and updated it to beta01. Also, I added this youtube like MinimizableLayout. It's amazing how simple it is to implement something like this with compose.
    videoplayer.mp4
    👏 18
    t
    p
    • 3
    • 3
  • o

    Orhan Tozan

    03/08/2021, 4:58 PM
    Any ETA for the Compose beta02 release?👀
    j
    c
    • 3
    • 21
  • s

    Sinan Gunes

    03/08/2021, 6:13 PM
    about
    #AndroidDevChallenge
    … My github actions fails on this test:
    com.example.androiddevchallenge.ExampleInstrumentedTest > sampleTest[test(AVD) - 10] FAILED 
    254
    	kotlin.UninitializedPropertyAccessException: lateinit property remeasurement has not been initialized
    255
    	at androidx.compose.foundation.lazy.LazyListState.snapToItemIndexInternal$foundation_release(LazyListState.kt:186)
    I haven’t touch that part. Any of you faced similar?
    🇳🇴 1
    a
    b
    +2
    • 5
    • 15
  • a

    alexsullivan114

    03/08/2021, 6:33 PM
    If I want to get the measurements for a given Composable - say a Text, how would I go about that? For reference, my use case is that I'm trying to basically animate a column up or down a certain number of items within the column. So my thought is I'd use one of the animation state primitives and change the translation y by some multiple of the height of an item inside the column
    z
    a
    • 3
    • 3
  • a

    alexsullivan114

    03/08/2021, 7:22 PM
    More questions! I'm struggling to get my brain to understand animations in declarative land. I've been looking at the animation codelab which is helpful, but I'm still struggling. Let's say I have some immutable composable and I want to animate changes to it whenever its recomposed with a new value. Is that possible? Is that something that you'd do at the immutable composable layer or at some wrapper layer?
    l
    d
    • 3
    • 8
  • a

    Arkadii Ivanov

    03/08/2021, 8:30 PM
    https://twitter.com/WajahatKarim/status/1369007522238128137?s=19
    i
    a
    w
    • 4
    • 7
  • g

    Gabriel Melo

    03/08/2021, 9:27 PM
    This is probably something easy I'm missing, but is there an easy way to animate between ImageVector states? I couldn't find an appropriate animate*AsState nor a suitable TwoWayConverter to use with animateValueAsState. For context, the icon is chosen according to a Boolean value (which also lacks an animate*AsState function).
    d
    i
    n
    • 4
    • 8
  • e

    eygraber

    03/08/2021, 11:11 PM
    Is there a built in way to create an ImageBitmap from an array of rgba values?
    t
    • 2
    • 8
  • j

    Joseph D

    03/08/2021, 11:46 PM
    why doesn't drawArc have the cap parameter? I need to round the line I draw.
    a
    • 2
    • 2
  • t

    Tash

    03/09/2021, 12:36 AM
    Having some trouble understanding the
    key
    Composable. Noticed its usage in Jetcaster’s Pager:
    for (page in minPage..maxPage) {
        val pageData = PageData(page)
        val scope = PagerScope(state, page)
        key(pageData) {
            Box(contentAlignment = Alignment.Center, modifier = pageData) {
                scope.pageContent()
            }
        }
    }
    What exactly is the purpose of
    key
    here? Would love some more insight into how/what it does in general. The implementation of
    key
    doesn’t betray its functionality, since the function params are “unused”.
    👍 1
    a
    • 2
    • 3
  • d

    dewildte

    03/09/2021, 1:04 AM
    Does anyone know how to get a BottomAppBar to hide upon scroll of a LazyColumn?
    l
    b
    +2
    • 5
    • 12
  • c

    Colton Idle

    03/09/2021, 1:11 AM
    @Composable
    fun PadMyContentWithTitle(
        modifier: Modifier = Modifier,
        header: String = "",
        content: @Composable ColumnScope.() -> Unit
    ) {
        Column(modifier) {
            Text(text = header)
            content(modifier.padding(horizontal = 16.dp))
        }
    }
    I want to have a composable with that essentially takes in another compasable (slot) but pads it on the left and right and adds a Text on top of it. This is what I came up with but I can't actually call
    content(modifier.padding(horizontal = 16.dp))
    . Is the way around this just to nest the context in a Box/Column and apply padding to that?
    :yes: 1
    t
    i
    • 3
    • 6
Powered by Linen
Title
c

Colton Idle

03/09/2021, 1:11 AM
@Composable
fun PadMyContentWithTitle(
    modifier: Modifier = Modifier,
    header: String = "",
    content: @Composable ColumnScope.() -> Unit
) {
    Column(modifier) {
        Text(text = header)
        content(modifier.padding(horizontal = 16.dp))
    }
}
I want to have a composable with that essentially takes in another compasable (slot) but pads it on the left and right and adds a Text on top of it. This is what I came up with but I can't actually call
content(modifier.padding(horizontal = 16.dp))
. Is the way around this just to nest the context in a Box/Column and apply padding to that?
:yes: 1
t

Timo Drick

03/09/2021, 2:14 AM
You cloud also provide the padding to the content e.g
content: @Composable ColumnScope.(PaddingValues) -> Unit
Scaffold do it this way. But it depends on what you want.
:thank-you: 1
☝️ 1
c

Colton Idle

03/09/2021, 3:05 AM
@Timo Drick neat little trick. Not sure I exactly follow, but would that basically mean that I would just have this instead:
content(ColumnScope, PaddingValues(horizontal = 16.dp))
I did look into the Scaffold source but I am admittedly a little bit lost.
Adam Powell you responded "Yes", but just wanted to see if you could confirm whether a Box would work or not. I can't get it to work because of ColumnScope... but should I change ColumnScope or should I just use a Column instead of a Box?
i

Ian Lake

03/09/2021, 3:34 AM
You can always add another Box around your Column as an implementation detail. Kind of depends if you want a child to opt out (i.e., not apply your modifier if it wants to go edge to edge) or if you want to make it mandatory
t

Timo Drick

03/09/2021, 8:44 AM
If you content needs ColumnScope you have to encapsulate it into a column. Otherwise you could also forward the BoxScope
@Composable
fun PadMyContentWithTitle(
    modifier: Modifier = Modifier,
    header: String = "",
    content: @Composable ColumnScope.() -> Unit
) {
    Column(modifier) {
        Text(text = header)
        Column(modifier.padding(horizontal = 16.dp)) {
            content()
        }
    }
}
c

Colton Idle

03/09/2021, 3:59 PM
I don't want the child to be able to opt out. So I think I will just wrap it in a column and be done with it. @Timo Drick how would I implement your original suggestion? I understand how wrapping in a column would work, but I'm curious how I could do it without that using the PaddingValues technique you suggested.
View count: 3