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

    zt

    03/24/2022, 8:10 PM
    I'm making something that has descriptions, that can sometimes contain URLs. How can I make those URLs be made clickable?
    e
    • 2
    • 2
  • a

    allan.conda

    03/24/2022, 8:49 PM
    Anyone knows why setting
    fillMaxSize
    is ignored if specified below
    verticalScroll
    Modifier?
    Untitled.kt
    t
    a
    • 3
    • 3
  • m

    Mehdi Haghgoo

    03/25/2022, 9:24 AM
    Why we have ProvideTextStyle() and not also ProvideShape() and ProvideColors()? We access theme values from within the theme object (MaterialTheme object), so why do we need to use ProvideTextStyle(value){content()} in the first place?
    c
    • 2
    • 3
  • r

    ritesh

    03/25/2022, 9:46 AM
    Say i have a Composable which, makes use of
    stringResource
    and maps from one object to another. I should be marking it as
    @ReadOnlyComposable
    ? More in 🧵
    t
    z
    • 3
    • 5
  • t

    takahirom

    03/25/2022, 11:03 AM
    I recently tried Compose Compiler Metrics and have a question regarding the Stability of Compose. Thanks for a very clear and simple tool! https://github.com/androidx/androidx/blob/androidx-main/compose/compiler/design/compiler-metrics.md Since Compose treats classes in another module as Unstable even if they are Immutable, if a class in another module has parameters in its arguments, even if the parameters have not changed, are they not skipped and subject to Recompose? I would like to know because it could considerably affect the design of the application using Compose. app module
    @Composable
    fun Composable1(articles: Articles) {
      Text(text = "Hello $articles!")
    }
    
    @Stable
    data class UiModel(val articles: Articles)
    
    @Composable
    fun Composable2(uiModel: UiModel) {
      Text(text = "Hello $uiModel!")
      uiModel.articles.articles.forEach {
        Composable3(it)
      }
    }
    
    @Composable
    fun Composable3(article: Article) {
      Text(text = "Hello $article!")
    }
    model module
    data class Articles(val articles: List<Article>)
    data class Article(val title: String)
    app_release-composables.txt
    restartable fun Composable1(
      unstable articles: Articles
    )
    restartable skippable fun Composable2(
      stable uiModel: UiModel
    )
    restartable fun Composable3(
      unstable article: Article
    )
    source code https://github.com/takahirom/compose-multi-module-stability
    r
    a
    +2
    • 5
    • 10
  • a

    axehit

    03/25/2022, 11:04 AM
    Hello, I am currently writing some tests for pagination in compose, and I noticed that
    performScrollToIndex
    method in compose ui test library provided for scrolling an item to a particular index, scroll that item index to the very top position. This behaviour is different from the
    recyclerView.scrollToPosition
    method we have currently in the old view system which scrolls the item just enough to make that item visible at the bottom. Can someone tell me is there an API for tests in compose to have that similar behaviour of scrolling the item just enough to make it visible at the bottom instead of at the top?
    ➕ 1
    s
    z
    • 3
    • 5
  • d

    Daniele Segato

    03/25/2022, 2:42 PM
    Why aren't text transformations (such as all-caps) part of
    TextStyle
    ? Most designers see those as part of the text styling but in compose we are forced to handle them via code. Is there any plan to include text transformations in text style so that we can manage them in themes? In some project I created my own Text widgets to add this behavior, but I think it should be part of Compose handling of Texts.
    s
    • 2
    • 11
  • j

    julioromano

    03/25/2022, 3:09 PM
    I’m writing a custom layout using
    Layout
    but the algorithm to compute the placement of the children composables (i.e. to compute both the constraints of the measurables and the x,y of the placeables) turns out to be O(n^2). Is it possible to handle this computation in a background coroutine or similar, but still while inside the composable
    Layout()
    function? Are there any patterns in compose to help with such cases?
    r
    m
    • 3
    • 9
  • a

    Arkadii Ivanov

    03/25/2022, 6:35 PM
    Hello. Is there a stable way to disable interaction with a whole sub-tree in a parent? E.g. I have the following function:
    @Composable
    fun Foo(content: @Composable () -> Unit) {
        var enabled by remember { mutableStateOf(true) }
        
        Box(
            modifier = Modifier // Disable the sub-tree if not enabled
        ) {
            content()
        }
    }
    How can I disable the
    content
    ? So far I discovered
    Modifier.pointerInteropFilter { true }
    which seems working, but it is marked as experimental with level
    ERROR
    .
    a
    • 2
    • 1
  • y

    YASAN

    03/25/2022, 9:18 PM
    I am trying to add pagination to my
    LazyColumn
    using Paging3 (with its compose library). I now show the paginated list by converting the
    PagingData
    into a
    LazyPagigItems
    object. My issue is that I cannot find a way to show any state other than the success state like showing the loading indicator or showing an error when the loading of a page fails. I have done this outside Compose using RecyclerViews but I cant find anything useful for it in Compose.
    m
    p
    • 3
    • 9
  • a

    Alexander Maryanovsky

    03/25/2022, 9:38 PM
    I’m trying to implement a
    Modifier
    that, when the element it modifies is “selected” (in a sense I define), it automatically makes it focused.
    fun Modifier.focusedWhenSelected(): Modifier = this.then(FocusedWhenSelected)
    
    object FocusedWhenSelected: Modifier.Element{
    
        fun implementingModifier(modifier: Modifier, isSelected: Boolean): Modifier{
            val hasFocusedWhenSelected = modifier.any { it == FocusedWhenSelected }
            if (!hasFocusedWhenSelected)
                return Modifier
    
            return Modifier.composed {
                val focusRequester = remember { FocusRequester() }
                if (isSelected) {
                    LaunchedEffect(Unit) {
                        focusRequester.requestFocus()
                    }
                }
    
                Modifier
                    .focusRequester(focusRequester)
                    .focusable()
            }
        }
    }
    and then, in the code that actually defines
    isSelected
    , I do:
    Box(
        modifier = FocusedWhenSelected.implementingModifier(modifier, isSelected)
    ){
    ...
    }
    Does this look right? I’m somewhat worried that I’m creating a new
    Modifier.composed
    every time.
    z
    • 2
    • 11
  • r

    robnik

    03/25/2022, 11:48 PM
    I'm trying to create LazyColumn of Images. I want it to fill width and take a height that preserves its aspect ratio. Everything I've tried has zero height, no visible images. Eg:
    Image(
        painter = ..., contentDescription = null,
        contentScale = ContentScale.Fit, // ???
        modifier = Modifier.fillMaxWidth() 
    )
    a
    • 2
    • 2
  • a

    Alexander Black

    03/26/2022, 1:29 AM
    Wondering if anyone has any advice on how I can do an overlay like this? I currently have it working using this code:
    overlay = {
                        if (it.isSelected) {
                            Box(
                                Modifier
                                    .size(if (it.rentalLength != null) 245.dp else 222.dp)
                                    .alpha(0.6f)
                                    .background(DownpourTheme.colors.primary)
                            )
                        }
                    }
                )
    but the size being hardcoded is obviously not ideal. Wondering if there’s an easy way to measure the size of the card my box is trying to overlay?
    c
    • 2
    • 5
  • a

    Aaron Waller

    03/26/2022, 7:03 AM
    Is there a way to convert a composable canvas into png and save it on the device? I want to make a small “Art” app where the user can create shapes etc and then extract them as png to use them elsewere. Is compose even able to do such things?
    s
    • 2
    • 1
  • l

    Luis Daivid

    03/26/2022, 1:01 PM
    Does anyone use the accompanist library in the product app? The library version is less than 1.0, so I’m worried, is it okay to use it in production level?
    👍 2
    f
    • 2
    • 1
  • a

    Alexander Maryanovsky

    03/26/2022, 1:32 PM
    Simplifying a lot, so forgive me if the use-case doesn’t make much sense. I’m trying to implement a
    Column
    where each row “knows” its index, like so:
    @Composable
    fun IndexedColumn(
        content: @Composable IndexedColumnScope.() -> Unit
    ){
        Column {
            content.invoke(IndexedColumnScope())
        }
    }
    
    class IndexedColumnScope{
    
        var index = 0
    
        @Composable
        fun row(
            rowContent: @Composable IndexedRowScope.() -> Unit
        ){
            val rowIndex = remember { index++ }
            rowContent.invoke(IndexedRowScope(rowIndex))
        }
    
    }
    
    class IndexedRowScope(
        val rowIndex: Int
    )
    
    @Composable
    fun UseIndexedColumn(){
        IndexedColumn{
            repeat(5) {
                row{
                    Text("Row $rowIndex")
                }
            }
        }
    }
    The problem is with the
    var index
    — when a row changes,
    row
    is called again (not recomposition, but regular composition) and
    index
    increases again. So if I had at the beginning
    Row 0
    Row 1
    Row 2
    Row 3
    Row 4
    and then row 2 changes from
    Text
    to
    BasicTextField
    , I’d have
    Row 0
    Row 1
    Row 5  <-- BasicTextField
    Row 3
    Row 4
    :thread-please: 1
    s
    z
    m
    • 4
    • 12
  • t

    Tobias Gronbach

    03/26/2022, 10:32 PM
    Hi guys, I've a design question. I want to position a FAB and I don't know what way is the most suitable for that. Code in Thread ...
    a
    • 2
    • 5
  • l

    Long Tran

    03/27/2022, 7:21 AM
    Hi guys, I'm trying to customize TextField to center its content. Everything else is okay except the cursor, i don’t know if there is a way to center it. Thanks for your help!!! 🙇
    r
    c
    a
    • 4
    • 7
  • r

    ritesh

    03/27/2022, 8:47 AM
    I have a logic to show animated composable sliding in from top. I was wondering if there's a better way to achieve what i have, the
    Side-effect
    part? More in 🧵
    c
    • 2
    • 13
  • a

    Aaron Waller

    03/27/2022, 8:48 AM
    To convert Bitmaps to ImageBitmaps we use
    .asImageBitmap()
    . But is there a way to convert ImageBitmaps to Bitmaps? I want to save the ImageBitmap as a .png on the internal storage and/or upload it to my cloud storage
    • 1
    • 1
  • r

    Ryosuke Yamada

    03/27/2022, 10:43 AM
    Hello. I'm trying to add swipe-to-refresh to my WebView, using Accompanist's
    SwipeRefresh
    . Simple example:
    var isRefreshing by remember { mutableStateOf(false) }
    var isLoaded by remember { mutableStateOf(false) }
    
    SwipeRefresh(state = rememberSwipeRefreshState(isRefreshing),
        onRefresh = { isRefreshing = true }) {
        AndroidView(
            factory = {
                WebView(it).apply {
                    webViewClient = WebViewClient()
                }
            }
        ) { webView ->
            if (!isLoaded) {
                webView.loadUrl("<https://www.android.com/>")
                isLoaded = true
            }
    
            if (isRefreshing) {
                webView.reload()
                isRefreshing = false
            }
        }
    }
    This does not work because
    SwipeRefresh
    needs scrollable child. By adding
    verticalScroll
    modifier to AndroidView,
    SwipeRefresh
    works, but WebView gets infinite height and content does not rendered as expected. Is there any way to notify legacy View's scroll events to parent Composable?
    d
    a
    • 3
    • 4
  • m

    Marcin Wisniowski

    03/27/2022, 6:07 PM
    Can I have overlapping composables in a
    Row
    ? I'm looking for something like
    Modifier.offset(x = 8.dp)
    , which correctly moves my item to overlap the next one, but does not modify the size of the outer
    Row
    . I have two items in the
    Row
    .
    m
    c
    • 3
    • 3
  • i

    Icyrockton

    03/28/2022, 4:53 AM
    how to implement overscroll refresh ? something like this
    f
    • 2
    • 6
  • z

    ziv kesten

    03/28/2022, 8:37 AM
    I am running a simple Test on `LaunchedEffect`:
    @Test
    fun testSomeState() {
        composeTestRule.setContent {
            SomeComposable {
                println("click $it")
            }
        }
        composeTestRule.onNodeWithTag("Zivi")
            .performClick()
            .assertExists()
    }
    
    @Composable
    fun SomeComposable(onClick: (Int) -> Unit) {
        var someState by remember { mutableStateOf(0) }
    
        Button(modifier = Modifier.testTag("Zivi").pointerInteropFilter {
            someState = when (it.action) {
                MotionEvent.ACTION_DOWN -> { 1 }
                MotionEvent.ACTION_UP -> { 2 }
                else -> { someState  }
            }
            true
    
        }, onClick = { }) {}
    
        LaunchedEffect(someState) {
            println("LaunchedEffect someState $someState") // prints "LaunchedEffect someState 0" 
                                                           // and then "LaunchedEffect someState 2"
            if (someState == 2) { onClick(someState) }
        }
    }
    ------------ This works well, however, if i change
    Button
    to a
    Box
    , like this: ------------
    @Composable
    fun SomeComposable(onClick: (Int) -> Unit) {
        var someState by remember { mutableStateOf(0) }
    
        Box(modifier = Modifier.testTag("Zivi").pointerInteropFilter {
            someState = when (it.action) {
                MotionEvent.ACTION_DOWN -> { 1 }
                MotionEvent.ACTION_UP -> { 2 }
                else -> { someState  }
            }
            true
    
        }) {}
    
        LaunchedEffect(someState) {
            println("LaunchedEffect someState $someState") // prints "LaunchedEffect someState 0"
            if (someState == 2) { onClick(someState) }
        }
    }
    Then the
    LaunchedEffect
    is not called on
    performClick
    , can anyone help me understand why?
    :thread-please: 2
    s
    • 2
    • 4
  • s

    Stylianos Gakis

    03/28/2022, 9:33 AM
    While migrating some screen from Views to Compose there was an inconsistency regarding the background color that I’d like to hear more about. Basically we’ve in some places relied on the functionality of the
    OutlinedButton
    style having a transparent background. This doesn’t seem to be the case in the compose version as it defines the
    surface
    color of the
    MaterialTheme
    as its background instead. I would love to hear more about what is the idea behind it? More often than not, when using an
    Outlined
    button, one would like to have it show the text and the outline but blend in with whatever is in the background by basically having no background. That is since what’s behind it often is not a
    surface
    . It could be for an image or some color close to surface not not quite the same. My guess would be that this was done to ensure a proper pair of surface/onSurface color to ensure accessibility, so it this the reason? Anything else I’m missing? We’re considering altering our design system’s outlined button to always have a transparent background (while still using onSurface for the content) and I would basically like to hear more about this to see why we may want/not want to do this. Assuming we’re taking care of making the content legible on a per-case basis of course.
    c
    l
    • 3
    • 8
  • c

    czuckie

    03/28/2022, 10:28 AM
    I'm getting some really bizarre behaviour in an android application where I'm trying to integrate compose. It seems like a nice way to dip our toe in is to use
    ComposeView
    inside a
    Fragment
    - it works well with our current navigation system, but we're noticing things like
    TextField
    will not update consistently on text entry. The exact same composable in a
    ComponentActivity
    works as expected. Is there some particular stuff I need to be wary of when using JC with Fragments?
    s
    • 2
    • 11
  • t

    Tobias Gronbach

    03/28/2022, 10:29 AM
    Hi all, I feel stuck. I have a MainScreen-Composable that contains a scaffold with a fab that is changing it's actions depending on the current screen shown in Scaffold-Content. One of those screens is the AddItem-Screen Composable that contains some TextFields. When I click on the FAB (in MainScreen-Composable) I want to keep the AddItem-Screen-State (the Text-Fields-Input) and call the AddItemViewModel.onFabSaveClicked() method (both in AdddItemScreen-Viemodel). It would be a no-brainer if the scaffold was inside AddItem-Screen-Composable but now I don't know how trigger AddItemViewModel.onFabSavedClicked() from the Fab in the MainScreen-Composable.
    j
    • 2
    • 8
  • j

    Johan Reitan

    03/28/2022, 11:35 AM
    I have a
    Row
    component that has two slots for text. Both texts can be of varying length, and I’m having a hard time getting the component to balance the text’s width so that the longest text takes the rest of the available space, and also weigh them equally if both texts are long. The closest I’ve been able to get is using equal values of
    Modifier.weight()
    , but that does not solve the case where one text is longer than the other. The first image is using
    weight()
    , and the second is what I’m trying to achieve. Code and more examples in thread 🧵
    s
    a
    s
    • 4
    • 13
  • r

    Rafael Costa

    03/28/2022, 12:51 PM
    Are modal screens (dialogs or bottom sheet from accompanist) expected to not stay in the back stack after navigating away from them? I've had issues opened on my library about this and I'm not sure if this is expected. At the moment they are not kept unless we navigate to another modal screen. So is this intended or should I open an issue?
    m
    i
    • 3
    • 7
  • i

    Icyrockton

    03/28/2022, 2:05 PM
    it's a way to disable Android12 stretch effect? I think
    accompanist-swiperefresh
    has a bug on it.
    k
    • 2
    • 2
Powered by Linen
Title
i

Icyrockton

03/28/2022, 2:05 PM
it's a way to disable Android12 stretch effect? I think
accompanist-swiperefresh
has a bug on it.
k

Kirill Grouchnikov

03/28/2022, 2:19 PM
Did you file a bug?
i

Icyrockton

03/28/2022, 2:50 PM
others submitted issue https://github.com/google/accompanist/issues/1059
View count: 6