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

    Chris Fillmore

    04/22/2021, 1:16 AM
    Can I use a
    ComposeView
    to draw a composition into a Canvas, off-screen? More or less this:
    val canvas = Canvas()
    val composeView = ComposeView(context)
    composeView.setContent {
      // Call composables here
    
      SideEffect {
        composeView.draw(canvas)
      }
    }
    Important to note that the ComposeView is never attached to a window / drawn in the UI. The view is created programmatically, as above. I am ultimately trying to get the composition into a Bitmap for the purpose of drawing into an OpenGL texture. (If there is a better approach, I’m all ears.) Thanks for any help!
    👀 1
    r
    a
    • 3
    • 14
  • i

    Indu

    04/22/2021, 2:06 AM
    I've a question regarding scoping of viewmodel across screens
    i
    • 2
    • 7
  • s

    Shivam Sethi

    04/22/2021, 4:28 AM
    Can, anybody help me with this error, I am getting this just right after creating a project with selecting empty compose template when trying to run the project even first time ?
    a
    j
    • 3
    • 3
  • s

    Shivam Sethi

    04/22/2021, 6:00 AM
    How can I pass a gradient using brush api to a composable who has a color parameter exposed as Color type ?
    a
    z
    • 3
    • 4
  • s

    Samir Basnet

    04/22/2021, 6:41 AM
    Will screen level transitions be coming in next beta? I am really hoping it comes fast.
    ➕ 2
    f
    a
    d
    • 4
    • 3
  • p

    Paul Woitaschek

    04/22/2021, 7:48 AM
    We are slowly migrating to compose and we have very complex recycler views. Is it possible to interop these so we can use compose inside a viewholder?
    :yes: 1
    d
    • 2
    • 1
  • l

    loloof64

    04/22/2021, 8:40 AM
    Hi ! As I need custom drawing for my
    Composable
    , is there a way to get the component size based on its given
    Modifier
    ? I mean, given
    @Composable
    fun MyComposable(modifier: Modifier = Modifier){}
    Is there a way to get the allocated width and height (inside
    MyComposable
    definition) ?
    a
    • 2
    • 1
  • m

    mzgreen

    04/22/2021, 9:02 AM
    I'd like to have a
    Row
    with 2
    Texts
    which both take up 50% of the screen width. Here is an xml version of the thing I want to achieve:
    <LinearLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        >
      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:text="Foo"
          />
      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:text="Bar"
          />
    </LinearLayout>
    I came up with this:
    Row(Modifier.fillMaxWidth()) {
        Text(text = "Foo", Modifier.fillMaxWidth(0.5f))
        Text(text = "Bar", Modifier.fillMaxWidth())
      }
    Is there some other, maybe better way to do it?
    :thread-please: 2
    f
    • 2
    • 3
  • l

    loloof64

    04/22/2021, 10:03 AM
    Looking at DrawScope documentation, https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.html#public-methods, I did not find any method for drawing a
    Vector Drawable
    : is there a way to do it ?
    z
    • 2
    • 4
  • l

    Lucien Guimaraes

    04/22/2021, 10:56 AM
    What would be to best way to reset the scroll of a lazylist in Compose when the list is updated from the viewModel ?
    a
    • 2
    • 5
  • e

    escodro

    04/22/2021, 11:58 AM
    Hello, everyone! 👋 I upgraded to Compose 1.0.0-alpha05 and all my instrumented tests on modules outside
    :app
    are no longer working because it can not find the
    ComponentActivity
    registered in the debug
    AndroidManifest.xml
    . Is it the expected behavior now? Should we have one debug Manifest for each library modules? It worked fine on Compose 1.0.0-alpha04. Issue tracker opened with more info: https://issuetracker.google.com/issues/186019857
    n
    • 2
    • 1
  • k

    Konyaco

    04/22/2021, 1:18 PM
    tryAwaitRelease()
    always returns
    false
    .
    m
    • 2
    • 1
  • a

    Altynbek Nurtaza

    04/22/2021, 2:06 PM
    Hi everyone! in the videos people say composable functions are very similar to suspend functions. why is Composable a annotation rather than a kotlin keyword?
    a
    a
    +2
    • 5
    • 5
  • s

    sen kumar

    04/22/2021, 2:29 PM
    What options do we have for showing tooltip or balloon when clicking on a icon?
    z
    d
    l
    • 4
    • 5
  • d

    dewildte

    04/22/2021, 2:55 PM
    I want this:
    TextFieldValue(
      cursorPosition = text.length
    )
    Manipulating the cursor position causes weird bugs when using a hardware keyboard. Especially around new lines.
    z
    • 2
    • 8
  • a

    alorma

    04/22/2021, 4:59 PM
    Hi! I'm trying to create a custom
    state
    (i guess) to save a value in preferences, and trigger recomposition when it changes... However, i managed to save the new value, but it is not triggering a recompostion.. what I'm missing? code on thread
    j
    r
    a
    • 4
    • 8
  • m

    Marko Novakovic

    04/22/2021, 8:21 PM
    am reading side effects documentation and I have a bit of a trouble grasping
    rememberUpdatedState
    . what is it used for and what is it really doing? am trying to write some code in order to test/grasp what’s it doing but still nothing
    z
    • 2
    • 3
  • b

    Brady Aiello

    04/22/2021, 8:57 PM
    I’m having an issue with TextField. If I have a TextField like this:
    @ExperimentalComposeUiApi
    @Composable
    fun UsernameTextField(
        state: State<String>,
        label: String,
        onValueChange: (String) -> Unit
    ) {
        Column {
            TextField(
                value = state.value,
                onValueChange = onValueChange,
                label = { Text(label) },
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(16.dp),
                singleLine = true
            )
        }
    }
    and call it like this:
    UsernameTextField(
        state = userName,
        label = getString(R.string.Username),
    ) {
        loginViewModel.updateUserName(it)
    }
    When typing most characters, the
    onValueChange
    is triggered on the whole String there, like “a”, “ad”, “ada”. But if I type a tab or return at the end of a String,
    onValueChange
    is triggered on only the tab/return character. Does anyone understand why this is happening?
    🤔 1
    z
    d
    s
    • 4
    • 19
  • y

    YASAN

    04/22/2021, 10:34 PM
    I am trying to let my users manually select dark mode independently from the system settings. On non-compose apps I just used
    AppCompatDelegate
    to change dark mode but on my Compose app it has no effect. It looks like
    isSystemInDarkTheme()
    just checks the system settings and even when I use my own function to check dark mode, it only effects the Compose MaterialTheme colors which I don't use much. I use resources for dark/light colors and it works fine except this. How can I handle this in Compose? It does not look like
    AppCompatDelegate
    has any effect on Compose.
    c
    • 2
    • 5
  • z

    Zhelyazko Atanasov

    04/23/2021, 5:53 AM
    I'm playing around with screenshot testing. So I checked the implementation of TextFieldScreenshotTest (part of Jetpack Compose) and there you are using
    AndroidXScreenshotTestRule
    . But I can't seem to find the appropriate dependency to add to my project so that I can use
    AndroidXScreenshotTestRule
    . I looked into Google's Maven repo for
    androidx.test
    group and I also have added these dependencies to my project: •
    androidx.test:core-ktx
    •
    androidx.test:runner
    •
    androidx.test:rules
    •
    androidx.test.ext:junit-ktx
    But none of them seems to contain the desired
    AndroidXScreenshotTestRule
    . What am I missing?
    c
    l
    s
    • 4
    • 8
  • m

    mzgreen

    04/23/2021, 6:02 AM
    I'd like to create a Compose library which can be consumed by Compose Android and Compose Desktop projects. Because of some differences like loading resources etc I think it would be the best to create a Kotlin Multiplatform project which builds 2 artifacts: a .jar which can be consumed by Compose Desktop projects and an .aar which can be consumed by Compose Android projects. Is there an example app out there so that I could take look at project's the setup?
    e
    c
    • 3
    • 3
  • j

    jean

    04/23/2021, 8:25 AM
    I’m trying to use an
    Image
    composable with
    rememberCoilPainter
    nested under a
    LazyColumn
    but it seems to not be working, the image is not loading. If I take the composable out of the
    LazyColumn
    then it works fine. Any idea what’s going on?
    a
    c
    i
    • 4
    • 8
  • l

    loloof64

    04/23/2021, 8:34 AM
    Hi ! I am drawing into my
    Composable
    , but I don't know how to make this drawing reactive to click. More in the thread.
    c
    z
    • 3
    • 63
  • a

    Adrian Landborn

    04/23/2021, 9:56 AM
    Hi! Is there a way to remove/replace the
    Ripple
    -indication for Buttons and Cards? Or to override
    rememberRipple
    in a custom theme?
    r
    l
    • 3
    • 7
  • y

    YASAN

    04/23/2021, 11:06 AM
    Is it possible to request focus on a TextField after opening a composable screen using Compose navigation? I want the keyboard to automatically open and focus on the TextField instead of the user having to tap on the TextField
    c
    d
    • 3
    • 9
  • a

    allan.conda

    04/23/2021, 12:20 PM
    How could I prevent a reload taking a parameter from the composable on the viewModel on configuration change?
    Profile(userId: String) {
      val viewModel = hiltNavGraphViewModel<ProfileViewModel>()
      DisposableEffect(userId) {
        viewModel.loadProfile(userId) // don't trigger on config change
        onDispose { }
      }
      val profile = viewModel.profile.collectAsState(...)
    }
    Actually, with compose-navigation it seems the backstack arguments are also in the ViewModel savedStateHandle. I’m wondering if it would be better to extract the userId from there instead.
    z
    i
    • 3
    • 15
  • m

    MaxUt

    04/23/2021, 1:16 PM
    Hi there, I'm struggling to figure out how to make a mutable
    NavHostController
    . I have several NavHostController so I can navigate through sub-pages and would like to send an event to the root Composable so I get the current NavHostController. The idea behind is to use it in a topBar so I can pop element off the stack and go back to the previous view. Do you guys have any experience with that ?
    i
    • 2
    • 7
  • c

    Colton Idle

    04/23/2021, 1:16 PM
    Saw this comment on reddit with a bunch of upvotes.
    I'm building a new app with no DI. It's a breath of fresh air, to be frank.
    CompositionLocalProvider currently serves the need I had for DI, and there's no sacrifice in testability (so far).
    Is it find to use CompositionLocalProvider for this sort of stuff? https://www.reddit.com/r/androiddev/comments/mwjut9/dagger_hilt_is_now_stable_with_235/gvj2beu?utm_source=share&amp;utm_medium=web2x&amp;context=3
    a
    • 2
    • 3
  • g

    grandstaish

    04/23/2021, 1:43 PM
    Hi all, I’m trying to run a fake layout pass and then capture a screenshot in my test. I’m grabbing the root Window View, and then calling measure/layout/draw manually on it to get the bitmap in the size I want. The problem I’m running into is that subcomposed composables aren’t positioned correctly in my screenshots. In my specific case, I have a LazyList with 3 items. When I run the test, the 3 items are drawn on top of each other (instead of stacked vertically in a column) in the screenshot. (Screenshots in :thread-please: ) Anyone know if there’s anything else I need to do to draw View/Composable content into a Bitmap correctly?
    • 1
    • 2
  • b

    Bryan Herbst

    04/23/2021, 1:51 PM
    I’d like to have my
    Text()
    measure as though its text is bold even when its not so that the size of the
    Text()
    component doesn’t change as text gets bolded/unbolded. What’s the best way to accomplish that? Here’s an example of the behavior I don’t want:
    Screen Recording 2021-04-23 at 8.20.41 AM.mov
    g
    z
    +3
    • 6
    • 19
Powered by Linen
Title
b

Bryan Herbst

04/23/2021, 1:51 PM
I’d like to have my
Text()
measure as though its text is bold even when its not so that the size of the
Text()
component doesn’t change as text gets bolded/unbolded. What’s the best way to accomplish that? Here’s an example of the behavior I don’t want:
Screen Recording 2021-04-23 at 8.20.41 AM.mov
g

grandstaish

04/23/2021, 2:18 PM
You could have invisible bolded versions of the labels in the same boxes so that they contribute to the size. But you’d need to be careful to ignore them in the semantics tree
☝️ 1
snap
z

Zach Klippenstein (he/him) [MOD]

04/23/2021, 2:18 PM
Lol
b

Bryan Herbst

04/23/2021, 2:19 PM
I actually just got a working modifier!
fun Modifier.widthByTextStyle(
  text: String,
  style: TextStyle
) = composed {
  val maxIntrinsics = MultiParagraphIntrinsics(
    annotatedString = AnnotatedString(text),
    style = style,
    placeholders = emptyList(),
    density = LocalDensity.current,
    resourceLoader = LocalFontLoader.current
  )

  val widthDp = with(LocalDensity.current) {
    maxIntrinsics.maxIntrinsicWidth.toDp()
  }

  width(widthDp)
}
:nice: 5
The invisible text was my first thought, but didn’t love it
z

Zach Klippenstein (he/him) [MOD]

04/23/2021, 2:19 PM
Nice!
b

Bryan Herbst

04/23/2021, 2:19 PM
Modifier needs a little cleanup, but was a lot easier than I feared
j

Javier

04/23/2021, 2:22 PM
Curiously, I am going to save that modifier, but I liked the animation when you change selected widget xD
z

Zach Klippenstein (he/him) [MOD]

04/23/2021, 2:23 PM
We interacted on Twitter about this, but idk if you saw this thread at the time about animating font weights in compose: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1618853550136500
Tl;dr it should technically be possible, but seems broken right now.
In case that’s something you try doing
b

Bryan Herbst

04/23/2021, 2:24 PM
I did! And I’ve had a similar discussion internally too- would love to support animating between font weights but our font isn’t a variable weight font right now anyway (reminds me, need to chat with our UX team about that)
@Javier thanks, I’m super happy with the selection animation too! The background of each chip is just a pretty straightforward modifier:
private fun Modifier.scrollableSegmentBackground(selected: Boolean) = composed {
  val elevationDp by animateDpAsState(
    targetValue = if (selected) TargetElevation.OnLight.medium else 0.dp
  )

  val backgroundColor by animateColorAsState(
    targetValue = if (selected) {
      TargetTheme.colors.background.default
    } else {
      TargetTheme.colors.background.container
    }
  )

  graphicsLayer(
    shadowElevation = with(LocalDensity.current) { elevationDp.toPx() },
    shape = SegmentShape
  ).background(
    color = backgroundColor,
    shape = SegmentShape
  )
}
👍 1
👀 1
s

Siyamed

04/23/2021, 4:40 PM
I recently learned that make font bold but dont change measurement is actually not weight but a variable font axis called grade
:today-i-learned: 2
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide#grade
doesn’t help you now but wanted to share
🙏 2
z

Zach Klippenstein (he/him) [MOD]

04/23/2021, 5:01 PM
This makes grade a useful axis of variation as it can be varied or animated without causing reflow of the text itself.
Wow this is super interesting. Learning so much today!
c

Colton Idle

04/23/2021, 5:04 PM
@Bryan Herbst that code snippet you posted is all you need to get that animation to work from a solid background "chip" to an elevated "card" looking chip?
b

Bryan Herbst

04/23/2021, 5:08 PM
Yep!
scrollableSegmentBackground()
does both the background color and the elevation.
🎉 2
View count: 1