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

    Paul Woitaschek

    08/03/2021, 4:56 AM
    Afaik compose is compatible with kotlin 1.5.10. What if a library is compiled against 1.5.20. Will that cause an incompatibility?
    i
    e
    +2
    • 5
    • 14
  • j

    Joey

    08/03/2021, 7:48 AM
    I have a TextField with
    singleLine = true
    and
    maxLines = 1
    , but in the emulator I can still press keys like ENTER to create newlines, can I somehow prevent that? Or should I just filter stuff like
    \n
    in the valuechange?
    ➕ 1
    d
    • 2
    • 2
  • b

    Benyam Seifu

    08/03/2021, 8:20 AM
    Is it possible to move Floating Action Button above keyboard when using Scaffold?
    t
    • 2
    • 2
  • a

    Albert Francis

    08/03/2021, 8:59 AM
    Hey, i'm trying to do something really simple but having some problems. i have a Row(text,icon) and the text can be super long so i made it
    maxLines = 1
    , and
    overflow = TextOverflow.Ellipsis
    so it can be like. "Lorem ipsum ..." ⬆️ but if i change the
    overflow
    to
    Ellipsis
    the text takes the whole row and it becomes -> "Lorem ipsum ..." without the icon i tried
    inlineContent
    also but that simple thing i couldn't achive anyone has idea?
    ✅ 1
    d
    c
    • 3
    • 5
  • l

    lhwdev

    08/03/2021, 9:22 AM
    How can I remove a Composable function entirely from UI Tree without losing state so that it does not visible, take spaces, consume events etc.? When I write like
    if(someState) Content()
    , the internal states may fly away. (such as value remembered by
    remember {}
    ) Generally speaking, can I prevent emitting the nodes? (Maybe linking to another composition with wrapper Applier which conditionally delegates to parent applier..? - this would overkill)
    👍 1
    y
    • 2
    • 3
  • v

    Vojtech Hrdina

    08/03/2021, 9:35 AM
    Hi, did anyone tried compose on wear os? We are creating new app and we are not sure if we can already start with compose or use xml. It looks like there are some wear composable components but I wasn’t able to find BoxInsetLayout and other components specific to wear os. https://developer.android.com/jetpack/androidx/releases/wear-compose
    m
    t
    j
    • 4
    • 18
  • n

    Nacho Ruiz Martin

    08/03/2021, 9:50 AM
    SOLVED Hey 👋 Is it possible to fully clear the backstack using navigation component on compose? If I set the destination at the bottom of the stack with
    inclusive = true
    I’m getting the following exception:
    androidx.navigation.NavGraph cannot be cast to androidx.navigation.compose.ComposeNavigator$Destination
    The use case is a user that signs out, so I want to clear the whole backstack and then navigate to the login screen.
    t
    • 2
    • 4
  • l

    loloof64

    08/03/2021, 12:12 PM
    Hi 👋. Let's say I've have a complex object I want to persist even if the screen is rotated as state: should I use
    ViewModel
    or
    remeberSaveable
    ? Which is best practice ?
    a
    c
    • 3
    • 7
  • a

    Akram Bensalem

    08/03/2021, 12:55 PM
    Please I need help!!! I have problem with rotating and draging 😢 Like you see in the video When I insert image and draging it without rotate it (it's works fine ✅) But if I rotate the image and try to drag it It drags to the wrong sens ❌❌❌ Which is not what it suppose to drag !!! Any one have an idea how to fix it ?!
    20210803_134934.mp4
    ❓ 1
    c
    • 2
    • 2
  • l

    loloof64

    08/03/2021, 1:53 PM
    Is it fine to use two different kinds of
    ViewModel
    for the same
    Composable
    ? This way I will have more granularity.
    c
    • 2
    • 7
  • c

    Colton Idle

    08/03/2021, 2:18 PM
    What's the gist for dealing with keyboard covering text inputs in a full compose app? If I have a screen that is not scrollable and it just contains a logo at the top and two text fields, but the keyboard covers the second text field, what paths forward do I have? 1. Is windowSoftInputMode still recommended in a full compose app? 2. Should I just make the entire page scrollable? Even though requirements say the page shouldn't scroll. 3. Can I only make the text inputs scrollable (wrap in a scrollable column) to make sure the keyboard doesn't cover. 4. Something else I missed? I initially was going to reach for windowSoftInputMode, but that always seemed fishy to me. Curious if there's a "proper" way forward with compose.
    👀 3
    t
    c
    +4
    • 7
    • 14
  • n

    nglauber

    08/03/2021, 3:21 PM
    Do I have to do something special to close an
    AlertDialog
    pressing back key or clicking outside? I saw the
    properties
    parameter receives an
    DialogProperties
    object which has these properties (
    dismissOnBackPress
    and
    dismissOnClickOutside
    ) set to true by default. But looks like it’s not working 😕
    m
    • 2
    • 3
  • j

    Jason Inbody

    08/03/2021, 5:04 PM
    Is there list of icons to browse for jetpack compose?
    n
    r
    • 3
    • 2
  • r

    robnik

    08/03/2021, 5:10 PM
    I'm trying to use bottom nav and multiple back stacks. I can jump between tabs/stacks fine, but if I tap the icon for the current tab, and I'm not at the "root" of that tab, I go to blank screen. I have no clue why. Anyone seen this?
    i
    p
    • 3
    • 6
  • m

    Marko Novakovic

    08/03/2021, 5:37 PM
    I have navigation problem. app has 3 screens 1st -> list of items 2nd -> item details 3rd -> gallery of item images I use compose navigation component version
    2.4.0-alpha05
    and am navigating from 1st to 2nd screen like this:
    navController.navigate("$route/${id.value}")
    and routes are defined like so:
    @JvmInline
    value class Routes(val route: String) {
        companion object {
            val Home = Routes("home")
            val ItemDetails = Routes("item_details/{id}")
            val ItemGallery = Routes("item_gallery")
        }
    }
    I access that
    id
    parameter inside
    ViewModel
    savedStateHandle.get<String>(ARG_ITEM_ID) // ARG_ITEM_ID = "id", same as route arg
    when I go from 1st screen, list of items, to 2nd, details, it works fine BUT when I go from details to gallery and press system back button
    ARG_ITEM_ID
    is
    null
    . it works fine with navigation version
    2.4.0-alpha04
    i
    • 2
    • 30
  • t

    Tiago Taraczuk

    08/03/2021, 7:09 PM
    How can I get the selected text from the
    SelectionContainer
    ?
    :jetpack-compose: 3
    👆 2
    r
    a
    • 3
    • 2
  • k

    Kurt Renzo Acosta

    08/03/2021, 8:02 PM
    How do you usually handle initial null values for states? In the old way, I have a
    Flow<T>
    then I just observe it and wait for the initial value before I update the UI. Now, I’m trying to consume it and it always needs an initial value. I tried to do
    .collectAsState(initial = null)
    but then it makes it nullable and I have to perform null checking on every flow. Is there a better practice around this? I’d like to have
    Flow<T>
    rather than
    Flow<T?>
    . Thanks in advance!
    d
    m
    +3
    • 6
    • 14
  • c

    Colton Idle

    08/03/2021, 9:39 PM
    I have a screen with a viewPager from accompanist. One thing that I'm having trouble with is syncing my viewModel.currentPage and rememberPagerState.currentPage, and remembered that one of the points of compose is single source of truth.
    @Composable
    fun SignUpScreen(
        viewModel: SignUpViewModel = hiltViewModel()
    ) {
        val pagerState = rememberPagerState(5)
    In order to have a single source of truth, should I just move
    val pagerState = rememberPagerState(5)
    into my ViewModel?
    ➕ 2
    s
    a
    +2
    • 5
    • 17
  • u

    ursus

    08/04/2021, 12:50 AM
    I have a 3rd party sdk which provides a Fragment subclass I cannot change. Can I somehow wrap it in
    AndroidView
    and make all the fragment lifecycle work? (Since they don't provide a View)
    e
    i
    c
    • 4
    • 12
  • c

    Colton Idle

    08/04/2021, 1:12 AM
    I have a problem with what I thought would be a simple example I tried to write up for compose. If you are well versed in mutableStateListOf I could use your help. Code in thread.
    n
    a
    • 3
    • 18
  • b

    Berkeli Alashov

    08/04/2021, 3:04 AM
    Is there a way to have a special
    BackHandler
    that consumes back calls before the inner most composable? My use case is I have a
    BottomSheetScaffold
    at the root of my app (Theme>BottomSheet>Home>NavHost) and I want to close the sheet on back clicks. But BackHandler defined in BottomSheet doesn't get invoked until all back handlers deeper in the tree are used (in my case, NavHost consumes before BottomSheet, until the first destination is reached / nav stack cleared).
    ➕ 1
    e
    i
    +2
    • 5
    • 23
  • e

    eygraber

    08/04/2021, 3:17 AM
    Is there anything special I need to do to prevent a non-state parameter to a composable function from messing with recomposition/skipping? For example:
    @Composable
    fun Parent(state: State, eventEmitter: EventEmitter<Event>)
    eventEmitter
    will always be the same instance for a given composition, and uses an identity based
    equals
    and
    hashCode
    . Is there anything else that I need to do? Note that I can't use
    CompositionLocal
    here because a lot of the events I need to emit occur in non `@Composable`lambdas (e.g.
    onClick
    ).
    z
    • 2
    • 2
  • c

    Colton Idle

    08/04/2021, 4:21 AM
    How can I place an image on the screen with a concrete height (140.dp in this case) which then affects the width of the image, but I want to offset the image alllllll the way on the left. Right now I hardcoded it to -200.dp and it works great on my pixel5, but running it on the emulator, it doesn't get pushed off the screen entirely. Do I have to try to measure the width somehow after height is applied and set offset that way?
    Box() {
        Image(
            modifier = Modifier.height(140.dp).offset(x = (-200).dp),
            painter = painterResource(id = com.myapp.myresources.R.drawable.catdog),
            contentDescription = null)
    }
    m
    a
    n
    • 4
    • 47
  • a

    Ayfri

    08/04/2021, 6:23 AM
    Hi, what is
    dp
    ?
    g
    • 2
    • 2
  • i

    iamthevoid

    08/04/2021, 6:49 AM
    Is there in compose default android AlertDialog realization? I mean realization that include native dialog buttons style, title and text styles etc? Looks like that in compose AlertDialog i should customize style almost completely and it is perfect! But what if am i want only pass strings and actions into to see android native alert dialog?
    a
    t
    • 3
    • 3
  • m

    Mohamed Ibrahim

    08/04/2021, 7:21 AM
    So I have a question about the XML selector drawable is it the same use in Compose or there something I miss? basically I need to reflect an icon selection in a group of items
    z
    • 2
    • 2
  • n

    Napa Ram

    08/04/2021, 9:31 AM
    Hi Everyone, I want to create separate Compose Component Library and then use it in my Project, in some case i want to override the compose component from Product app. can anyone help me in this case
    d
    m
    • 3
    • 4
  • j

    james

    08/04/2021, 10:52 AM
    if I have a screen built entirely in compose, but a 3rd party library I want to use requires a
    View
    to be passed into it when using it to use as an anchor.. is there any way to do that? or is this type of interop impossible? it's important to note, the 3rd party library doesn't actually need to do anything with the
    View
    besides use it as an anchor point.. so if there was a way I could programmatically generate a view that could work I guess?
    n
    s
    • 3
    • 4
  • n

    natario1

    08/04/2021, 10:56 AM
    What happens to `AndroidView`s during orientation changes? Are they re-measured with swapped width/height? Drawn with rotated canvas? My activity has
    android:configChanges="(everything)"
    as suggested by compose team, so compose handles UI rotations. But I'm seeing issues with `SurfaceView`s in the compose hierarchy. Would love to have some insight about what's happening under the hood
    👀 3
    a
    r
    • 3
    • 14
  • g

    George Kylafas

    08/04/2021, 12:19 PM
    About testing: how can I verify that a
    Text()
    node has text with a certain style, e.g. bold? Is there such a matcher/assertion available? The testing cheat sheet doesn't seem to include something similar.
    z
    • 2
    • 6
Powered by Linen
Title
g

George Kylafas

08/04/2021, 12:19 PM
About testing: how can I verify that a
Text()
node has text with a certain style, e.g. bold? Is there such a matcher/assertion available? The testing cheat sheet doesn't seem to include something similar.
z

Zach Klippenstein (he/him) [MOD]

08/04/2021, 4:46 PM
I’m not sure if there are higher level apis for this yet, but if you need to write your own assertion you could just read the
SemanticsProperties.Text
property which gives you a list of `AnnotatedString`s, and check those strings for the styles you expect. You can look at the implementation of the existing assertions, eg
assertTextContains
, as a starting point.
g

George Kylafas

08/06/2021, 12:58 PM
Thanks for your suggestion, @Zach Klippenstein (he/him) [MOD]! Unfortunately,
SemanticsProperties.Text
's
AnnotatedString
s have no spanStyles nor paragraphStyles (both are empty lists). However, the node also contained a
SemanticsActions.GetTextLayoutResult
property, which is a lambda whose enclosing class is a
TextController
which contains a
TextState
which contains a
TextDelegate
which contains a
TextStyle
which contains the desired
FontWeight
. Since half of those classes are internal, I had to do a fair amount of reflection to come up with this matcher:
@OptIn(InternalFoundationTextApi::class)
fun hasFontWeight(
    weight: FontWeight,
): SemanticsMatcher {
    val propertyName = SemanticsActions.GetTextLayoutResult
    return SemanticsMatcher(
        "$propertyName contains $weight text"
    ) {
        val actualWeight = it.config.getOrNull(propertyName)
            ?.action
            ?.javaPrivateField("this$0")
            ?.javaPrivateField("state")
            ?.javaPrivateField("textDelegate")
            ?.run { this as TextDelegate }
            ?.style
            ?.fontWeight
        actualWeight == weight
    }
}
where
fun Any.javaPrivateField(fieldName: String): Any? =
    this.javaClass
        .getDeclaredField(fieldName)
        .also { it.isAccessible = true }
        .get(this)
I am certain this is NOT the proper way to do this, but until the framework supports this officially I guess it will have to do.
z

Zach Klippenstein (he/him) [MOD]

08/06/2021, 1:21 PM
Huh, I thought the whole point of exposing annotated strings in the semantics api was to allow access to spans - eg TtsSpan or whatever it’s called in compose is purely for accessibility. Maybe it’s just not implemented yet? I would file a bug.
👍 1
(please post the bug here if you file so i can star/follow it!)
g

George Kylafas

08/06/2021, 8:58 PM
@Zach Klippenstein (he/him) [MOD] https://issuetracker.google.com/issues/195668156
⭐ 1
Can't say that I am thrilled with the solution proposed in the issue, especially since the resolved text style differs slightly from the text style I set in the code, but it's an improvement over my reflection-heavy solution.
View count: 33