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

    Mehdi Haghgoo

    09/13/2020, 5:00 AM
    How can I use predefined UI portions as scaffold parameters without getting this warning? > The expression is unused
    b
    • 2
    • 3
  • a

    Arpan Sarkar

    09/13/2020, 5:28 AM
    I am trying to create cube grid animation like the first video, In my implementation for first time the animation is working as expected, after the animation repeat everyting is becoming mess...i guess when using
    repeatable{}
    the keyframe delay is not working as expected.
    Screencast 2020-09-13 10:48:21.mp4
    s
    d
    • 3
    • 4
  • m

    Mehdi Haghgoo

    09/13/2020, 8:27 AM
    How to divide available space in a row evenly between items? For a bottomBar for example, the items tend to stick to start by default.
    a
    • 2
    • 2
  • m

    Mehmet Peker

    09/13/2020, 9:57 AM
    I using Modifier.clickable() for handle click event but when i tap to view showing effect on view(like ripple effect).How can i disable this?
    l
    • 2
    • 2
  • j

    John O'Reilly

    09/13/2020, 11:14 AM
    I'm using
    launchInComposition
    as shown here to call suspend function....what's recommended way to show progress indicator (like
    CircularProgressIndicator
    ) until that function completes?
    @Composable
    fun MainLayout(sdk: SpaceXSDK) {
        var launches by remember { mutableStateOf<List<RocketLaunch>>(emptyList()) }
    
        launchInComposition {
            launches = sdk.getLaunches(false)
        }
        
        LazyColumnFor(items = launches) { launch ->
            LaunchView(launch)
        }
    }
    h
    • 2
    • 4
  • s

    Saiedmomen

    09/13/2020, 12:20 PM
    Here's hoping it hasn't been too many times... Is is intended/ok to have
    State
    in ViewModels?
    :yes: 3
    s
    • 2
    • 2
  • s

    sasikanth

    09/13/2020, 1:52 PM
    I am trying to use
    remember
    with
    mutableStateOf
    as a property delegate, but I am getting this error.
    Type 'TypeVariable(T)' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate
    Here is the usage
    var selectedItem by remember { mutableStateOf(0) }
    Currently I am using AS 4.2 Canary 10 with Compose Alpha 02. Am I doing something wrong or is this an issue?
    • 1
    • 3
  • s

    Sourabh Rawat

    09/13/2020, 2:01 PM
    How can achieve this TextField? Seems very difficult to write extra code on top of
    BaseTextField
    .
    m
    z
    • 3
    • 6
  • a

    Archie

    09/13/2020, 2:28 PM
    What's compose stand about persistent UI? Such as keeping the same AppBar across multiple screen. Is it expected that we change the whole screen everytime in Compose?
    s
    • 2
    • 1
  • l

    Leland Richardson [G]

    09/13/2020, 7:48 PM
    Hey everyone! Don’t want to over self-promo here, but just wanted to let you all know that I’m starting a twitch + youtube channel where I will be live-streaming a bunch of stuff about compose. Made a quick video to explain more about what the content will be about and the motivation!

    https://www.youtube.com/watch?v=WNkIMx3Mr9o▾

    Twitch: https://www.twitch.tv/intelligibabble
    👍 13
    🎉 76
    ❤️ 27
    p
    a
    +3
    • 6
    • 13
  • m

    Mohamed Elfiky

    09/13/2020, 7:59 PM
    Is animation inspector for compose already exist in android studio canary?
    y
    d
    • 3
    • 2
  • k

    KamilH

    09/14/2020, 9:36 AM
    Where would you start if you want to implement
    ChipGroup
    ? Some custom
    Layout
    or some combination of
    Column
    and
    Row
    ?
    s
    d
    • 3
    • 3
  • a

    Alex Barcelo

    09/14/2020, 11:46 AM
    Hi, there! Did anyone took the Using State in Jetpack Compose codelab? Once I’ve finished the Dynamic UI based on state section, when running the codelab project, adding items by clicking the add button goes ok, but when clicking on ime action from keyboard, it adds a default item (no text + default icon). Moreover, if I hide the keyboard, show it back and then press action button, it does add the item properly. Oh, and that’s with the
    start
    project,
    finished
    doesn’t even do anything. I’m building the codelab project from AS 4.2 Canary 10, Compose alpha-02 and running it on a Google Pixel 3a.
    a
    a
    +2
    • 5
    • 7
  • m

    manueldidonna

    09/14/2020, 12:47 PM
    Which is the most performing way to wrap a composable just to add a modifier?
    s
    c
    • 3
    • 11
  • a

    Archie

    09/14/2020, 12:58 PM
    Where can I see these sample codes written in the documentation?
    *
     * @sample androidx.compose.material.samples.ButtonSample
     *
     * If you need to add an icon just put it inside the [content] slot together with a spacing
     * and a text:
     *
     * @sample androidx.compose.material.samples.ButtonWithIconSample
    y
    • 2
    • 2
  • d

    Daniele B

    09/14/2020, 3:53 PM
    I also had the idea of using
    ambientOf
    in this way, which is basically the same way you would use
    @EnvironmentObject
    in SwiftUI: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1592352556316500
    @Composable
    fun foo(appState: StateFlow<ChannelState>) {
      val currState by appState.collectAsState()
      Providers(CurrAppState provides currState) {
        // Content that should see currState
      }
    }
    as a kind of “dependency injection”, which “saves” an object in the environment, so that it’s possible to call it down the tree without having it passed all the time as a parameter. But I didn’t understand the explanation of @Adam Powell and @Zach Klippenstein (he/him) [MOD] why
    ambientOf
    should not be used in this use case, and what is the way to use it instead.
    a
    s
    • 3
    • 9
  • a

    Archie

    09/14/2020, 4:32 PM
    Hi, I was wondering if anyone understands how
    Crossfade
    composable work? How does it it able to fade in and fade out the Composables? Why are there two
    Stack
    inside
    Crossfade
    ? What exactly does
    invalidate
    do? and so on and so forth.. I would like to create a custom transition of my own but i struggle to understand how it works. Any guide on where I should start so I could understand these concepts better?
    z
    • 2
    • 5
  • m

    mattinger

    09/14/2020, 6:28 PM
    Anyone know how to set dark mode in the preview window? I have a custom theme that i can pass colors, but the default is to call a composable function which checks the
    isSystemInDarkTheme()
    function and decides whether to return my light or dark colors instance.
    a
    s
    j
    • 4
    • 13
  • s

    spierce7

    09/15/2020, 2:10 AM
    Has anyone run into this lately? Kotlinx.serialization not working with jetpack compose? https://issuetracker.google.com/issues/157901343
    a
    d
    i
    • 4
    • 3
  • c

    Colton Idle

    09/15/2020, 2:41 AM
    Okay, I feel really dumb. I have a new project and I'm just trying to add a simple material TextField to the screen. Why is this not working? TextField seems to accept a string value, and a onValueChange of a string as well.
    TextField(value = "first", onValueChange = { s: String -> })
    z
    v
    +4
    • 7
    • 12
  • r

    Rodri Represa

    09/15/2020, 10:45 AM
    Do I have to import any specific library to retrieve a ViewModel into a @Composable function? I'm trying to retrieve it and the app crashes
    val viewModel: LoginViewModel by viewModel()
    c
    i
    i
    • 4
    • 5
  • s

    Se7eN

    09/15/2020, 1:21 PM
    I have a
    LazyColumnFor
    that displays 20 items. The items consist of an image and some text. When displaying 20 items with each image of size 128kb, it lags like hell. Is this a bug or am I missing something? Also, it works totally fine when displaying only text.
    m
    c
    +6
    • 9
    • 17
  • h

    Henning B

    09/15/2020, 4:16 PM
    I am having a problem in the "Layouts in Jetpack Compose" Codelab. Chapter 6 "Create your custom layout". You are supposed to map a List of Measurables to a list of Placeables. The
    map
    operator doesn't work for me though. I am getting the error:
    Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: ...
    .fastMap
    works though. Why is this happening? Should I report this? Link to codelab: https://developer.android.com/codelabs/jetpack-compose-layouts#5
    • 1
    • 2
  • n

    Neal Sanche

    09/15/2020, 6:20 PM
    I'm trying to use Canvas in compose, and am seeing what looks like old state in my DrawScope. I sort of expected that the canvas would be cleared each time. Is there a way for me to clear the draw scope, so that it just repaints the whole canvas?
    n
    • 2
    • 2
  • a

    Alejandro Rios

    09/16/2020, 2:25 AM
    Hello, I was doing the
    Migrating to Jetpack Compose
    codelab then on the
    Testing
    tab it mentions that you can use
    findByText
    to validate a composable String the strange thing is that function doesn't appear
    p
    • 2
    • 2
  • n

    Nat Strangerweather

    09/16/2020, 4:04 PM
    Hi, I followed the Jetpack Compose Theming Codelabs tutorial to the letter but my status bar is still purple. Any ideas what I need to do? I would like it to be white in LightTheme and black in DarkTheme...
    m
    l
    • 3
    • 4
  • z

    zoha131

    09/16/2020, 4:23 PM
    Is it possible to create a ViewModel inside a Compose function? What would be the approach in Compose only app?
    a
    a
    • 3
    • 6
  • t

    tcracknell

    09/16/2020, 5:07 PM
    Hello! The latest Jetpack Compose minor release, alpha03, has just dropped! You can get it now on Google’s Maven Repository. Release notes are available at https://developer.android.com/jetpack/androidx/versions/all-channel. As always, feedback is welcome at https://issuetracker.google.com/issues/new?component=612128.
    🎉 14
    👍 27
    l
    • 2
    • 1
  • u

    3bdoelnaggar

    09/16/2020, 5:25 PM
    I want to change layout directions how can I do that thanks
    v
    • 2
    • 4
  • d

    dagomni

    09/16/2020, 7:09 PM
    Any ETA on official navigation/backstack? 😅
    i
    j
    +3
    • 6
    • 28
Powered by Linen
Title
d

dagomni

09/16/2020, 7:09 PM
Any ETA on official navigation/backstack? 😅
i

Ian Lake

09/16/2020, 7:21 PM
https://issuetracker.google.com/issues/161472731 is the issue to star for progress updates
👍 4
j

Javier

09/16/2020, 8:43 PM
@Ian Lake is it available in navigation 2.4 in the androidx snapshot repo?
i

Ian Lake

09/16/2020, 10:09 PM
It is a separate
androidx.compose.navigation
artifact group at the moment
But yes, there is a snapshot available in pre-dev level of quality
👍 3
j

Javier

09/17/2020, 9:42 AM
I have a few questions: • Where can I give feedback about improvements for androidx.dev web? (actually, if I want to find
ui/androidx/compose/navigation
, I have to click "next page" a few minutes, and in the url I can't put the page number too because it is using a token • I didn't see samples with args, so I guess they are not supported at this moment
i

Ian Lake

09/17/2020, 1:56 PM
Args are being added in https://android-review.googlesource.com/c/platform/frameworks/support/+/1423769
👍 1
a

Alexander Karkossa

09/17/2020, 3:29 PM
Is there a way to use a Crossfade with the current implementation of NavHost?
i

Ian Lake

09/17/2020, 4:15 PM
No, that's one of the topics we're going to be working on prior to any release
👍 1
a

Alexander Karkossa

09/17/2020, 7:54 PM
Are there any plans to support Hilt-ViewModelInject for the upcoming navigation library for compose?
s

Sergey Y.

09/17/2020, 8:02 PM
Injection into a Composable function? Please no
👍 1
😄 1
i

Ian Lake

09/17/2020, 8:02 PM
Navigation in Compose supports ViewModels at the screen level. Navigation doesn't care/control/have anything to do with where you get your ViewModel Factory from, Hilt or not
❤️ 1
a

Alexander Karkossa

09/17/2020, 8:04 PM
Hmm ok, maybe I have to check again. Currently he is searching for an empty constructor in my ViewModels. It seems that the HiltViewModelFactory was not used
i

Ian Lake

09/17/2020, 8:22 PM
Sounds like it isn't using your Hilt provided factory at all. Have you tried the instructions in the Hilt guide? https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodel-navigation
a

Alexander Karkossa

09/17/2020, 8:26 PM
Jup. ViewModel Injection outside of compose works fine. Don’t know if there is a Problem with NavBackStackEntry within the androidx navigation library. The getDefaultViewModelProviderFactory created the SavedStateVieeModelFactory
In NavHost compose the ViewModelStoreOwnerAmbient provides the currentNavBackStackEntry. I thought that would cause these problem
j

Javier

09/17/2020, 8:31 PM
@Ian Lake so if I annotate the activity as EntryPoint, hilt should work with compose ootb (using the ViewModel function inside the composable)?
i

Ian Lake

09/17/2020, 8:33 PM
More official documentation on Hilt+Compose is still to come, but if you use the containing Activity/Fragment's
defaultViewModelProviderFactory
and Compose's viewModel function, then it'll certainly use Hilt's factory
👍 1
Assuming your containing Activity/Fragment is correctly set up in Hilt land (i.e., as an EntryPoint)
That's all independent of Navigation
a

Alexander Karkossa

09/17/2020, 8:35 PM
Hmm I did all of this. I will try it tomorrow again.
@Ian Lake Tried it again.  Test 1 (worked): val viewModel: MyViewModel by viewModels() in the MainActivity injects the ViewModel with Hilt.  Test 2 (worked): val viewModel: MyViewModel = viewModel() within compose Test 3(crash): val viewModel: MyViewModel = viewModel() within NavHost. NewInstanceFactory tries to create an instance. No zero argument constructor.
i

Ian Lake

09/17/2020, 9:28 PM
You did read the docs I linked above right? You have to pass in the factory when in Navigation
Hilt only does things at the Activity or Fragment layer, it has no idea about the Navigation layer, so when you create ViewModels that are scoped at the Navigation layer, you need to be explicit that you want to pull a ViewModelProvider.Factory out from your Activity/Fragment
This is part of what the Hilt team is looking at for best practices for Hilt in Compose
a

Alexander Karkossa

09/17/2020, 9:44 PM
You were right. didn’t read correctly. Worked with using the defaultViewModelProviderFactory from the Activity. But now it crashes, when i enter a subview second time. SavedStateProvider with given key is already registered. Think i am still doing something wrong.
➕ 2
i

Ian Lake

09/17/2020, 9:51 PM
50/50 chance that it isn't your fault too. There's a reason that Navigation and Hilt isn't part of the current alpha release yet - still more to do 😄
👍 1
m

michaelevans

12/29/2020, 11:14 PM
@Alexander Karkossa did you ever solve this?
a

Alexander Karkossa

12/30/2020, 6:49 AM
Hey, this was a while ago, so I’ll try to get it together once. I found a way to use
Hilt
`ViewModel`s in
NavHost
, but I haven’t checked for a long time to see if it works without that workaround in the meantime.
class ViewModel(
  private val repository: Repository,
) : ViewModel() {

}

class ViewModelFactory(private val context: Context) : ViewModelProvider.Factory {

  @EntryPoint
  @InstallIn(ApplicationComponent::class)
  interface ViewModelProviderEntryPoint {
    fun repository(): Repository
  }

  @Suppress("UNCHECKED_CAST")
  override fun <T : ViewModel?> create(modelClass: Class<T>): T {
    val provider = EntryPointAccessors.fromApplication(context, ViewModelProviderEntryPoint::class.java)
    return ViewModel(
      repository = provider.repository(),
    ) as T
  }
}

@Composable
fun ComposeView(
  modifier: Modifier = Modifier
) {
  val viewModel: ViewModel = viewModel(factory = ViewModelFactory(AmbientContext.current))
}
View count: 1