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

    Colton Idle

    12/04/2020, 5:12 AM
    Are their docs for sample/common usages of each composable? I know I can look at the github sample apps but I really just want a page where I can see a list of components, and then the common methods I would use on them.
    a
    f
    • 3
    • 6
  • c

    codeslubber

    12/04/2020, 6:07 AM
    Image that takes a vectorResource and a modifier no longer compiles in alpha08?
    a
    v
    n
    • 4
    • 5
  • s

    Sam

    12/04/2020, 8:39 AM
    Not sure where to report this, but I’m having major problems deploying compose projects to a physical device over usb (Pixel 4a) using a new Apple Silicon Macbook Air. The phone seems to be keeping an old version, doesn’t matter if Run/Debug. Uninstalling the app is the only way for the deployment to correct launch the latest apk. This is on Android Studio Arctic Fox Canary 2 with Compose on latest alpha08. I’ve also tried with compose-samples (JetChat) and having the same problems. I have resorted to adding a dynamic buildCode to
    build.gradle
    which gets new deployments properly launched on the device:
    def buildCode = (int)(((new Date().getTime()/1000) - 1451606400) / 10)
    android {
        compileSdkVersion 30
        buildToolsVersion "30.0.2"
    
        defaultConfig {
            ...
            versionName "0.1.${buildCode}"
            ...
        }
    }
    I am not sure if this has to do with apple silicon, arctic fox, or alpha08?
    a
    c
    • 3
    • 9
  • r

    Rafs

    12/04/2020, 9:48 AM
    How do you add inner padding in compose?
    padding
    modifier only seems to add margin
    ✅ 1
    s
    • 2
    • 3
  • k

    Kshitij Patil

    12/04/2020, 10:15 AM
    Has anyone faced the problem of keyboard not showing up after focusing a textfield? I'm using an
    OutilnedTextField
    with
    savedInstanceState (<textfield-saver>) { TextFieldValue(state.text) }
    Putting app in background an reopening fixes this issue. I'm not sure if I'm doing any wrong or there's a subtle issue in compose
    ➕ 2
    v
    j
    +2
    • 5
    • 5
  • r

    Rafs

    12/04/2020, 12:18 PM
    How do I create a mini
    FloatingActionButton
    ➕ 1
    ✅ 2
    m
    • 2
    • 4
  • r

    Rafs

    12/04/2020, 1:21 PM
    Is there ayway to animate an
    ExtendedFloatingActionButton
    into a
    FloatingActionButton
    ?
    d
    • 2
    • 3
  • k

    Kshitij Patil

    12/04/2020, 3:24 PM
    What exactly happens when we do
    collectAsState()
    in it? Do I get a snapshot of snapshot of state and won't receive any further updates or will do? I've a navigation graph definition using navigation-compose and am using different viewModel for each of its screens. I'm doing
    collectAsState
    in the content parameter of
    NavGraphBuilder.comoposable()
    extension function. I want the respective Composable in the navgraph to be notified on any state changes in its associated viewModel. I checked every step in the process of mutating the state and viewModel state is working properly but the Composable is not listening to these changes and thus not being updated. How should this be achieved in general? Individual Composables listening to their own ViewModels when they're part of some navigation hierarchy like BottomNavigation ?
    a
    j
    • 3
    • 4
  • k

    Kshitij Patil

    12/04/2020, 5:14 PM
    I just realised there's one class Called
    ComposeNavigator
    which is supposed to handle backstack and create destination. Where can I find the example usage of it?
    i
    a
    • 3
    • 4
  • m

    Manuel Lorenzo

    12/04/2020, 5:49 PM
    hi everyone, I’m trying to upgrade a library from using alpha04 to alpha08 and I have added the following to the `build.gradle.kts`:
    android {
      buildFeatures {
            compose = true
        }
    
        compileOptions {
            targetCompatibility = JavaVersion.VERSION_1_8
            sourceCompatibility = JavaVersion.VERSION_1_8
        }
        composeOptions {
            composeOptions.kotlinCompilerVersion = versionsProperties["version.kotlin"].toString()
            kotlinCompilerExtensionVersion = versionsProperties["version.androidx.ui"].toString()
        }
    }
    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
        kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs = listOf("-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check")
            useIR = true
        }
    }
    However, I’m still getting the following error message for several classes:
    Class 'androidx.compose.ui.Modifier' is compiled by a new Kotlin compiler backend and cannot be loaded by the old compiler
    n
    • 2
    • 3
  • n

    Nat Strangerweather

    12/04/2020, 6:26 PM
    Hi, I have a list of composables that look like this (please see above). I have a Boolean called isDisabled, and I want to assign it to other composables when I select one of them. How can I achieve that? I have now spent two weeks trying everything I can think of, but with no success.
    f
    • 2
    • 2
  • s

    SrSouza

    12/04/2020, 6:44 PM
    HI folks, I was looking for a Table composable in the Internet, I found the DataTable but seems that was removed from the Compose Material, what composable is replacing it?
    a
    e
    h
    • 4
    • 3
  • b

    Bradleycorn

    12/04/2020, 7:16 PM
    Is there something equivalent to
    remember()
    but that launches its
    calculation
    in a coroutine scoped to the composable? Something like:
    val myVal by remember(viewModel) {
        viewModel.someSuspendingMethod()
    }
    My use case is that I have a
    suspend
    method in a ViewModel who’s return value I need to
    remember
    . Sure I could make the ViewModel method a “normal” method and use
    viewModelScope
    to launch a coroutine, but that is going to be scoped to the ViewModel, which itself is scoped to the Activity. I want it to be scoped to the composable (so that if the composable is removed from the tree, the coroutine is canceled). I guess I could use
    produceState
    for this? Is that the best way?
    val myVal by produceState(initialValue = "Loading...", subject = viewModel) {
       value = viewModel.someSuspendingMethod()
    }
    z
    s
    • 3
    • 18
  • b

    Bradleycorn

    12/04/2020, 7:34 PM
    If I could convince someone here to give me a nickel every time I write
    TextView("Some Text", modifier = …)
    instead of
    Text("Some Text", modifier = …)
    … man I’d be 💰
    😄 1
    h
    • 2
    • 2
  • g

    Grigoriev Dmitriy

    12/04/2020, 10:42 PM
    Guys, after migration to alpha08 I got the error "Unexpected exception thrown by non-Glide code" on the screen with GlideImage from Accompanist. Has anyone had a similar problem?
    b
    • 2
    • 1
  • v

    Vsevolod Ganin

    12/05/2020, 1:37 AM
    Is there a way to tell is a composable running in an initial composition or a recomposition? I’m building yet another screen transition composable based on
    Crossfade
    and I want it not animate anything on initial composition
    s
    z
    +3
    • 6
    • 14
  • c

    Colton Idle

    12/05/2020, 8:39 AM
    I have a list that I want to display, but each item in the list consists of a header and a sub list. This works, but I don't think the inner forEach loop is done correctly (this looks like it's not recycling the inner list)
    LazyColumn {
        item {
            Text("MAIN HEADER")
        }
        items(mylist.sections) { section: MyClass.Section ->
            Text(section.title)
            section.subsections.forEach {
                Text(it.body)
            }
        }
    }
    this does not work, but it's what I expected I should do
    LazyColumn {
        item {
            Text("MAIN HEADER")
        }
        items(mylist.sections) { section: MyClass.Section ->
            Text(section.title)
            item(sec.subsections) {
                Text(it.body)
            }
        }
    }
    a
    • 2
    • 13
  • n

    Nat Strangerweather

    12/05/2020, 11:21 AM
    compose-samples/Grid.kt at 1630f6b35ac9e25fb3cd3a64208d7c9afaaaedc5 · android/compose-samples (github.com) Layout is "undefined reference". What am I missing?
    l
    • 2
    • 2
  • k

    Kshitij Patil

    12/05/2020, 1:20 PM
    I'm using
    exoplayer
    with compose and for some reason the video is not getting shown. The audio starts playing as soon as the composable is rendered but video is not working. I've tried the latest version and
    2.11.7
    version of exoplayer and I'm currently using compose
    alpha07
    val context = ContextAmbient.current
    val exoPlayer = remember(mediaUri) {
        SimpleExoPlayer.Builder(context)
            .build()
            .apply {
                val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(
                    context,
                    Util.getUserAgent(context, context.packageName)
                )
                val source = HlsMediaSource.Factory(dataSourceFactory)
                    .createMediaSource(mediaUri.toUri())
                this.prepare(source)
            }
    }
    
    Box(
        modifier = Modifier.preferredSize(244.dp)
            .padding(vertical = 24.dp, horizontal = 8.dp)
            .clip(RoundedCornerShape(12.dp)),
    ) {
        AndroidView(
            viewBlock = { context ->
                PlayerView(context).apply {
                    layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
                    useController = false
                    resizeMode = RESIZE_MODE_ZOOM
                    player = exoPlayer
                    exoPlayer.playWhenReady = true
                }
            },
            modifier = Modifier.fillMaxSize()
        )
    }
    
    onDispose {
        exoPlayer.stop()
        exoPlayer.release()
    }
    Here is my implementation snippet, any help would be appreciated. Thanks!
    • 1
    • 1
  • d

    Daniele B

    12/05/2020, 1:56 PM
    Trying to summarize the difference between the apps of the “past” and the apps of the “future”:
    👍🏻 2
    j
    • 2
    • 25
  • b

    Bradleycorn

    12/05/2020, 3:33 PM
    Given this basic composable:
    @Composable
    fun FancyText(text: String) {
        val formattedText = remember(text) { computeTextFormatting(text) }
        Text(formattedText)
    }
    Is the use of
    remember
    necessary/valuable here? Seems like the only time this would get recomposed is if
    text
    changes, and in that case we’d want to re-compute the
    formattedText
    value. In other words, we’ll always re-compute the
    formattedText
    value, so do we even need
    remember
    ?
    👀 1
    d
    a
    +3
    • 6
    • 76
  • j

    Jeisson Sáchica

    12/05/2020, 5:21 PM
    Is there a way to achieve a behavior similar to the SnapshotMutationPolicy of MutableState with onCommit (or basically remember)?
    a
    • 2
    • 7
  • d

    Doris Liu

    12/05/2020, 10:37 PM
    Quick poll: If you could seek a
    Transition
    , would you prefer to seek by: 1️⃣ percentage based progress (0-1f), or 2️⃣ playtime (between 0 and total duration)?
    1️⃣ 16
    c
    b
    a
    • 4
    • 8
  • z

    zsperske

    12/06/2020, 3:26 AM
    Does anyone know how to resolve this?
    This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 4.3 or newer.
    r
    • 2
    • 3
  • j

    Jorge Rodríguez

    12/06/2020, 4:22 AM
    I’m having this issue:
    e: java.lang.IncompatibleClassChangeError: Found interface org.jetbrains.kotlin.ir.declarations.IrClass, but class was expected
    at androidx.compose.compiler.plugins.kotlin.VersionChecker.check(VersionChecker.kt:65)
    at androidx.compose.compiler.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:49)
    at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade$doGenerateFiles$1.invoke(JvmBackendFacade.kt:72)
    at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade$doGenerateFiles$1.invoke(JvmBackendFacade.kt:34)
    at org.jetbrains.kotlin.psi2ir.Psi2IrTranslator.generateModuleFragment(Psi2IrTranslator.kt:98)
    at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFiles(JvmBackendFacade.kt:87)
    at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.generateModule(JvmIrCodegenFactory.kt:40)
    at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:35)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:616)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:203)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:164)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:86)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:346)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:102)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:240)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:39)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:81)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:93)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:601)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:93)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1633)
    at jdk.internal.reflect.GeneratedMethodAccessor99.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
    e: java.lang.IncompatibleClassChangeError: Found interface org.jetbrains.kotlin.ir.declarations.IrClass, but class was expected
    Execution failed for task ':app:compileDebugKotlin'.
    > Internal compiler error. See log for more details
    a
    v
    • 3
    • 6
  • r

    Rafs

    12/06/2020, 9:18 AM
    So my previews are not deploying anymore
    c
    b
    • 3
    • 7
  • d

    Davide Giuseppe Farella

    12/06/2020, 10:23 AM
    Another question: why is this? 😄 I have ui-tooling, didn’t change the dependencies
    j
    • 2
    • 3
  • c

    Colton Idle

    12/06/2020, 10:49 AM
    1. Have Existing project that uses fragments 2. Enable compose in build.gradle via
    kotlinOptions {
            jvmTarget = '1.8'
            useIR = true
        }
        buildFeatures {
            compose true
            viewBinding true
        }
        composeOptions {
            kotlinCompilerVersion '1.4.20'
            kotlinCompilerExtensionVersion '1.0.0-alpha08'
        }
    
    ...
    
    implementation "androidx.compose.runtime:runtime:1.0.0-alpha08"
    3. Everything works fine 4. Add
    implementation "androidx.compose.ui:ui:1.0.0-alpha08"
    5. Every fragment in my app now has a red line on the class name (but still seems to build fine). Hovering over the error says "Class 'MyFragment' is not abstract and does not implement abstract base class member public abstract fun <I : Any!, O : Any!> prepareCall" Ideas?
    s
    • 2
    • 2
  • d

    darkmoon_uk

    12/06/2020, 10:58 AM
    One aspect of the way Compose handles ViewModels appears be quite troublesome... The default ViewModel factory invokes only the parameterless constructor of any ViewModel class. Clearly most ViewModels are going to need some dependencies; so parameterless construction implies that these are being provided externally i.e. by a DI framework. But what if you don't want to use a DI framework? This is not a problem if the default factory can be reassigned to one that allows you to perform your own construction, but it can't be. Yes; it's easy to create a
    ViewModelProvider.Factory
    with a lambda that constructs ViewModels with parameters, there is no way to assign this as the default factory. This entails that you either have to pass the factory around your composable functions to use it e.g.
    by viewModels(myFactory)
    or actually override the
    getDefaultViewModelFactory
    method. This is convenient enough in an
    Activity
    but becomes more troublesome if you try to do it for a
    NavHost
    . In other words the API design is coercing us toward using Dependency Injection frameworks in our ViewModels, rather than just plain construction. Whether you favour DI frameworks or not; construction parameters are objectively the primary mechanism in the Kotlin language for providing dependencies to an object: this at least implies that construction parameters should remain the first and best supported mechanism, followed by others. Am I missing something here or is there a case for Google to make these API's more flexible?
    i
    • 2
    • 7
  • o

    Oussama Haff.

    12/06/2020, 4:40 PM
    I noticed that elements in my
    LazyColumnFor
    don’t have the same rendering of the shadow despite of having a fixed elevation of
    4.dp
    on each material
    Card
    item. Am I missing something ? In the screenshots bellow I compare between the shadow of the first and the last elements in the list link to sources : https://github.com/hfrsoussama/android-conferences/blob/a8b3725f1f8ad6f995d04bc554[…]rc/main/java/dev/lesam/androidconferences/HomeScreenActivity.kt
    s
    • 2
    • 2
Powered by Linen
Title
o

Oussama Haff.

12/06/2020, 4:40 PM
I noticed that elements in my
LazyColumnFor
don’t have the same rendering of the shadow despite of having a fixed elevation of
4.dp
on each material
Card
item. Am I missing something ? In the screenshots bellow I compare between the shadow of the first and the last elements in the list link to sources : https://github.com/hfrsoussama/android-conferences/blob/a8b3725f1f8ad6f995d04bc554[…]rc/main/java/dev/lesam/androidconferences/HomeScreenActivity.kt
s

Sergey Y.

12/06/2020, 6:45 PM
It is how elevation works in Android. https://blog.usejournal.com/playing-with-elevation-in-android-91af4f3be596
✅ 1
👍 1
o

Oussama Haff.

12/06/2020, 6:54 PM
Thanks @Sergey Y. for sharing this, I have always worked with custom views so that I didn’t spot this slight variation before !
👍 1
View count: 3