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

    Tolriq

    10/07/2021, 7:01 AM
    Hi, What would be the proper way to delay a lazylist /scroll state restoration? For example with
    collectAsLazyPagingItems
    the state is collected in a launched effect so even if the flow is cached and available if the collect is started in a composable that is recreated there's at least a frame running with no content and the position is reset to 0. In that case I can collect earlier in a scope that is not removed as the data is cached. But what if I wanted to actually not keep the data, reload it then restore scroll. Is there some official doc / pattern for that ?
    a
    • 2
    • 5
  • m

    Michael Bichlmeier

    10/07/2021, 7:25 AM
    Hey guys, I need your help by finding a solution for my layout issue. I have a row or list item (doesn’t care at the moment) with different layouts and different click areas. 1. Click area of the
    Text
    should be from
    parent.start
    until
    Divider
    2. Text and Divider+Icon have to be centered with 5% spacing to start and end 3. Icon has his own click area I will post an example code snippet in the thread. I’m very interested in your ideas how to do this in a “simple” way 😉
    • 1
    • 1
  • r

    Radoslaw Juszczyk

    10/07/2021, 7:37 AM
    I need to achieve sticky header like that (it should add any space between sections);
    a
    a
    • 3
    • 8
  • s

    slartus

    10/07/2021, 8:26 AM
    is it possible to make blur effect like this?:
    👀 2
    s
    m
    +2
    • 5
    • 13
  • r

    ritesh

    10/07/2021, 8:58 AM
    What's the correct way of rendering html string in compose? Something very similar to
    HtmlCompat.fromHtml()
    in textView.
    👀 1
    s
    z
    • 3
    • 9
  • f

    Florian

    10/07/2021, 9:23 AM
    How can I get rid of `compose-navigation`'s cross-fade animation? It doesn't work well with 1. hiding bottom bars, 2. per-screen scaffolds. I can use Accompanist, but I don't wanna set the transition to null in each single
    composable
    path 😣.
    a
    c
    s
    • 4
    • 11
  • a

    athos

    10/07/2021, 9:30 AM
    Hello I am trying to have a column that will take the whole available height as long as it is between a
    MIN_H
    and
    MAX_H
    . If the vertical available space is more than
    MAX_H
    , the column should leave some empty space at the bottom, and if it is less than
    MIN_H
    , the content will be scrollable. I thought I could get this quite easily with
    Modifier.heightIn()
    but it doesn't matter where I put it or what I pass to it I never get the desired result. Example code in the thread.
    j
    • 2
    • 6
  • z

    ziv kesten

    10/07/2021, 10:39 AM
    Is there a
    Text
    implementation that can take
    SpannedString
    ?
    j
    a
    +2
    • 5
    • 14
  • z

    ziv kesten

    10/07/2021, 12:27 PM
    Which library supports GIF files best for compose?
    c
    • 2
    • 4
  • l

    Louis

    10/07/2021, 2:06 PM
    Hello , I’m having hard time trying to implement this (vertical text in a card). I tried with graphicsLayer, rotation and translation but without success...
    z
    c
    • 3
    • 2
  • d

    Dmitriy Gaiduk

    10/07/2021, 2:34 PM
    Hello, What’s the preferred way to implement a custom string resource system in Compose? Problem: We are adding the Lokalise SDK https://docs.lokalise.com/en/articles/1400668-lokalise-android-sdk. And working with strings looks like this:
    val resources = new LokaliseResources(context)
    val text = resources.getString(R.string.screen_title)
    What’s the best way to store and create the
    LokaliseResources
    object in Compose? We want to use the
    LokaliseResources.getString ()
    function as a replacement for
    androidx.compose.ui.res.stringResource ()
    . We now have an implementation like this:
    @Composable
    fun CustomTheme(
      useDarkTheme: Boolean = false,
      content: @Composable () -> Unit,
    ) {
      val colors = if (useDarkTheme) DarkColorPalette else LightColorPalette
      val colorPalette = remember { colors }
      colorPalette.update(colors)
      
      MaterialTheme(
        colors = debugColors(),
        typography = MaterialTypography,
      ) {
        CompositionLocalProvider(
          CustomColors provides colorPalette,
          content = content,
        )
      }
    }
    
    class Screen : com.bluelinelabs.conductor.Controller {
      private val lokaliseResources: LokaliseResources by lazy { LokaliseResources(activity) }
      private fun getString(@StringRes resId: Int): String {
        return lokaliseResources.getString(resId)
      }
    
     @Composable
     fun Content() {
        CustomTheme(useDarkTheme = false) {
          Text(value = getString(R.string.screen_title))
        }
      }
    }
    But the problem is that you cannot get a string resource outside of the
    Screen
    class in any Compose method. Is it possible to create LokaliseResources in a singleton? Or can this be added to
    CustomTheme
    somehow?
    🧵 3
    a
    c
    d
    • 4
    • 5
  • a

    Alexander Suraphel

    10/07/2021, 2:40 PM
    I’m following this guide to add compose to my existing app.. It says
    Make sure you're using Kotlin 1.5.21 in your project.
    Will Kotlin version
    1.5.31
    work?
    m
    a
    • 3
    • 25
  • a

    Andrew Hughes

    10/07/2021, 5:52 PM
    Would anyone be able to provide some guidance on how to implement an animated expanding/collapsing navigation rail similar to what is shown here (which is from the Navigation drawer section of this page)? The issue that I'm running into is related to how the text in the FAB or list items behaves when the rail is collapsing. As you can see in the animation, the desired effect is to have the text (i.e. "Compose" and "Inbox") fade out as the rail collapses with the result being that only the icons are visible. However, in practice, since the FAB and list items are contained within the rail, the text gets wrapped during the animation as the width of the rail animates to the collapsed size. The only thing I have found to "work" is to set the
    wrapContentWidth(unbounded = true)
    modifier on the
    Text
    composable, however, this has the side-effect of never wrapping the text, which I don't necessarily want. I started looking into creating a transition and using
    AnimatedContent
    but I haven't been having much luck so far.
    mio-staging_mio-components_1584058305895_assets_1flsPRyx7n3EHeYwkO5i5_uc19v_w5zZf_rail-behavior-reply.mp4
    👀 1
    d
    r
    • 3
    • 40
  • l

    Lilly

    10/07/2021, 6:47 PM
    I have a data class annotated with
    @Stable
    and would expect that a change to the property would reflect the new state but it doesn't:
    @Stable
    data class StableState(var isChecked: Boolean)
    
    @Composable
    fun StableTest(state: StableState) {
        Checkbox(checked = state.isChecked, onCheckedChange = {
            state.isChecked = it
        })
    }
    What did I miss?
    m
    a
    c
    • 4
    • 13
  • i

    Ink

    10/07/2021, 8:57 PM
    Hi guys How Can I wrap my text to new line when it's too long to be fully visible in one line?
    • 1
    • 1
  • b

    brabo-hi

    10/07/2021, 11:22 PM
    Hi, how can we get elevation only at the bottom when using a
    Card
    composable
    w
    • 2
    • 2
  • s

    smallshen

    10/08/2021, 5:20 AM
    is there a version of compose build that everything is open? I try to implement something but everything is marked as internal
    z
    • 2
    • 5
  • a

    Alex

    10/08/2021, 6:57 AM
    Is there a snap-helper for snapping to items in lists? (e.g. when the user stops scrolling, the list snaps to the nearest item)
    a
    c
    c
    • 4
    • 9
  • a

    Andrei Kovalev

    10/08/2021, 9:01 AM
    Hi folks, I’m trying to resolve the issue when cards overlap in grid view with
    zIndex
    , but the problem is that in lazy LazyGrid Implementation
    val rows = (scope.totalSize + nColumns - 1) / nColumns
        LazyColumn(
            modifier = modifier,
            state = state,
            contentPadding = contentPadding
        ) {
            items(rows) { rowIndex ->
                Row {
                    for (columnIndex in 0 until nColumns) {
                        val itemIndex = rowIndex * nColumns + columnIndex
                        if (itemIndex < scope.totalSize) {
                            Box(
                                modifier = Modifier.weight(1f, fill = true),
                                propagateMinConstraints = true
                            ) {
                                scope.contentFor(itemIndex, this@items).invoke()
                            }
                        } else {
                            Spacer(Modifier.weight(1f, fill = true))
                        }
                    }
                }
            }
        }
    our composable items are wrapped in a Box, but
    zIndex
    only works for direct children of the composable node. How would you resolve this issue? Any suggestions are welcome
    ✅ 1
    p
    a
    a
    • 4
    • 9
  • l

    Lucien Guimaraes

    10/08/2021, 10:16 AM
    Just updated to Accompanist 0.19.0, and I have an issue with the reworked HorizontalPager: my items have now a start/end padding to fill the pager width, instead of only keeping the item width. Anyone know how to fix this ?
    20211008_110132.mp4
    👍 2
    n
    c
    • 3
    • 20
  • a

    Alex

    10/08/2021, 10:32 AM
    Is there a way for
    LazyRow
    items to fill the max available width (and size their children accordingly?)
    • 1
    • 4
  • f

    Felipe

    10/08/2021, 3:00 PM
    Hi guys i built a small library to help navigate in compose with well typed functions: https://github.com/xmartlabs/TypedNavigation Any feedback is welcome!!
    a
    • 2
    • 7
  • j

    Jeferson Boesing

    10/08/2021, 8:00 PM
    Can someone provide a code example of how I should unit test my
    ViewModel
    that defines a
    mutableStateOf
    property? I found that
    Snapshot.withMutableSnapshot
    or
    snapshotFlow
    can be used to achieve this, has anyone used this strategy?
    l
    a
    j
    • 4
    • 3
  • m

    Mehdi Haghgoo

    10/08/2021, 8:03 PM
    I think there is something wrong with the Navigation docs in the Interoperability section. Navigating from fragment-based screens to Compose screens is fine. You just wrap the Compose UI in a ComposeView and go! But, I don't understand what the docs say when the reverse is to be done; Navigate from a Compose UI to a Fragment. The example snippet is not clear if not wrong.
    i
    • 2
    • 11
  • a

    adjpd

    10/09/2021, 12:04 AM
    If Google have the underlying Compose system working with iOS's UiKit, are they considering releasing it so developers can use the underling Compose system with iOS's UI widgets? I'd enjoy using the Compose system even if I do need to use new UI widgets with it.
    c
    • 2
    • 4
  • c

    Colton Idle

    10/09/2021, 1:08 AM
    Is there a way to get the "frosted glass" blur effect in Android 11 and lower in compose? https://medium.com/android-news/the-blurry-frosted-background-is-a-common-pattern-on-ios-where-they-have-simply-controls-to-cbd0c5843e5f
    a
    e
    a
    • 4
    • 9
  • s

    Steve C

    10/09/2021, 5:10 AM
    Clicking/dragging doesn't seem to work when I offset a composable within the scope of another composable. It seems the click rectangle for the composable is where the composable would be if it wasn't offset. In other words, the click rectangle doesn't get moved by the offset. Here's a simple example where I want the nested boxes to be moved with the parent when the parent is dragged, but the nested boxes can also be dragged independently too. This works as long as you don't move the red or green boxes outside of the blue one. Am I doing something wrong, or missing something here?
    data class MyBox(val index: Int, val color: Color)
    
    @Composable
    fun DraggingTest() {
        val boxes = mutableListOf<MyBox>()
        boxes.add(MyBox(0, Color.Blue))
        boxes.add(MyBox(1, Color.Red))
        boxes.add(MyBox(2, Color.Green))
    
        ConstraintLayout(modifier = Modifier
            .fillMaxSize()
            .background(Brush.verticalGradient(listOf(Color.Black, Color.Transparent)))
        ) {
            if(boxes.isNotEmpty()) {
                DraggableBox(index = boxes[0].index, color = boxes[0].color, boxes.takeLast(boxes.size-1))
            }
        }
    }
    
    @Composable
    fun DraggableBox(index: Int, color: Color, boxes: List<MyBox>) {
        val initialYOffset = if(index == 0) 0f else 100f
        Box(modifier = Modifier.fillMaxSize())
        {
            val offsetX = remember { mutableStateOf(0f) }
            val offsetY = remember { mutableStateOf(initialYOffset) }
            Box(modifier = Modifier
                .offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
                .size(150.dp).background(color)
                .pointerInput(Unit) {
                    detectDragGestures { change, dragAmount ->
                        change.consumeAllChanges()
                        offsetX.value = (offsetX.value + dragAmount.x)
                        offsetY.value = (offsetY.value + dragAmount.y)
                    }
                }
            ) {
                Text("Box $index", modifier = Modifier.align(Alignment.BottomCenter)
                    .offset(0.dp, 20.dp))
    
                if(boxes.isNotEmpty()) {
                    DraggableBox(index = boxes[0].index, color = boxes[0].color, boxes.takeLast(boxes.size-1))
                }
            }
        }
    }
    🧵 3
    z
    • 2
    • 4
  • e

    elye

    10/09/2021, 6:03 AM
    Hi, just check if anyone know, is • using `Column`/`Row` have the same down side as using
    LinearLayout
    ? (i.e. ConstraintLayout is preferred over LinearLayout). Or • in JetpackCompose, there’ll be no performance impact using `Column`/`Row`, and the Compose’s
    ConstraintLayout
    is just to make placement easier (for some case), but no performance benefit? Thanks!
    a
    • 2
    • 2
  • l

    Laco

    10/09/2021, 7:15 AM
    Hi, I found a issue that occurred using
    paddingFromBaseline
    in Text. I saw this document and wrote code as below
    @Composable
    fun TwoTexts(...) {
        Row(modifier.height(IntrinscisSize.Min) {
            // skipped other modifiers
            Text(text = "Hi", modifier = modifier.paddingFromBaseline(top = 26.sp, bottom = 10.sp) 
            Divider(...)
            Text(text = "there", ...)
        }
    }
    // TextSize = 24.sp
    // LineHeight = 36.sp
    But ui rendered differently. I think that text measured by
    paddingFromBaseline
    even if it's smaller than Baseline value Is this the result intended by IntrinsicSize.Min? Please look at pictures below Thanks!
    🧵 1
    • 1
    • 1
  • m

    Marc

    10/09/2021, 9:36 AM
    Perhaps it would be a quite basic question there I go: I’m implementing a custom graphic view with 2 possible cases: 1. Infinite width (and fixed height) in such case the width is taken from the number of elements of the graphic and the i just allow horizontal scrolling. 2. Fixed with and height where in this case I need to know the width and height of the component to properly fit the graphic in the canvas rect. Can anyone help me out with the second point? (I’m just starting so there are many things yet that I don’t know exist) Thanks!
    z
    • 2
    • 2
Powered by Linen
Title
m

Marc

10/09/2021, 9:36 AM
Perhaps it would be a quite basic question there I go: I’m implementing a custom graphic view with 2 possible cases: 1. Infinite width (and fixed height) in such case the width is taken from the number of elements of the graphic and the i just allow horizontal scrolling. 2. Fixed with and height where in this case I need to know the width and height of the component to properly fit the graphic in the canvas rect. Can anyone help me out with the second point? (I’m just starting so there are many things yet that I don’t know exist) Thanks!
z

Zach Klippenstein (he/him) [MOD]

10/12/2021, 2:18 AM
Not quite sure what you're asking, but the max constraints give you that information. If you have something like this:
Canvas(Modifier.fillMaxSize()) {
  // inside here you have access to the size
}
m

Marc

10/21/2021, 9:37 AM
omg, yes hahaha, this is exactly what i wanted thanks!
View count: 2