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

    AmrJyniat

    11/24/2021, 12:24 PM
    Is there a way to preview the Icon in
    Icons.Default
    ?
    t
    a
    6 replies · 3 participants
  • j

    joadar

    11/24/2021, 1:21 PM
    Hello guys, do you know how to migrate step by step a BottomNavigationView to Compose? I can’t find any articles about this topic. So far I can’t reuse the fragments from my BottomNavigation because of the new navigation system form Compose. Maybe I am doing it wrongly?
    l
    5 replies · 2 participants
  • z

    Zhelyazko Atanasov

    11/24/2021, 3:10 PM
    Hi, I'm building an app using Compose and some of my Composable elements have a default height (similarly to the Compose Material Buttons). I'm wondering how to create the public API of my composable: 1. Have a
    Modifier
    argument and then add
    .height()
    internally. The negative side is that there won't be a way to change the composable's height.
    @Composable
    fun MyComposable(
        modifier: Modifier = Modifier
    ) {
        Surface(modifier = modifier.height(24.dp)
    }
    2. Have a default value of the
    modifier
    argument that specifies the height. The downside is that if you want to pass a modifier to the composable, you'd have to add the
    height
    one as well:
    @Composable
    fun MyComposable(
        modifier: Modifier = Modifier.height(24.dp)
    ) {
        Surface(modifier = modifier
    }
    In my particular case the composable will always be displayed in the default height, but I'm asking what's the generally preferred way to do this for composables that may vary in size, but we still want to have some default/min height
    o
    a
    4 replies · 3 participants
  • j

    jannis

    11/24/2021, 3:45 PM
    Is there any way to remove the build-in padding from a
    TextField
    without using the
    BasicTextField
    ? It doesn't bother me that much, but if the
    TextField
    scrolls you get a white gap at the top/bottom of the
    TextField
    😅
    l
    z
    4 replies · 3 participants
  • t

    Tgo1014

    11/24/2021, 4:03 PM
    Any idea how could I implement something like a
    ContentLoadinProgressBar
    in compose?
    d
    3 replies · 2 participants
  • a

    Alexa_Gal

    11/24/2021, 4:20 PM
    hi guys, do you know how can i detect when the
    back
    button has been pressed? i tried with all the
    KeyboardActions
    but none of them are triggered when i press that button 😕 (using BasicTextField)
    r
    8 replies · 2 participants
  • s

    Stylianos Gakis

    11/24/2021, 5:02 PM
    I am experiencing a weird case of a
    <androidx.compose.ui.platform.ComposeView>
    not showing its contents specifically in Android 9 (API 28) until I put my finger down in its area and then the items show. More details and a video 🎥 in thread 🧵
    a
    z
    9 replies · 3 participants
  • f

    Filip Wiesner

    11/24/2021, 5:13 PM
    Why did I just get Rick-rolled by "Advanced Jetpack Compose" button at the top? 😄 Who did this?
    :parrot-upside-down: 2
    s
    4 replies · 2 participants
  • h

    Hachemi Hamadi

    11/24/2021, 5:34 PM
    Hello, Recently i added Google Maps with Compose using AndroidView composable. But the map gestures aren't working at all (zoom / rotate ... ) Although i enabled then using the uisettings. Any idea how to make them work ?
    c
    1 reply · 2 participants
  • b

    Brian Donovan

    11/24/2021, 6:08 PM
    Is my line 77 wrong?
    l
    a
    2 replies · 3 participants
  • e

    escodro

    11/24/2021, 6:47 PM
    Hello, everyone! Is there any support in
    TextField
    similar to Extract UI Mode (fullscreen) for
    EditText
    ? I have a screen with some
    EditText
    and it does not look work well when the device is on landscape. Any ideas? Thanks a lot!
    z
    2 replies · 2 participants
  • s

    Stylianos Gakis

    11/24/2021, 10:51 PM
    Don’t really have a minimum repro atm, but wanted to ask if anyone else has seen this before. When using a
    androidx.compose.ui.platform.ComposeView
    in xml (in a fragment, with ConstraintLayout being the parent), I am getting a crash
    Cannot add views to ComposeView; only Compose content is supported
    error when I am trying to work with having an exit transition on the fragment that contains said ComposeView. The code that breaks this is something like:
    supportFragmentManager
        .findFragmentByTag("someTag")
        ?.exitTransition = MaterialSharedAxis(SHARED_AXIS, true)
    Full stack trace in thread🧵
    a
    2 replies · 2 participants
  • c

    Colton Idle

    11/24/2021, 11:54 PM
    I'm having a bit of analysis paralysis at the moment on how to refactor a MyCompanyBottomBar into an isolated component. Code in thread, but mostly asking what you think the right refactor would be.
    z
    2 replies · 2 participants
  • l

    lesincs

    11/25/2021, 12:03 AM
    How to make
    item
    of
    LazyColumn
    fill the reset of the height? See thread.
    c
    a
    3 replies · 3 participants
  • r

    rsktash

    11/25/2021, 1:54 AM
    Hi is there a team working on jetpack compose beta of Mobile sdk ? https://developers.google.com/admob/flutter/quick-start
    1 reply · 1 participant
  • c

    Colton Idle

    11/25/2021, 3:38 AM
    Compose testing docs say:
    // Test rules and transitive dependencies:
    androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version")
    // Needed for createComposeRule, but not createAndroidComposeRule:
    debugImplementation("androidx.compose.ui:ui-test-manifest:$compose_version")
    Should the
    debugImpl
    actually be
    androidTestImpl
    ?
    i
    1 reply · 2 participants
  • t

    Tim Malseed

    11/25/2021, 3:48 AM
    Edit: Solved by disabling ‘parallel run’ on tests in AS Hey all, another Instrumented Testing crash I could use some help with.. It seems that I get this crash depending on the order that my tests are executed.. Stacktrace:
    java.lang.NullPointerException
            at androidx.compose.ui.layout.SubcomposeLayoutState.disposeCurrentNodes$ui_release(SubcomposeLayout.kt:386)
    ...
    z
    23 replies · 2 participants
  • a

    Alex C

    11/25/2021, 4:33 AM
    Anyone know how I can debug the onClick event? Somehow I couldn't get the button click event triggered
    @Composable
    fun TestClick() {
        Box(modifier = Modifier
            .background(Color.Red)
            .padding(40.dp)
        ) {
            Column(
                modifier = Modifier
                    .background(Color.Green)
                    .clickable { Log.d("Test", "Column onClick") }
                    .padding(40.dp)
            ) {
                Button(onClick = { Log.d("Test", "Button onClick") }) {
                    Text(text = "Click", fontSize = 24.sp)
                }
            }
        }
    }
    k
    d
    7 replies · 3 participants
  • z

    Zoltan Demant

    11/25/2021, 4:56 AM
    Im having some animation issues, my intention is to slide in a piece of content over the current; but if the piece is running animations itself, the sliding animation breaks. 🧵👀
    c
    3 replies · 2 participants
  • c

    Clament John

    11/25/2021, 5:46 AM
    ✅ How to have two `Button`s in a
    Row
    that take up equal widths?
    Row(
        modifier = Modifier.fillMaxWidth()
    ) {
        Button(
            onClick = { /*TODO*/ },
        ) {
            Text("SELECT ADDRESS")
        }
        Spacer(modifier = Modifier.width(12.dp))
        Button(
            onClick = { /*TODO*/ }
        ) {
            Text("ADD ADDRESS")
        }
    }
    Demo image in the thread
    k
    4 replies · 2 participants
  • s

    Steffen Funke

    11/25/2021, 6:40 AM
    Hello, is there any best practice to return a
    State<T>
    AND a
    StateFlow<T>
    , backed by the same changing data, at the same time from an Android ViewModel? I have some View based UI which consumes the data as
    StateFlow
    , and some Compose UI, which would need
    State
    . And ideally I don’t want to rewrite the Compose part to
    collectAsState()
    , rather just have it consume State directly from ViewModel (e.g. hide the implementation details inside ViewModel):
    Inside ViewModel:
        // is consumed by View based UI
        protected val _itemsFlow = MutableStateFlow<List<Item>>(emptyList())
        val itemsFlow = _itemsFlow.asStateFlow()
    
        // should be consumed by Compose UI
        val items: State<List<Item>> = itemsFlow.collectAsState() // not working bc. of missing @Composable scope
        val items: State<List<Item>> = itemsFlow.collectAsState(emptyList()) // also not working
    z
    j
    9 replies · 3 participants
  • r

    rajesh

    11/25/2021, 10:33 AM
    I've a ViewModel (say
    ProfileViewModel
    ) that has a function that fetch posts (paging data) of given user. I've 2 composables namely
    ProfileView
    and
    DetailedPostView
    I need to use same function to load posts with cached value in viewmodel, but when I navigate to detailed screen, it re-fetch the data instead of cached value. How to avoid it? code is in thread.
    a
    s
    +1
    10 replies · 4 participants
  • n

    Napa Ram

    11/25/2021, 12:15 PM
    Hi Everyone i migrated one of my module into compose and removed unused dependency after that also all unused library related to appcompact, fragment are showing inside apk analyser can anyone got same issue as i attach screenshot also #android
    c
    4 replies · 2 participants
  • z

    Zoltan Demant

    11/25/2021, 1:22 PM
    Is it possible to reduce the number of recompositions happening for a subset of a composable? 🧵👀
    z
    3 replies · 2 participants
  • c

    Cicero

    11/25/2021, 1:57 PM
    How do you guys are calling the file in between the UI and the ViewModel? I'm calling it "Bridge" but even then it feels okish, I feel like there is a name for it, and appropriate term for it that I'm missing. So, ViewUI(parameters from the bridge), ViewBridge(viewModel), ViewModel
    h
    n
    +2
    10 replies · 5 participants
  • a

    allan.conda

    11/25/2021, 2:41 PM
    Snackbar in compose testing hides the button I want to press. Anyone know what can I do in this case?
    z
    3 replies · 2 participants
  • l

    Lukasz Kalnik

    11/25/2021, 3:39 PM
    What is the recommended way to attach a Composable to a StateFlow from a ViewModel? I have a ViewModel which exposes an alert dialog state:
    data class NameDialogState(val show: Boolean, val nameFieldValue: TextFieldValue)
    val nameDialogState: StateFlow<NameDialogState>
    The composable has a parameter for its UI state:
    @Composable
    fun NameDialog(uiState: State<NameDialogState>) {
        if (uiState.value.show) {
            AlertDialog(
                // ...
                text = TextField(value = uiState.value.nameFieldValue)
            )
            // ...
        }
    }
    Inside the Fragment, the composable for the dialog takes the flow with
    collectAsState()
    val uiState = viewModel.nameDialogState.collectAsState()
    
    setContent {
        NameDialog(uiState = uiState)
    }
    This works, but I wonder if it is possible to get rid of the
    State<*>
    in the composable and use
    NameDialogState
    directly, like this:
    @Composable
    fun NameDialog(uiState: NameDialogState)
    All Google examples recommend injecting viewmodel directly into composable, which doesn't seem good architecture... I would like to keep the composables as "stupid" as possible.
    a
    b
    11 replies · 3 participants
  • l

    Lukasz Kalnik

    11/25/2021, 3:45 PM
    Currently I have the problem that the preview doesn't work. For the preview I create a fake uiState:
    @Preview
    @Composable
    fun NameDialogPreview() {
        val uiState = mutableStateOf(
            NameDialogState(
                show = true, 
                nameFieldValue = TextFieldValue(text = "My name")
            )
        )
        NameDialog(uiState = uiState)
    }
    But it doesn't show anything.
    a
    2 replies · 2 participants
  • y

    YASAN

    11/25/2021, 4:20 PM
    I have been unable to update my 
    navigation-compose
     past 
    2.4.0-alpha10
    . All versions after that crash for me and the log isn't clear.
    2.4.0-beta02
    throws this:
    java.lang.ClassCastException: java.util.LinkedHashSet cannot be cast to java.util.List
            at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost$lambda-3(AnimatedNavHost.kt:388)
            at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:165)
            at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:91)
            at yasan.space.mnml.ai.launcher.ui.navigation.NavGraphKt$NavGraph$1.invoke(NavGraph.kt:76)
            at yasan.space.mnml.ai.launcher.ui.navigation.NavGraphKt$NavGraph$1.invoke(NavGraph.kt:75)
    a
    4 replies · 2 participants
  • z

    Zoltan Demant

    11/25/2021, 4:37 PM
    My
    transition.AnimatedContent
    block sometimes takes 500-1000 ms to execute. Is this a bug, or am I doing something wrong? 🧵👀
    z
    4 replies · 2 participants
Powered by Linen
Title
z

Zoltan Demant

11/25/2021, 4:37 PM
My
transition.AnimatedContent
block sometimes takes 500-1000 ms to execute. Is this a bug, or am I doing something wrong? 🧵👀
This is my code. I can verify that all other code runs <10 ms; its specifically the invokation of
AnimatedContent
itself which is super-slow, and it happens when the content passed in has a lot of data, e.g. in this case a list with ~300 items.
val transition = stack
    .last()
    .let { top ->
        updateTransition(
            targetState = BackStackState(
                key = Compatible.findKey(top),
                content = top,
                size = size
            ),
            label = null
        )
    }

transition.AnimatedContent(
    contentKey = BackStackState::key,
    transitionSpec = {
        contentTransform(
            difference = targetState.size - initialState.size
        )
    },
    content = { state ->
        stateKeeper.SavedState(
            key = state.key,
            content = {
                Render(state.content)
            }
        )
    }
)

private fun contentTransform(
    difference: Int
): ContentTransform {
    return when {
        difference >= 0 -> {
            ContentTransform(
                targetContentEnter = slideInVertically(
                    initialOffsetY = { height -> height },
                    animationSpec = SlideSpec
                ),
                initialContentExit = fadeOut(
                    animationSpec = FadeSpec
                ),
                targetContentZIndex = 1f
            )
        }
        else -> {
            ContentTransform(
                targetContentEnter = fadeIn(
                    animationSpec = FadeSpec
                ),
                initialContentExit = slideOutVertically(
                    targetOffsetY = { height -> height },
                    animationSpec = SlideSpec,
                )
            )
        }
    }
}

@Immutable
private data class BackStackState(
    val content: Any,
    val key: String,
    val size: Int
)
Removing
content
from targetState fixes it, but how am I then to know which content to render in the content block of AnimatedContent?
z

Zach Klippenstein (he/him) [MOD]

11/25/2021, 7:53 PM
Does the problem scale with the size of the list? Does your key derivation function walk the whole list?
z

Zoltan Demant

11/26/2021, 6:31 AM
Yep, it seems to scale with how complex the screen itself is. The key is derived only from the screen itself, e.g. in this case my content is something like HistoryScreen (key=typeOf<HistoryScreen>) which in turn has the large list. Update: Its the hashCode function on my screen taking ~100 ms, and then being called a lot during the animation. I can work around it by wrapping the content in a
() -> Any
block. Not sure if thats a good idea in practice, or is it? Im really looking to transition screens from A -> B, rather than animate whenever A/B themselves change.
View count: 1