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

    ste

    07/25/2022, 5:34 PM
    How can I add a good looking fling behaviour to the red rect? All I see is the velocity tracker returning nonsense values (most of the times) - what am I missing?
    a
    • 2
    • 3
  • a

    Alex Vanyo

    07/25/2022, 6:16 PM
    One of the tricky parts here when looking at a specific implementation is how it comes down to naming and the associated expectations. When you have a single
    MutableStateFlow<MyUiEvent>
    , it reads like you are prolonging the handling of an event and keeping it in-flight for longer to be handled later. When you call
    triggerEvent
    , that sort of reads as “tell the UI to do this thing” (both of which are antipatterns as described in the article) Telling the UI to do something is not directly possible. If the UI isn’t available, then multiple calls to
    triggerEvent
    will clear out the previous “event” that was sent, without it being handled. Maybe that’s what you want, and maybe not, depending on the exact situation. Another weird issue that might happen because
    block
    is suspending: What happens if, while
    block
    is in the middle of running,
    triggerEvent
    is called again? I would try to turn
    triggerEvent
    into updating some state that more accurately reflects why you want to go to a different screen. Then, the
    LaunchedEffect
    reads more like “I am currently showing this
    Composable
    , and the state I am getting from the
    ViewModel
    says Y. Therefore, I should navigate somewhere else, and maybe tell the
    ViewModel
    I did so”
    r
    c
    m
    • 4
    • 7
  • s

    Sean McQuillan [G]

    07/25/2022, 6:45 PM
    Is anyone subclassing
    Paragraph
    ?
    class MyParagraph: Paragraph {...}
    If so, can you share a bit more about what you're doing and why you chose not to wrap it?
    class MyParagraphWrapper(val paragraph: Paragraph)
  • j

    Jasmin Fajkic

    07/25/2022, 7:05 PM
    Hello. Maybe this question is already asked but really want to see how other people manage this. I need access to navcontroller deep down in child component. I do not want to do react thing “props drill” and that every piece of app knows for navcontroller event it does not need it. Is there any better approach to pass navcontroller deep down? Local composition?
    c
    d
    i
    • 4
    • 9
  • d

    Daniel Rotenberg

    07/25/2022, 8:59 PM
    Hi all, How can I create custom snack bar which used in scaffold? details in thread.
    k
    • 2
    • 2
  • z

    zt

    07/26/2022, 3:32 AM
    I'm using a LazyColumn to display a list of videos but it loses its scroll position when navigating away from it to another screen. If i remove the loading indicator item then it remembers the scroll position properly
    LazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .padding(horizontal = 14.dp),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.spacedBy(8.dp)
        ) {
            items(videoListItems) { video ->
                if (video == null) return@items
    
                VideoCard(
                    video = video,
                    onClick = { onClickVideo(video.id) },
                    onClickChannel = { onClickChannel(video.author!!.id) }
                )
            }
    
            item {
                videoListItems.loadState.apply {
                    when (append) {
                        is LoadState.Loading -> {
                            CircularProgressIndicator(modifier = Modifier.padding(4.dp))
                        }
                        is LoadState.Error -> {
                            (append as LoadState.Error).error.printStackTrace()
    
                            Text("An error has occurred")
                        }
                        else -> Unit
                    }
                }
            }
        }
    i
    • 2
    • 3
  • c

    Colton Idle

    07/26/2022, 4:53 AM
    I'm using the sample BottomNavigation bar and it's items like such:
    BottomNavigation {
            items.forEachIndexed { index, item ->
                BottomNavigationItem(
                    icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
                    label = { Text(item) },
                    selected = selectedItem == index,
                    onClick = { selectedItem = index }
    )}}
    but on samsung devices (which are typically "zoomed in" out of the box) the text and icon overlap. If I try to increase the icon size (or add padding) then it grows larger than the bottomBar can support and so my icons are cut off. Surprisingly the BottomNavigationBar doesn't grow in height to support the larger text size or icon size. Is there any "right" way to fix this or should I look to implement an autosize text for the tab text?
    c
    l
    • 3
    • 3
  • a

    allan.conda

    07/26/2022, 7:31 AM
    Reading about Compose Phases, I’m not sure about one thing. How does Scrollable list states avoid causing a recomposition (just remeasure/redraw)? I’m reading the source and saw a lot of mutableStates to track the scroll state, which should trigger recomposition in my understanding. But it seems to just call
    remeasure
    instead. Is there an optimization happening somewhere for scrolling?
    a
    • 2
    • 2
  • s

    Stylianos Gakis

    07/26/2022, 9:46 AM
    I want to get the size of a composable I’m currently in, is there a way to do this “inline” without doing something that moves this to the next frame? Say I got a state like this
    var width by remember { mutableStateOf(0f) } // 0f or 0 or 0.dp not sure what I need yet
    var height by remember { mutableStateOf(0f) }
    Canvas can get you a size but can only set it on the next frame to the local state as I understand.
    Canvas(Modifier.fillMaxSize()) {
      width = this.size.width
      height = this.size.height
    }
    OnGloballyPositioned also on the next frame
    .onGloballyPositioned { it.size.height | width }
    BoxWithConstraints uses subcomposition. My use case is trying to get the bounds of my Canvas in order to animate something that’s moving inside of it and make sure it’s not going outside. What other options do I have? Or is getting it from canvas and saving it to a local state the way to go? Also what if I was not using a Canvas anyway, what other alternatives are there?
    m
    • 2
    • 2
  • l

    Lukasz Kalnik

    07/26/2022, 12:42 PM
    Is there a dropdown spinner, showing the currently selected option when collapsed and with an expand/collapse arrow?
    j
    • 2
    • 4
  • p

    Programmistich

    07/26/2022, 3:44 PM
    Any modifier for hold element?
    combinedClickable()
    have onClick/onDouble/onLong but dont have onHold
    l
    • 2
    • 2
  • l

    Lokik Soni

    07/26/2022, 6:00 PM
    Hi all I am collecting flow in compose using collectAsState() But don't know how to make it lifecycle aware or collectAsState() is already lifecycle aware. In compose screen
    val isAlarmOn by viewModel.alarmBtnState.collectAsState()
    In ViewModel
    val alarmBtnState = isAlarmActivated(Unit).map {
        it.successOr(DEF_VAL_ALARM_ACTIVATED)
    }.stateIn(viewModelScope, WhileViewSubscribed, DEF_VAL_ALARM_ACTIVATED)
    a
    o
    m
    • 4
    • 18
  • c

    Chuck Stein

    07/26/2022, 7:45 PM
    I understand that animating insertions/deletions into a
    LazyList
    is still under development, but what's the recommendation for animating insertions/deletions into a regular
    Column
    or
    Row
    ?
    j
    a
    d
    • 4
    • 18
  • r

    Raymond

    07/26/2022, 8:09 PM
    Hi Guys! Any news about composable function references in kotlin?
    m
    • 2
    • 1
  • d

    deviant

    07/27/2022, 10:54 AM
    hey guys is it possible to use
    compose.material
    and
    compose.material3
    in same project (same screen)?
    l
    • 2
    • 1
  • a

    Arkadii Ivanov

    07/27/2022, 10:55 AM
    🔥 https://twitter.com/JorgeCastilloPr/status/1552169372193538049
  • j

    Ji Sungbin

    07/27/2022, 1:18 PM
    Hi, How can I use the
    liveLiterals
    plugin option? When I try to apply it, I get this error: Multiple values are not allowed for plugin option androidx.compose.compiler.plugins.kotlin:liveLiterals.
    freeCompilerArgs += [
            "-P",
            "plugin:androidx.compose.compiler.plugins.kotlin:liveLiterals=false"
    ]
  • j

    jasu

    07/27/2022, 1:35 PM
    I’m using
    compose-hilt-navigation
    and in one of the screens i’m using BackHandler(onBack = someCall). Somecall is not getting called any idea? inshort: back handler is not working
    o
    t
    • 3
    • 8
  • r

    Rafs

    07/27/2022, 5:16 PM
    Do we have any official or decent flow layout libraries in compose? I remember there used to be
    FlowRow/Column
    but they aren’t available anymore.
    p
    • 2
    • 1
  • a

    Ale Stamato

    07/27/2022, 5:17 PM
    Compose 1.2 is stable https://android-developers.googleblog.com/2022/07/jetpack-compose-1-2-is-now-stable.html
  • b

    Benjamin Deroche

    07/27/2022, 7:21 PM
    Are
    ArrowCircleLeft
    and
    ArrowCircleRight
    icons missing from Android Compose? I use all 4 of them (left, top, right, bottom) in my Kotlin Multiplatform app for Android and JVM. Android Studio show no error, the JVM app compile and run just fine, but the Android app fail to compile because I get an unresolved reference for left and right arrows
  • i

    itnoles

    07/27/2022, 8:02 PM
    I like how compose compiler made a huge jump from 1.3.0 beta 1 to 1.3.0 rc 1
  • h

    Harold Scissors

    07/27/2022, 8:28 PM
    Couldn't find an answer by searching,, was
    repeatOnLifecycle
    removed from
    lifecycle-runtime-ktx
    ? I'm looking to solve an issue where we need link
    produceState
    based on lifecycle events within a composable function.
    i
    • 2
    • 2
  • h

    Harold Scissors

    07/27/2022, 11:23 PM
    Somewhat related follow-up question to the above: what would be the best way have a suspend fun called on each
    Lifecycle.State.RESUMED
    ? I tried this which was posted before on similar threads but it seems because
    produceState
    conflates
    value
    , only the first value causes recomposition. So, on the first resume, we see the value, on the second (if it is the same) we see nothing. Ideally, we'd want to see it on every
    RESUMED
    even if it is the same.
  • o

    oianmol

    07/28/2022, 3:51 AM
    Hi Folks! We Android Devs @MutualMobile are back again with a new Pixel-Perfect Compose Project after the Slack android clone, We present #Discord #jetpackcompose clone, It's a but here's a sneak peek. https://github.com/Anmol92verma/DiscordJetpackCompose
    a
    • 2
    • 1
  • t

    Tin Tran

    07/28/2022, 4:34 AM
    Is it a good practice passing
    ModalBottomSheetState
    to ViewModel?
    o
    a
    +4
    • 7
    • 20
  • a

    Ali Khaleqi Yekta

    07/28/2022, 5:46 AM
    message has been deleted
    c
    • 2
    • 1
  • k

    Kazik

    07/28/2022, 6:23 AM
    Hi Guys. Is there any way to detect when bottom sheet is dismissed? For now I subscribe to navController’s current back stack entry flow inside bottom sheet, but it feels like hacky solution.
    LaunchedEffect(Unit) {
      navController.currentBackStackEntryFlow
        .filter { it.destination.route == parentRoute }
        .collect { onClose() }
    }
    j
    • 2
    • 2
  • z

    zt

    07/28/2022, 6:36 AM
    How can I use scroll behavior for a top app bar and also the pull to refresh accompanist library together?
  • a

    Arun Joseph

    07/28/2022, 6:52 AM
    Is there any known issue with
    accompanist-navigation-animation
    and rotation, I observe that the obtained
    viewmodel
    leaks when transitions between screens, when each screen forces certain orientation. Sample code in thread.
    • 1
    • 4
Powered by Linen
Title
a

Arun Joseph

07/28/2022, 6:52 AM
Is there any known issue with
accompanist-navigation-animation
and rotation, I observe that the obtained
viewmodel
leaks when transitions between screens, when each screen forces certain orientation. Sample code in thread.
class AppActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            SampleNavHost()
        }
    }
}

@Composable
fun SampleNavHost() {
    val navController = rememberAnimatedNavController()
    AnimatedNavHost(
        navController = navController,
        startDestination = "ScreenA",
    ) {
        composable("ScreenA") {
            val viewModel: ScreenAViewModel = viewModel()
            val context = LocalContext.current
            LaunchedEffect(key1 = Unit) {
                context.tryFindActivity()?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
            }
            Button(
                onClick = {
                    navController.popBackStack()
                    navController.navigate("ScreenB")
                },
                content = {
                    Text("Navigate to ScreenB")
                }
            )
        }
        composable("ScreenB") {
            val viewModel: ScreenBViewModel = viewModel()
            val context = LocalContext.current
            LaunchedEffect(key1 = Unit) {
                context.tryFindActivity()?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
            }
            Button(
                onClick = {
                    navController.popBackStack()
                    navController.navigate("ScreenA")
                },
                content = {
                    Text("Navigate to ScreenA")
                }
            )
        }
    }
}

class ScreenAViewModel : ViewModel() {
    override fun onCleared() {
        println("onCleared $this")
        super.onCleared()
    }
    init {
        println("onCreated $this")
    }
}

class ScreenBViewModel : ViewModel() {
    override fun onCleared() {
        println("onCleared $this")
        super.onCleared()
    }
    init {
        println("onCreated $this")
    }
}

fun Context.tryFindActivity(): Activity? {
    var context = this
    while (context is ContextWrapper) {
        if (context is Activity) return context
        context = context.baseContext
    }
    return null
}
I get the below when I use just the
NavHost
2022-07-28 08:38:22.523 14687-14687 System.out                                           I  onCreated com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@30e43db
2022-07-28 08:38:25.694 14687-14687 System.out                                           I  onCreated com.tomtom.roadcaptain.home.presentation.ScreenBViewModel@7939130
2022-07-28 08:38:26.428 14687-14687 System.out                                           I  onCleared com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@30e43db
2022-07-28 08:38:45.367 14687-14687 System.out                                           I  onCreated com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@a2852cc
2022-07-28 08:38:46.084 14687-14687 System.out                                           I  onCleared com.tomtom.roadcaptain.home.presentation.ScreenBViewModel@7939130
whereas with
AnimatedNavHost
2022-07-28 08:48:02.868 15669-15669 System.out                                           I  onCreated com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@66faa0b
2022-07-28 08:48:05.696 15669-15669 System.out                                           I  onCreated com.tomtom.roadcaptain.home.presentation.ScreenBViewModel@5b834d9
2022-07-28 08:48:14.797 15669-15669 System.out                                           I  onCreated com.tomtom.roadcaptain.home.presentation.ScreenAViewModel@1ef23a5
I filed bug at https://github.com/google/accompanist/issues/1265
View count: 12