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

    Shivam Sethi

    02/27/2021, 5:51 AM
    Hello Composers, I have a topbar composable where I am using Row as a composable content, I am not able to align the text( title of appbar) to center vertically in row, I have set vertical alignment of Row to center vertically. It centers as expected when the icon (back arrow) appears but goes to default alignment top when icon is not there.
    a
    a
    • 3
    • 3
  • s

    Shivam Sethi

    02/27/2021, 8:13 AM
    Anybody know how can I add compose to existing codebase, I want to add it to a new fragment without any XML, I tried to follow Interop documentation but after doing the steps, the build was successful app launched and crashed when I navigated to that fragment, it only had a ComposeView with a Text.
    t
    a
    c
    • 4
    • 18
  • s

    Smorg

    02/27/2021, 8:24 AM
    I have been experiencing serious issues with the Android Studio IDE since trying to use compose with it, specifically in an existing project. Issues ranging from not completing “Analyzing/syncing” source files, resource manager not showing my resources, autocomplete is slow or not even working sometimes. I got a pop-up saying this below:
    High number of internal exceptions has been detected. This indicates a serious problem with the IDE. Please consider clean reinstall of Android Studio. If the problem persists, please report a bug by following the link below.
    Anyone else experiencing this?
    t
    t
    c
    • 4
    • 8
  • a

    Archie

    02/27/2021, 9:55 AM
    Hi, just would like to share and confirm. This is how I scope my
    ViewModel
    to a
    NavGraph
    .
    @Composable
    inline fun <reified VM : ViewModel> navGraphViewModel(
        route: String,
        navController: NavController,
    ): VM {
        // Now get the NavBackStackEntry associated with the parent
        val backStackEntry = navController.getBackStackEntry(route)
    
        val context = LocalContext.current
      
        return ViewModelLazy(
            viewModelClass = VM::class,
            storeProducer = { backStackEntry.viewModelStore },
            factoryProducer = { HiltViewModelFactory(context, backStackEntry) }
        ).value
    }
    Was wondering how others are doing theres? (I am using Hilt for my project, the ViewModelFactory could be passed in if you are not using Hilt)
    j
    • 2
    • 4
  • a

    A. Sachdeva

    02/27/2021, 10:35 AM
    hi, I upgraded to compose beta 1.00 and my current project that i created a day ago started showing error for
    setContent{
    and
    LazyColumn{
    what are the new alternatives for these?
    j
    t
    • 3
    • 13
  • s

    Spikey Sanju

    02/27/2021, 10:48 AM
    Hi guys, Currently i'm developing one sample app. Whenever I click on icon button I need to change the app theme & Icon. Below code works fine. But is there any way to optimise the below code?... Since I'm repeating the entire code block in both
    if
    and
    else
    block?
    j
    j
    a
    • 4
    • 10
  • s

    Spikey Sanju

    02/27/2021, 11:08 AM
    Hi guys, I'm trying to create transparent chip view for genders
    Male
    &
    Female
    . I'm repeating this code block for two times here. Below code works but I guess it can be optimised. Any Suggestion? I have also attached image of the both chip views
    j
    j
    +3
    • 6
    • 13
  • l

    loloof64

    02/27/2021, 1:05 PM
    Hi everybody ! I've just cloned and downloaded the Puppy Challenge repository, but AS Artic Fox (2020.3.1 Canary 8 ) do not even manage to compile it:
    An exception occurred applying plugin request [id: 'com.android.application']
    > Failed to apply plugin 'com.android.internal.application'.
       > java.lang.NoSuchMethodException: java.lang.invoke.MethodHandles.privateLookupIn(java.lang.Class, java.lang.invoke.MethodHandles$Lookup)
    I'm compiling with Java 8 from AdoptOpenJDK
    n
    • 2
    • 2
  • a

    A. Sachdeva

    02/27/2021, 1:56 PM
    hi, what could be an alternative to notifydatasetchanged onjetpack compose? i have this note like ui with text and a crosss button. on click of cross , i wish to invoke a listener which will remove that item from the list. code in thread
    j
    • 2
    • 5
  • s

    Slackbot

    02/27/2021, 2:56 PM
    This message was deleted.
    q
    r
    • 3
    • 4
  • v

    Vipulyaara

    02/27/2021, 3:13 PM
    I am trying to justify a single line of text. I have tried appending
    \n
    with no help. The first line of text is justified if I set
    maxLines = 2
    and let the text flow in second line. I am not so familiar with how justification works on android but is there a way to achieve this - a single line of text which can stretch to occupy full width of the screen?
    • 1
    • 1
  • g

    Gabriel

    02/27/2021, 3:49 PM
    If I have a Row, with background colour and rounded corners, when I have achild in that row with a different background colour how can I make it fit the rounded corners of the parent without also needing to tell it about rounded corners?
    t
    • 2
    • 2
  • s

    Spikey Sanju

    02/27/2021, 4:27 PM
    Hi guys, how to send data class as an arguments instead of each type in the data class? P.S -> I'm having list of items in home screen when onClick I need to pass the data as a class!
    a
    c
    i
    • 4
    • 11
  • m

    Malte Heitmüller

    02/27/2021, 5:05 PM
    Hey guys, what do you think is the best way to implement a vertical grid with items that could fit full width and half width (so sometimes there is empty space in a column)?
    r
    • 2
    • 1
  • s

    Sergey Y.

    02/27/2021, 6:09 PM
    Hi, on the android show talked about the experimental api for multithreaded composition. Is it available in beta1? does it need to be turned on somehow? because apparently all my composition functions are always called from the main thread. Thanks.
    👍 1
    a
    j
    • 3
    • 2
  • n

    natario1

    02/27/2021, 7:23 PM
    Is it possible to nest a LazyColumn in a scrollable Column? Like a RecyclerView with
    height="wrap_content"
    .
    d
    a
    • 3
    • 12
  • r

    robnik

    02/27/2021, 8:06 PM
    What is the difference between
    rememberSavable
    and
    savedInstanceState
    . Both are mentioned in https://developer.android.com/jetpack/compose/state. They look like they do the same thing.
    d
    • 2
    • 3
  • a

    A. Sachdeva

    02/27/2021, 8:29 PM
    Hi, I was trying to create notes app like screen and ran into some bugs and crashes, probably due to my implementation. below file contains the code. • My ui would  consists of a list of notes, each note consisting of text, a button to edit(that will just change notes text directly on click) , a button to delete  and an overall toast on item click. • so from what i know, for this  i would need an item ui composable, a list ui composable , a state controller composable(state hoisting i guess?) and finally setting all of this to setContentView, right? • so i did all this .the  list was showing correctly. I was also using
    SnapshotStateList
    directly for learning purposes instead of using
    mutableStatelistof.
    But: 1. the  on click log and delete action seems to work, but when done too quickly, started giving index out of bounds. is it because of my implementation? 2. my main goal was to show a toast on item click, but could not access 
    LocalContext.current
     , so had to test with logs. how to get context? 3. onEdit was not working immediately, but would show effect after scrolling. if it was recycler view, i would say a classic problem of adapter not reflecting latest changes due to lack of notifydatasetchanged call. so again, what did i missed?
    file.kt
    j
    • 2
    • 4
  • g

    Gabriel

    02/27/2021, 9:50 PM
    I have a composable that represents a screen, with a list of items, a fab to add new items, edit buttons, delete buttons, so like 6 things I'm passing into this screen from the viewmodel
    a
    • 2
    • 5
  • t

    Tash

    02/27/2021, 10:13 PM
    Using the Pager in Jetcaster and trying to introduce a draggable component in one of the Pages of the Pager. What’s the best way to make the draggable component in the Page completely consume the pointer events so that the parent Pager doesn’t react to them?
    • 1
    • 1
  • d

    Daniel

    02/27/2021, 10:56 PM
    Hi, I have a composable that takes one heavy parameter that should never change and one lightweight parameter that should change a lot. I initially wrote it like this
    @Composable
    private fun Page(page: PageRenderer /* @Immutable data class, never changes */, turn: Dp = 0.dp /* changes frequently in animations */) {
        Surface(
            Modifier
                .fillMaxSize()
                .background(page.background)
                .offset {
                    IntOffset(
                        -turn
                            .toPx()
                            .roundToInt(), 0
                    )
                }
                .drawWithCache {
                    onDrawWithContent {
                        drawContent()
                        drawIntoCanvas {
                            Timber.i("Drawing into canvas")
                            page.paint(it)
                        }
                    }
                },
            elevation = 15.dp
        ) {}
    }
    Based on my logs, I noticed that
    drawIntoCanvas
    was called every time
    turn
    changed, which I was very surprised by. (I thought the whole point of offset taking a lambda would prevent that) I fixed the issue by adding another component, but I'm confused by why this was necessary
    @Composable
    private fun Page(page: PageRenderer, turn: Dp = 0.dp) {
        Surface(
            Modifier
                .fillMaxSize()
                .background(page.background)
                .offset {
                    IntOffset(
                        -turn
                            .toPx()
                            .roundToInt(), 0
                    )
                },
            elevation = 15.dp
        ) {
            Canvas(Modifier.fillMaxSize()) {
                drawIntoCanvas {
                    Timber.i("Drawing into canvas")
                    page.paint(it)
                }
            }
        }
    :thread-please: 3
    a
    • 2
    • 1
  • r

    Rahul Sainani

    02/27/2021, 11:17 PM
    Is there a recommended place/callback to use for the first composition, analogous to fragment's onCreate?
    a
    k
    • 3
    • 4
  • d

    Daniel

    02/27/2021, 11:26 PM
    What do you want to do with it @Rahul Sainani? You might be looking for
    remember
    r
    z
    • 3
    • 7
  • y

    Yofou

    02/28/2021, 5:09 AM
    This is just out of curiousty, is there any resources out there for how to create your own custom LAZY layout, thank you in advanced
    z
    s
    • 3
    • 2
  • c

    Ch8n

    02/28/2021, 9:11 AM
    Hi Guys how can I load
    gif
    image from raw files in composing? I'm using GlideImage library..
    r
    • 2
    • 1
  • s

    Shakil Karim

    02/28/2021, 11:33 AM
    Is it a performance issue, if i put mutableState fields in model class which is use in lazyColumn items?
    d
    • 2
    • 3
  • m

    Mehdi Haghgoo

    02/28/2021, 12:38 PM
    When I add kotlin to the list of plugins in my project as per this doc, I get this error: (The rest in the thread)
    a
    • 2
    • 5
  • a

    André Thiele

    02/28/2021, 1:24 PM
    Anybody else experiencing this issue? I upgraded to beta01 and kotlin 1.4.30
    androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.0.0-alpha13) expects a minimum runtime version of 1.0.0-alpha13.
    q
    a
    +2
    • 5
    • 35
  • s

    Spikey Sanju

    02/28/2021, 2:09 PM
    Guys I have completed the #AndroidDevChallenge. I hope it helps someone who's looking forward for some UI inspiration with JP Compose implementation. You can download app from Github share your reviews 🙏... Heartly congratulations for Jetpack Compose Team & Android Community who worked hard to make Compose great ♥️ Github
    😍 18
    👍 14
    j
    j
    +3
    • 6
    • 12
  • d

    Daniel

    02/28/2021, 2:22 PM
    I'm writing an ebook reader. I wrote a composable to display paginated text, which involves measuring MultiParagraphs and then rendering clipped portions to canvases. I want to allow text selection, so I looked at how the builtin Text handles selection. Unfortunately, essentially all the code used to manage selection in compose below the level of Text appears to be internal. I'm currently planning to copy https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]/foundation/text/selection/AndroidSelectionHandles.android.kt and most of https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]l=78?q=CoreText&amp;ss=androidx%2Fplatform%2Fframeworks%2Fsupport to my own project, which doesn't feel ideal. Am I missing something?
    j
    • 2
    • 4
Powered by Linen
Title
d

Daniel

02/28/2021, 2:22 PM
I'm writing an ebook reader. I wrote a composable to display paginated text, which involves measuring MultiParagraphs and then rendering clipped portions to canvases. I want to allow text selection, so I looked at how the builtin Text handles selection. Unfortunately, essentially all the code used to manage selection in compose below the level of Text appears to be internal. I'm currently planning to copy https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]/foundation/text/selection/AndroidSelectionHandles.android.kt and most of https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]l=78?q=CoreText&amp;ss=androidx%2Fplatform%2Fframeworks%2Fsupport to my own project, which doesn't feel ideal. Am I missing something?
j

jim

02/28/2021, 5:31 PM
cc @Siyamed
d

Daniel

02/28/2021, 5:33 PM
Here's what I have so far: https://gist.github.com/danielzfranklin/db21db2598a93294533764bcc4e6c5e8
I've got a
PageRenderer
that is responsible for knowing what text is on the current page where. All I'm doing is copying from what
CoreText
uses, stripping out anything I don't need (like cross-composable selection)
The gist leads to working drag-to-highlight so far
View count: 1