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

    Tin Tran

    09/17/2021, 7:53 AM
    Hi guys! I’m having some weird issue with Gboard with auto correct enabled and TextField It happen If I use
    TextFieldValue
    var text by remember { mutableStateOf("") }
    TextField(value = TextFieldValue(text), onValueChange = {text = it.text})
    Screen_Recording_20210917-145141_GOLFTEC Clubhouse 3.mp4
    f
    f
    • 3
    • 6
  • g

    gsala

    09/17/2021, 8:56 AM
    Hi. I'm trying to create a
    Table
    composable that displays data in rows and column of variable width/height. So far I managed to lay out the table using a `Layout`(image 1). The cells are placed properly, but not measured properly, because I gave up on trying to understand and implement intrinsic measurements. I need to add the grid to the table but if I try to use the cells to do so, the borders are not aligned since the cells are not measured properly (image 2) Is there a way to draw directly on the Layout using the same coordinates I used to place the cells?
    z
    w
    • 3
    • 6
  • r

    ritesh

    09/17/2021, 9:17 AM
    What is the correct way of disabling screen interaction when
    CircularProgressIndicator
    is materialized on screen.
    Box(
        modifier = Modifier.fillMaxSize(),
        showLoading:Boolean,     
      ) {
        LazyColumn { // displaycontent
          
        } 
        if(showLoading){ // disable background screen interaction
           CircularProgressIndicator()
        }
      }
    d
    • 2
    • 1
  • r

    Rizwan Minhas

    09/17/2021, 9:21 AM
    Hi! I am currently working on an aap with all composables (No fragment) with single activity, I am little confuse about navigation compose. If in future, I have to use fragment in this app, can I navigate from a composable to a fragment or How its work?
    j
    c
    +2
    • 5
    • 8
  • c

    Colton Idle

    09/17/2021, 11:25 AM
    I've got text like this
    Text("first line\nsecond line")
    but it just shows the \n directly in the Text widget According to SO, I should do
    Text("first line\r\nsecond line")
    but that didn't work either. Any thoughts? Edit: nvm did this and it works now
    myText.replace("""\n""", "\n")
    z
    • 2
    • 22
  • p

    PHondogo

    09/17/2021, 11:43 AM
    Hello! Is it possible to specify color only for one side of border?
    c
    • 2
    • 1
  • c

    Colton Idle

    09/17/2021, 11:47 AM
    Shouldn't their be an option to extract a composable to a function? or am i missin somethin
    t
    • 2
    • 2
  • i

    iamthevoid

    09/17/2021, 2:21 PM
    Is it bug or feature? When TextField disappears it triggers
    onValueChange
    c
    w
    l
    • 4
    • 12
  • s

    Sergey Zarochentsev

    09/17/2021, 2:28 PM
    Hello! I want to set focus on input and show a keyboard when the screen is showed. I want to implement this behavior on a number of screens and I want to reduce code duplication with FocusRequester and LaunchedEffect. Is it correct to create requestFocus modifier like this?
    fun Modifier.requestFocus(requester: FocusRequester = FocusRequester()): Modifier = composed {
        LaunchedEffect(requester) {
            requester.requestFocus()
        }
    
        focusRequester(requester)
    }
    z
    • 2
    • 2
  • c

    Cicero

    09/17/2021, 3:32 PM
    What do you guys think about adding some compose into your data models? 🤔
    m
    a
    a
    • 4
    • 9
  • c

    Chris Fillmore

    09/17/2021, 3:34 PM
    Is there an available composable text field that allows user input while also showing a trailing value? For use cases where the user is entering the user name portion of an email address, or the subdomain in a domain name, and you want to show the trailing domain. Like this:
    User can input text on the left of this text field, and "<http://example.com|example.com>" stays visible as the user is typing
    ________________________________
    |<user input here> .<http://example.com|example.com>|
    --------------------------------
    Alternately the "<http://example.com|example.com>" could be outside the text field:
    ___________________
    |<user input here>| .<http://example.com|example.com>
    -------------------
    🧵 1
    c
    n
    • 3
    • 4
  • d

    dimsuz

    09/17/2021, 4:37 PM
    what is the safe way to show old-style android dialog from Composable function? For example:
    @Composable
    fun ScreenContent(state: State) {
      if (state.showDialog) {
        // Need to show MaterialDatePicker here
      }
    }
    Use
    SideEffect
    ?
    z
    a
    +2
    • 5
    • 17
  • s

    Scott Kruse

    09/17/2021, 7:01 PM
    Can i leverage compose runtime on kotlin multiplatform iOS targets via
    expect / actual
    ?
    b
    • 2
    • 1
  • b

    brabo-hi

    09/17/2021, 7:32 PM
    Hi, what is the best way to handle a
    LongClick
    on a
    TextButton
    r
    • 2
    • 2
  • r

    Rafs

    09/17/2021, 7:35 PM
    Is it possible to animate the constraints of a constraintLayout in compose?
    👀 1
    a
    • 2
    • 1
  • s

    Sololo

    09/18/2021, 3:15 AM
    how to convert Compose View to Bitmap?
    w
    c
    m
    • 4
    • 3
  • w

    Waqas Tahir

    09/18/2021, 9:07 AM
    How could one go about creating a text field which supports Undo Redo !
    a
    z
    • 3
    • 2
  • t

    Tolriq

    09/18/2021, 9:49 AM
    So I've searched a lot about @Immutable / @Stable but I have an hard time to understand the cases when it's properly inferred or not. I have data classes that are shared with non compose apps so I'd prefer not to add compose-runtime to those modules. But I do not really understand if it's currently possible to wrap then with no cost or help compose without those annotations.
    👍 4
    a
    e
    a
    • 4
    • 10
  • t

    theapache64

    09/18/2021, 2:20 PM
    [✅ SOLVED] ✨ Animation:
    expandHorizontally
    and
    shrinkHorizontally
    accept a param named
    expandFrom
    and
    shrinkTowards
    respectively. But it looks like it doesn’t consider that param. OR am I doing anything wrong? More details inside 🧵
    h
    s
    • 3
    • 6
  • f

    Fudge

    09/18/2021, 2:26 PM
    Consider the map:
    @Composable fun MyComponent(map: Map<Int, String>) {
       val states = map.mapValues {(k,_) -> remember(k) {mutableStateOf(0) } }
       for ((k,v) in map) MyStatefulComponent(v,states[k]!!)
    }
    On a first look, this looks fine. We host the states for
    map.size
    items of
    map
    in a parent component
    MyComponent
    , and create
    map.size
    child `MyStatefulComponent`s, each with its own state. However, on a second look, this code makes no sense. The way
    remember(key)
    works, is that whenever a new value is passed, the state is erased and something new is remembered. So if there are at least two elements, the state of all elements except the last one will be erased. In practice, hocus pocus, it works. Each element of
    map
    has its own unique state cell. No clue how. If a child gets added to or removed from
    map
    , it updates and keeps working. Magic! But, in my case that I can't reproduce here, the state gets deleted whenever the map shrinks. So I want to understand: what actually makes this work?
    🧵 1
    a
    d
    • 3
    • 31
  • a

    adjpd

    09/18/2021, 2:34 PM
    If you use a
    Shadow
    in a
    TextStyle
    and the
    blurRadius
    is
    0
    then the shadow doesn't appear. Is that intended behaviour, do you think?
    a
    • 2
    • 2
  • a

    Akram Bensalem

    09/18/2021, 5:18 PM
    What is the best method to swith between 2 languages ( localization) ? Is there any example ??
    c
    • 2
    • 1
  • e

    eneim

    09/19/2021, 12:41 PM
    I have seen a few times a method call is called twice like this https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]/runtime/Composer.kt;l=1742?q=internal%20class%20ComposerImpl or this https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]ime/Composer.kt;l=1235-1237?q=internal%20class%20ComposerImpl (not consecutive, but somehow a method is called twice. Maybe it is legit due to internal state change) Not sure it is a bug or something hidden inside?
    a
    • 2
    • 2
  • h

    Hien Nguyen

    09/19/2021, 1:26 PM
    Is there any way to apply the old style in existing app with compose like below
    <style name="TextAppearance.TypographyStyles.Caption.Test">
            <item name="fontFamily">@font/roboto_medium</item>
            <item name="android:fontFamily">@font/roboto_medium</item>
            <item name="android:letterSpacing">0.0</item>
        </style>
    e
    • 2
    • 2
  • e

    eneim

    09/19/2021, 1:48 PM
    [Q] I have the following layout:
    LazyColumn(modifier = Modifier.fillMaxSize()) {
      item {
        Box(modifier = Modifier.fillMaxWidth().height(200.dp))
      }
      items(100) {
        Text(text = stringResource(id = R.string.long_text))
      }
    }
    When I scroll down, the Box is out of the screen, but not enough for it to be disposed. How can I tell that the Box is out of the screen or not without using LazyListState? (So something that works even when the LazyColumn is replaced by a scrollable Column).
    f
    • 2
    • 3
  • t

    theapache64

    09/19/2021, 4:13 PM
    Can somebody show me a simple example of
    TargetBasedAnimation
    ? 🤔 (Maybe something with
    Box
    ,
    Text
    etc 😬)
    d
    • 2
    • 1
  • a

    andrew

    09/19/2021, 6:35 PM
    Pretty happy with this interaction, feels smooth
    r
    • 2
    • 2
  • c

    Colton Idle

    09/20/2021, 12:53 AM
    How do I create a form like this which can have the keyboard go to the next text field, and on the second text field, the keyboard essentially clicks the button?
    l
    • 2
    • 8
  • d

    darkmoon_uk

    09/20/2021, 6:21 AM
    For those implementing Accessibility w/ TalkBack - Are there any common reasons why TalkBack would not say the role of the component? All I get is: '<the button text>, double-tap to activate' whereas with the old View system it would say '<the button text>, button, double-tap to activate' <-- I need this for consistency ...I've tried setting the Role semantic, merging nodes, not merging etc. it just won't say 'Button' and it's driving me up the wall! EDIT: Solved but in an unexpected way - not sure if this is a bug - :google: folk?
    a
    a
    • 3
    • 7
  • j

    james

    09/20/2021, 7:31 AM
    this might be a silly question, but those of you who work on projects where unit tests are important but UI tests are much less common, what did you do when you started bringing in more and more Composables into your app? obviously the coverage drops significantly if you don’t write UI tests for everything because you now have a lot more kotlin code for Composables.. but I’m curious about what others have done. have you: • started being more strict about writing UI tests • not written UI tests and simply accepted the coverage % drop • something else?
    k
    z
    +2
    • 5
    • 10
Powered by Linen
Title
j

james

09/20/2021, 7:31 AM
this might be a silly question, but those of you who work on projects where unit tests are important but UI tests are much less common, what did you do when you started bringing in more and more Composables into your app? obviously the coverage drops significantly if you don’t write UI tests for everything because you now have a lot more kotlin code for Composables.. but I’m curious about what others have done. have you: • started being more strict about writing UI tests • not written UI tests and simply accepted the coverage % drop • something else?
k

K Merle

09/20/2021, 8:01 AM
I do not monitor test coverage and do not care that much about UI tests. From my exp unit tests are the ones to worry about.
👍 3
z

ziv kesten

09/20/2021, 9:05 AM
Adding UI Tests for composables, it was easier then I anticipated, and made coding the composables faster, since I just ran the tests and didn't have to compile the project and navigate to that UI element.
z

Zach Klippenstein (he/him) [MOD]

09/20/2021, 4:29 PM
UI tests and unit tests are not mutually exclusive. You can write unit tests for UI, and compose makes doing so very easy. That said, I don’t think raw “coverage” is a very useful metric without context so pragmatically I wouldn’t be worried about this as long as you’re separating out changes that migrate ui to compose from changes to actual business or non-ui logic.
👍 1
c

Colton Idle

09/21/2021, 3:46 AM
You can write unit tests for UI
🤔 With jetpack compose though you still technically need to run those unit tests on the device right?
k

K Merle

09/21/2021, 6:26 AM
@Colton Idle I think you do, as most of the stuff in composable function reacts to user interaction. So if you wanna test if something changed, you must run device and interact with the screen. e.g.
@Test
    fun should_call_sign_out_once_when_sign_out_button_clicked() {
        with(composeTestRule) {
            setContent { SignOutScreen(viewModel = viewModel) {} }
            val signOutButtonText = activity.getString(R.string.sign_out_button)
            onNodeWithText(signOutButtonText).performClick()
            verify { viewModel.signOut() }
        }
    }
z

ziv kesten

09/21/2021, 7:53 AM
If you need an activity/device/emulator I don't see how it is a unit test and not a UI test. Would you place it in the test package or in the androidTest package?
z

Zach Klippenstein (he/him) [MOD]

09/21/2021, 6:31 PM
With jetpack compose though you still technically need to run those unit tests on the device right
Probably, although you may be able to run them with robolectric.
If you need an activity/device/emulator I don’t see how it is a unit test and not a UI test.
They are different axes. A “unit test” tests a “unit” of code, as opposed to an integration test which tests how multiple components interact. There are other types of tests on this axis as well (e.g. functional). A “unit” can be a non-UI bit of logic, or a single UI component, for example. A “UI test” tests some UI. That may be a single component (i.e. a unit UI test) or a whole navigation flow. Typically UI tests are ran on an emulator or device, although it might be possible in the future to run UI tests without a device/emulator (typically called “host-side”).
👍 1
z

ziv kesten

09/21/2021, 8:17 PM
So something like testing if a button changes color when clicked is both a UI test and a unit test?
z

Zach Klippenstein (he/him) [MOD]

09/21/2021, 8:56 PM
If you’re actually only testing the button component itself with all its dependencies faked out, vs launching the app, navigating to a screen with the button, and clicking it, then yes
👍 2
j

james

09/24/2021, 4:55 AM
thank you all for the detailed answers 🙏
View count: 10