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

    Tin Tran

    02/18/2022, 3:21 AM
    Hi. Does anyone having
    java.lang.IllegalStateException: pending composition has not been applied
    with compose 1.1.0? . Full stack trace in 🧵
    c
    a
    a
    • 4
    • 10
  • t

    Tin Tran

    02/18/2022, 3:24 AM
    And this starting to come back again after upgrading to navigation compose from 2.4.0-alpha09 to 2.4.1
    java.lang.IllegalStateException: You cannot access the NavBackStackEntry's ViewModels after the NavBackStackEntry is destroyed.
    i
    • 2
    • 2
  • t

    Tin Tran

    02/18/2022, 5:45 AM
    On compose 1.2.0-alpha03 writing this give me a compilation error saying
    @Composable invocations can only happen from the context of a @Composable function
    . It wasn’t the case in 1.1.0. Is this expected?
    buildAnnotatedString{
        withStyle(SpanStyle(....)){
            append(" • ${stringResource(key = "key", defaultValue = "Open now")}") //won't compile
        }
    }
    buildAnnotatedString {
        append(stringResource(key = "key", defaultValue ="Work time")) //compile
    }
    j
    s
    o
    • 4
    • 5
  • l

    Lance Gao

    02/18/2022, 6:27 AM
    Hi, how to update composable when a list changes by
    rember { mutableStateOf(mutableListOf<Int>())}
    ?
    m
    c
    • 3
    • 10
  • s

    Saurabh Khare

    02/18/2022, 7:57 AM
    Hi, My testing need id for compose view, does anyone have idea how we can add id to compose view
    c
    m
    • 3
    • 4
  • e

    elye

    02/18/2022, 8:33 AM
    Hi All, do you know if the
    UpdateTransition
    animation being interupted half way, does it still retain its velocity for it’s subsequent animation (that interrupt it)? I think it should, as that’s what
    AnimateAsState
    and
    Animatable
    behave like. For more context, I provide a full code and some GIF animation to illustrate this clearer in https://stackoverflow.com/questions/71170430/will-updatetransition-animation-maintain-its-running-velocity-when-if-being-chan
    d
    • 2
    • 12
  • g

    Gerardo Ernesto Rodriguez Navar

    02/18/2022, 10:01 AM
    My Espresso tests started flaking when I added the
    @get:Rule
    val composeTestRule = createAndroidComposeRule<MainActivity>()
    • 1
    • 4
  • l

    linus muema

    02/18/2022, 10:46 AM
    Hi guys, I have been working on a form library for Jetpack compose and I have a first release. It would be awesome if you could give it a try and any feedback would be of great help.
    c
    • 2
    • 1
  • l

    Lokik Soni

    02/18/2022, 11:13 AM
    Hi all, I am working with Jetpack compose and not able to use ViewModel properly. Here is problem: I Know we can not @inject a class inside @composable function so I decided to @Inject BatteryBroadcast class in MainActivity and pass data from that class to the ViewModel.
    @AndroidEntryPoint
    class MainActivity : ComponentActivity() {
    
        @Inject
        lateinit var batteryBroadcast: BatteryBroadcast
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            
            setContent {
                BatteryAlarmGoldTheme {
    
                    val homeViewModel = hiltViewModel<HomeViewModel>()
                    lifecycle.addObserver(batteryBroadcast)
                    homeViewModel.setBatteryProfileData(batteryBroadcast.dataFlow)
    
                    // A surface container using the 'background' color from the theme
                    Surface(color = MaterialTheme.colors.background) {
                        BatteryAlarmGoldApp()
                    }
                }
            }
        }
    }
    Now I want to use the same ViewModel in my compose to access that data. I am using NavHost for that currently
    fun NavGraphBuilder.homeNavGraph(
        navController: NavHostController
    ) {
        navigation(startDestination = Screen.HomeScreen.route, route = HOME_ROUTE) {
            composable(Screen.HomeScreen.route) {
                val homeBackStackEntry = remember { navController.getBackStackEntry(HOME_ROUTE) }
                val homeViewModel: HomeViewModel = hiltViewModel(homeBackStackEntry)
    
                HomeScreen(
                    navController = navController,
                    viewModel = homeViewModel
                )
            }
            composable(Screen.SelectRingtoneScreen.route) {
                val homeBackStackEntry = remember { navController.getBackStackEntry(HOME_ROUTE) }
                val homeViewModel: HomeViewModel = hiltViewModel(homeBackStackEntry)
    
                RingtoneScreen(
                    viewModel = homeViewModel
                )
            }
        }
    }
    Or there is any batter solution to achieve the same please suggest me.
    m
    • 2
    • 2
  • m

    Mike Speed

    02/18/2022, 11:16 AM
    Hi all, I have a very strange problem with my
    LazyColumn
    . I am updating the menuList
    State
    in the ViewModel, the view recomposes but the debugger gets to LazyColumn and then stops, which means the children aren’t redrawn with the new data. Any ideas why? Thanks! MyView:
    val menuList = viewModel.menuData.observeAsState()
    
    LazyColumn() {
                    items(menuList.value.size) { i->
                        MenuItem(menuList.value[i])
                    }
    }
    MyViewModel:
    private var menu: MenuUiState? = null
    val menuData: SingleLiveEvent<MenuUiState> by lazy { SingleLiveEvent() }
    
    // ...
    menu?.sections?.forEach {
        //update menu properties here
    }
    menuData.value = menu?.copy()
    l
    c
    a
    • 4
    • 6
  • k

    Kamesh Yadav

    02/18/2022, 12:52 PM
    I am having an issue with scoping my ViewModel to nested graph, the ViewModel is getting initilalized again, but the ViewModel scoped with screen composable survives.
    • 1
    • 2
  • m

    Mjahangiry75

    02/18/2022, 2:26 PM
    as we know the
    SideEffect
    gets triggered on every recomposition so it works fine in the code below(triggered only once when
    MainScreen
    starts composition), but if I uncomment the
    LaunchedEffect
    the
    SideEffect
    block will get triggered whenever the
    count
    state changes, while if I comment the
    LaunchedEffect
    block it will not. why?
    a
    a
    +3
    • 6
    • 10
  • z

    Zoltan Demant

    02/18/2022, 3:18 PM
    Is it possible to disable the text selection handles that show up in
    TextFields
    after a long press?
    DisableSelection
    exists and works for
    Text
    , but not
    TextField
    .
    j
    z
    • 3
    • 5
  • v

    Vsevolod Kaganovych

    02/18/2022, 4:10 PM
    I tried to search for the answer but couldn't find it. How can I run some method every time I enter the screen for one time?
    b
    a
    • 3
    • 5
  • d

    dimsuz

    02/18/2022, 4:12 PM
    when I use
    BottomSheetScaffold
    it's
    content
    seems to "steal" clicks even if it's empty. View below this scaffold doesn't receive them. is there an option to make them pass through
    content
    ?
    c
    m
    • 3
    • 4
  • d

    David Corrado

    02/18/2022, 5:23 PM
    Is there any Android Talkback engineers on here. I have a couple really big bugs IMO. Wanted to ensure the engineers got it. I emailed disability-support@google.com and they said they were looking into it. But wanted to also try here. In the comments I'll leave stackoverflow posts with videos and descriptions. LMK if there is a better place to communicate this or if the email is the best.
    k
    c
    • 3
    • 6
  • a

    aoriani

    02/18/2022, 7:34 PM
    Is it possible to prevent an AndroidView from recomposing if a parent node recomposes? I have an AndroidView wrapping a camera2 PreviewView to display the camera feed. When a parent node recomposes I see that the PreviewView blinks black, which tells me that the view is being recreated.
    a
    a
    • 3
    • 6
  • t

    theapache64

    02/19/2022, 1:04 PM
    What’s the actual purpose of
    consumePositionChange()
    (link)? 🤔
    👍 1
    a
    • 2
    • 3
  • a

    Alexander Maryanovsky

    02/19/2022, 2:29 PM
    There seems to be a general problem with Compose in that a lot of times it exposes state as a regular type, and its `State`fulness is implicit. For example, compose-desktop has
    WindowState.position
    of type
    WindowPosition
    and
    WindowStateImpl
    implements it as
    override var position by mutableStateOf(position)
    but from just looking at the
    WindowState
    interface, there’s no way for you to know that
    position
    can be observed. Wouldn’t it better if the type of
    WindowState.position
    was
    MutableState<WindowPosition>
    ?
    🇳🇴 2
    a
    • 2
    • 67
  • t

    Tolriq

    02/19/2022, 3:37 PM
    Starting to become mad at debugging state recomposition. I'm using `
    val playlistEntriesItems = remember(playlistEntries) {
        Log.e("AAA", "Update entries")
        playlistEntries.toMutableStateList()
    }
    Then use that state list in a LazyColumn. All works correctly and change to items order properly triggers recomposition. If that function is called again with a new playlistEntries the state is properly updated, but then the LazyColumn no more react on the changes. Am I missing something obvious?
    a
    • 2
    • 12
  • l

    Landry Norris

    02/19/2022, 6:03 PM
    I'm evaluating switching existing code from the Android View library to compose. One feature of the app was implemented in C (now kotlin/native after I refactored it) and writes raw RGBA data to a surface using the NDK's ANativeWindow. Does Compose have something equivalent, or would I need to use platform interop with a TextureView like I have now?
    r
    • 2
    • 4
  • m

    Mohammad Sianaki

    02/20/2022, 11:35 AM
    Hi guys I want to show a timer in items of a
    LazyRow
    :
    val timerState = produceState(
        initialValue = TimerCounter(0L, 0L, 0L),
        key1 = product.id,
        producer = {
            withContext(Dispatchers.Default) {
                val endTimeInMillis =
                    product.productDeal?.dealEndTime?.toTimeInMillis() ?: return@withContext
                val endTimeInSeconds = endTimeInMillis / 1000
                while (isActive) {
                    val currentTimeInSecond = System.currentTimeMillis() / 1000
                    if (endTimeInSeconds < currentTimeInSecond) {
                        value = TimerCounter(0L, 0L, 0L)
                        return@withContext
                    }
                    var reminders: Long
                    val durationInSeconds = endTimeInSeconds - currentTimeInSecond
                    val remainDays = durationInSeconds / DAY_IN_SECONDS
                    reminders = durationInSeconds % DAY_IN_SECONDS
                    val remainHours = ((reminders / HOURS_IN_SECONDS)) + (remainDays * 24)
                    reminders %= HOURS_IN_SECONDS
                    val remainMinutes = reminders / MINUTE_IN_SECOND
                    val remainSecond = reminders % MINUTE_IN_SECOND
                    value = TimerCounter(remainHours, remainMinutes, remainSecond)
                    delay(1000)
                }
            }
        }
    )
    the above code is in composable which shows list item. is this a right approach? in case not, which
    Effect
    should?
    c
    • 2
    • 1
  • m

    Marcin Wisniowski

    02/20/2022, 12:09 PM
    Why is Compose's
    Card
    default elevation different from
    CardView
    ? In a mixed app, this makes the cards looks different, which looks especially bad in layouts that have both.
    ✅ 1
    a
    • 2
    • 2
  • b

    Bradleycorn

    02/20/2022, 11:20 PM
    How can I get a string resource in an instrumented test without using
    createAndroidComposeRule()
    ? I do not want or need to load my app’s main activity. That would load all of my application content, and this is a Unit Test for a single composable. But I need to get a string resource to test with.
    a
    a
    • 3
    • 4
  • b

    brabo-hi

    02/21/2022, 1:54 AM
    Hi all, i have two custom SurfaceView representing 2 videos
    Row {
            AndroidView(factory = { context -> CustomView(context, "A") }, update = {})
            AndroidView(factory = { context -> CustomView(context, "B") }, update = {})
            Button(onClick = { swapViews() }) {
                Text(text = "Swap view")
            }
        }
    swapViews()
    should swap both views. but it looks like i have to manually remove each view from parent. Should i call
    removeView()
    in each
    update{}
    ? here is the error i am getting
    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.`
    a
    • 2
    • 18
  • m

    Mehmet Peker

    02/21/2022, 2:02 AM
    I have an app written fully with compose,i working about how to implement native ads in compose but i cant.Someone can help me?
    a
    p
    • 3
    • 15
  • r

    Rene Win

    02/21/2022, 7:20 AM
    Hello, im trying to have a AnimatedVisiblity composable inside a Box, which is nested inside a Column like this:
    Column {
            Box {
               AnimatedVisibility(visible = true) {
                   Text("test")
               }
            }
        }
    This results into an error:
    'fun ColumnScope.AnimatedVisibility(visible: Boolean, modifier: Modifier = ..., enter: EnterTransition = ..., exit: ExitTransition = ..., label: String = ..., content: AnimatedVisibilityScope.() -> Unit): Unit' can't be called in this context by implicit receiver. Use the explicit one if necessary
    The provided fix from IDE is to annotate the AnimatedVisibility with
    Column {
            Box {
                this@Column.AnimatedVisibility(visible = true) {
                    Text("test")
                }
            }
        }
    Then everything works fine. The question is why is this necessary? Is this the correct fix? Why cant I call this composable like every other composable?
    a
    a
    • 3
    • 3
  • h

    Hussain Saad

    02/21/2022, 10:11 AM
    What android developers actually want in Compose? -Live Relaoding (such a haslte building app again and again) -Drag , drop code creation (similar to Swift UI for less time spent on ui through code) -Need Attributes and Palette Window support for composables as well with drag drop -All recycler view features in Column, Row Widgets
    z
    • 2
    • 1
  • m

    Mohammad Sianaki

    02/21/2022, 1:23 PM
    Has anyone used
    contentType
    in
    LazyColumn
    ? I’m trying to implement a multi type List, but I’m facing serious performance issue
    m
    s
    • 3
    • 5
  • g

    Guilherme Delgado

    02/21/2022, 1:36 PM
    Hello. I’m using
    PointerInputScope.detectTransformGestures
    to compute and apply some transformations to a
    composable
    but I need to know when the user stops touching the screen. I was thinking in combining it with
    PointerInputScope.detectDragGestures
    and listen for
    onDragEnd
    but only one is used. 1 - Is is possibile to combine “Gestures”? 2 - What’s the best approach for what I want? thx.
    a
    • 2
    • 3
Powered by Linen
Title
g

Guilherme Delgado

02/21/2022, 1:36 PM
Hello. I’m using
PointerInputScope.detectTransformGestures
to compute and apply some transformations to a
composable
but I need to know when the user stops touching the screen. I was thinking in combining it with
PointerInputScope.detectDragGestures
and listen for
onDragEnd
but only one is used. 1 - Is is possibile to combine “Gestures”? 2 - What’s the best approach for what I want? thx.
a

Albert Chang

02/21/2022, 3:44 PM
The best approach is to create your version of
detectTransformGestures
.
👍 1
g

Guilherme Delgado

02/21/2022, 4:34 PM
Yup that’s what I ended up doing
suspend fun PointerInputScope.detectTransformGestures(
    panZoomLock: Boolean = false,
    onEvent: (event: PointerEvent) -> Unit, <<<<<<<<<<<<<<<<<<<<<<<<<
    onGesture: (centroid: Offset, pan: Offset, zoom: Float, rotation: Float) -> Unit
) { ... }
View count: 7