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

    henrikhorbovyi

    07/07/2020, 6:44 PM
    How can I achieve a nested scroll with compose? 🤔
    m
    • 2
    • 11
  • s

    Sergey Y.

    07/07/2020, 7:26 PM
    Does Compose handle overdraw issue? How it will render multiple opaque overlaying layers?
    l
    n
    +4
    • 7
    • 27
  • a

    Anes

    07/07/2020, 7:50 PM
    Hi, I am new to compose and I am trying ConstraintLayout, I have this issue where the title is overlapping with favorite button, Any help is appreciated. Thank you.
    ConstraintLayout(modifier = Modifier.padding(16.dp)) {
            val (headerImage, title, subtitle, date, like) = createRefs()
            val modifier = Modifier
                .preferredHeight(180.dp)
                .fillMaxWidth()
                .clip(RoundedCornerShape(8.dp))
                .constrainAs(headerImage) {
                    top.linkTo(parent.top)
                    centerHorizontallyTo(parent)
                }
            Image(
                asset = image,
                modifier = modifier,
                contentScale = ContentScale.Crop
            )
            likeCounter(
                isFavorite = isFavorite.value,
                tintColor = colors.primary,
                updateCounts = { newValue -> isFavorite.value = newValue },
                modifier = Modifier.constrainAs(like) {
                    top.linkTo(headerImage.bottom)
                    end.linkTo(parent.end)
                }
            )
            Text(
                text = "Hello this is nothing from nothing withing " +
                        "nothing and usually besides nothing and embedded in nothing",
                style = typography.h6,
                maxLines = 2,
                overflow = TextOverflow.Ellipsis,
                modifier = Modifier.constrainAs(title) {
                    top.linkTo(headerImage.bottom)
                    start.linkTo(parent.start)
                    end.linkTo(like.start)
                    width to Dimension.fillToConstraints
                }
            )
    }
    a
    • 2
    • 4
  • h

    henrikhorbovyi

    07/08/2020, 1:48 AM
    Is there a
    GridLayout
    in Compose?
    z
    • 2
    • 3
  • a

    Alejandro Rios

    07/08/2020, 1:55 AM
    Hello, I'm trying to create a
    BottomAppBar
    inside a
    Scaffold
    , a simple one, but keeps showing me an error Type mismatch related to this
    ((BottomAppBar.FabConfiguration?) → Unit)?
    m
    • 2
    • 1
  • a

    Alejandro Rios

    07/08/2020, 1:55 AM
    this is my code
    @Composable
    @Preview(showBackground = true)
    fun DefaultRecipeCard() {
        Scaffold(topAppBar = {
            TopAppBar(
                title = {
                    Text(text = "ComposablecookBok")
                }
            )
        }, bodyContent = {
            RecipeList(defaultRecipes)
        }, bottomAppBar = BottomAppBar {
            Text(
                text = "Jetpack Compose",
                modifier = Modifier.padding(16.dp)
            )
        }
        )
    }
    n
    t
    m
    • 4
    • 5
  • a

    Alejandro Rios

    07/08/2020, 1:56 AM
    any idea of what's wrong with it?
    a
    • 2
    • 2
  • s

    Siyamed

    07/08/2020, 4:05 AM
    No, there is no min lines
    t
    s
    • 3
    • 7
  • s

    Siyamed

    07/08/2020, 4:06 AM
    You can set the height though?
    t
    • 2
    • 1
  • p

    pajatopmr

    07/08/2020, 6:07 AM
    Would I be correct in explaining the
    remember
    function as doing two things: 1) providing an initial value in performing a composition and 2) caching that value for subsequent compositions?
    v
    a
    • 3
    • 2
  • t

    Timo Drick

    07/08/2020, 8:51 AM
    Just recognized that Slider and Scaffold drawer does not support RTL layout. (infact the UI supports it but not the gestures when using them). Is this a known issue or should i create a bug report? I think the problem is that the grsture detection is not RTL aware but the UI is.
    m
    • 2
    • 3
  • c

    coolchandrakumar

    07/08/2020, 9:48 AM
    AndroidView(view = webview(ctx, "test"))
    Facing crash in Huawei device while using AndroidView for converting ClassicView to compose. It is working in emulator and samsung device
    fun webview(ctx: Context, html: String) = WebView(ctx).apply {
        Log.d("ChanLog", "webview: $html")
        this.webViewClient = WebViewClient()
        loadData("<html><body><h1>Ch($html)</h1></body></html>", "text/html", "utf-8")
    }
    at androidx.ui.core.AndroidViewsHandler.onDescendantInvalidated(AndroidViewsHandler.kt:40)
        at android.view.HwApsImpl.isNonEmptyFrameCase(HwApsImpl.java:353)
        at android.view.ViewGroup.invalidateChild(ViewGroup.java:5984)
        at android.view.View.invalidateInternal(View.java:17751)
        at android.view.View.invalidate(View.java:17702)
        at android.view.View.setFrame(View.java:22267)
        at android.webkit.WebView.access$701(WebView.java:107)
    Huawei_compose_crash.rtf
    m
    a
    • 3
    • 10
  • a

    AJ

    07/08/2020, 2:12 PM
    I have a
    ModelList
    of objects (like a
    Story
    object with a title and body). When updating an object in my
    ModelList
    , my UI doesn't change. However, if I add an element to the list, or just re-assign the entire list after changes, then the UI updates. Is this behavior expected? What is the best way to manage changing objects within a list that are represented on a Jetpack Compose UI, like in a VerticalScroller or LazyColumnItems so that it actually updates?
    a
    • 2
    • 5
  • j

    John O'Reilly

    07/08/2020, 5:08 PM
    I have a screen that's making use of
    AndroidView
    to contain a layout that in turn contains a
    com.google.android.gms.maps.SupportMapFragment
    . It works fine if that's only screen but just added some navigation and when I show another screen and then come back to this one again I'm getting following. Is there any recommended approach available right now to work around this?
    Binary XML file line #6: Duplicate id 0x7f08009a, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
    l
    i
    m
    • 4
    • 11
  • l

    Lilly

    07/09/2020, 12:32 AM
    Hi, would you guys say it is legit to use
    ConstraintLayout
    for all layouts. In non-compose layouts I used to use only
    ConstraintLayout
    for all layouts and never regret. I mean, are there any use cases where you would use
    Rows/Columns
    where
    ConstraintLayout
    wouldn't also fit?
    b
    g
    s
    • 4
    • 6
  • h

    Harish Gupta

    07/09/2020, 5:18 AM
    Hi, Is there any way i can do conditional rendering for the compose functions ?
    l
    • 2
    • 3
  • n

    Nikhil

    07/09/2020, 9:44 AM
    Hi, can someone guide me to the internals of the jetpack compose ? I’m already looking into the androidx-master-dev but is there any blog/document/written article to get to know the stuff inside of the compose ?
    z
    l
    • 3
    • 5
  • s

    SrSouza

    07/09/2020, 5:39 PM
    I saw the placeholders at the Compose sub repositories (Material, Foundation...), this means that when this modules get migrated to be a sub module of compose will be "Android Free", I mean that will be able to use in diferents targets like the WIP Desktop?
    l
    l
    • 3
    • 4
  • j

    Joe Jensen

    07/09/2020, 11:46 PM
    Hi Everyone! I'm currently investigating Jetpack compose and how it might work for our project going forward, but we are heavy users of Dagger in the current world of Android. One project I've been looking around in is the JetNews app, and there is no use of Dagger or Hilt. Any idea how Dagger/Hilt will play with Compose? I'd imagine composables would end up being injectable, just like fragments and activities are right now. Would appreciate any articles or references if this integration already exists 😄
    z
    j
    s
    • 4
    • 12
  • y

    Yamila Gammeri

    07/10/2020, 1:02 AM
    Hey everyone, I'm having issues with my vertical scroll while using a scaffold. Some of the items on my screen are going behind my tab bar. Was wondering what is the best practice to prevent that?
    n
    z
    +2
    • 5
    • 11
  • t

    Tolriq

    07/10/2020, 7:05 AM
    Really sorry about an offtopic question but there's all Android UI gurus here and I can't find any precise information about this 😞 What exactly is High input latency and what impact it? Vitals reports 300% for it and I can see the number growing from dumpsys but HWUI profile shows no issue and I can't find anything in systrace either.
    z
    • 2
    • 1
  • a

    aipok

    07/10/2020, 12:36 PM
    How should be handled
    onFocusChange
    for view in compose? I meant that keyboard is not always called automatically and we need a view reference in order to present it or hide it. It there any clean way to handle from composable?
    z
    • 2
    • 9
  • d

    Desmond Teo

    07/10/2020, 1:24 PM
    Hi! is there a way to achieve fillViewPort for VerticalScroller?
    m
    a
    • 3
    • 3
  • n

    nglauber

    07/10/2020, 2:27 PM
    Do I have to do something special to run tests in compose? I wrote this simple test on androidTest folder:
    @RunWith(JUnit4::class)
    class ExampleInstrumentedTest {
        @get:Rule
        val composeTestRule = createComposeRule()
    
        @Test
        fun testProductQuantity() {
            var quantity = 0
    
            composeTestRule.setContent {
                MaterialTheme {
                    MyComponent(onUpdate = { quantity += it })
                }
            }
            findByTag("Product_Inc")
                .doClick()
                .doClick()
    
            runOnIdleCompose {
                assertEquals(quantity, 2)
            }
        }
    }
    When I press the run button, I can see the loading on the Run panel on Android Studio, but after a few seconds I get this message:
    java.lang.AssertionError: Activity never becomes requested state "[CREATED, STARTED, RESUMED, DESTROYED]" (last lifecycle transition = "PRE_ON_CREATE")
    h
    a
    • 3
    • 12
  • c

    caelum19

    07/10/2020, 2:41 PM
    Hey y'all I've been working on this side project that I'm excited to share https://caelumf.github.io/FigmaToCompose/ It allows you to easily convert designs in Figma (a really cool design tool that you can use for free) to Jetpack Compose code, to more quickly get started when implementing designs. I made it for myself but figured it'd be fun to share so here you go. Any feedback very appreciated 🙂 Quick usage video:
    FTC.mp4
    🤔 2
    😲 14
    👏 47
    r
    • 2
    • 2
  • i

    iex

    07/11/2020, 10:03 AM
    I just started an Android app that I plan to release in at least 3 months and I'll be working alone on it. Would you recommend using Compose?
    🇳🇴 11
    t
    p
    +2
    • 5
    • 18
  • i

    iex

    07/11/2020, 10:31 AM
    lol, already the first issue running the first step in Google's tutorial:
    class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContent {
                Text("Hello world!")
            }
        }
    }
    java.lang.NoSuchMethodError: No static method setContent$default(Landroidx/activity/ComponentActivity;Landroidx/compose/Recomposer;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Landroidx/compose/Composition; in class Landroidx/ui/core/WrapperKt; or its super classes (declaration of 'androidx.ui.core.WrapperKt' appears in /data/app/com.match.android-863fKnuh3LTaDvTF4A7agg==/base.apk)
    a
    t
    • 3
    • 6
  • n

    nglauber

    07/11/2020, 1:59 PM
    Last month I saw a question here regarding WebView and handling touch events on
    AndroidView
    . Does this issue still happening? I have a layout with a
    TextView
    and a
    CalendarView
    and I’m just trying to show/hide the
    CalendarView
    when I click on the
    TextView
    . But the screen is frozen… 😕
    @Composable
    fun MyCalendar() {
        var currentDate by state { Date() }
    
        AndroidView(resId = R.layout.my_layout) { view ->
            val textView = view.findViewById<TextView>(R.id.txtDate)
            val calendarView = view.findViewById<CalendarView>(R.id.calendarView)
    
            calendarView?.visibility = View.GONE
            textView?.text = currentDate.toString()
            textView?.setOnClickListener {
                calendarView?.let {
                    it.visibility = if (it.visibility == View.VISIBLE)
                        View.GONE
                    else View.VISIBLE
                }
            }
        }
    }
    j
    p
    • 3
    • 3
  • s

    Socheat KHAUV

    07/11/2020, 3:56 PM
    I wanted to create a custom AndroidImageAsset
    Image(asset = CustomAndroidImageAsset(bitmap = p.bitmap))
    But some how when framework starting to draw the image. there is an implementation inside AndroidCanvas.kt call the following function
    image.asAndroidBitmap()
    This function always throw UnsupportedOperationException("Unable to obtain android.graphics.Bitmap") which is correct because my CustomAndroidImageAsset is not AndroidImageAsset. Mabye you could expose AndroidImageAsset for external use as well ?
    a
    • 2
    • 2
  • i

    iex

    07/11/2020, 7:01 PM
    It's interesting that there seem to be a lot of ways to manage state with Compose. The ones with mutability (e.g.
    Model
    annotation) don't resonate that much with me. I like the unidirectional flow with MVVM and live data. I'm considering implementing MVI like described here https://medium.com/swlh/android-mvi-with-jetpack-compose-b0890f5156ac but without the "innovation" of letting the state to directly create the Compose views. I'd let the fragment create those in response to the state. Are there any problems with this approach?
    a
    l
    • 3
    • 8
Powered by Linen
Title
i

iex

07/11/2020, 7:01 PM
It's interesting that there seem to be a lot of ways to manage state with Compose. The ones with mutability (e.g.
Model
annotation) don't resonate that much with me. I like the unidirectional flow with MVVM and live data. I'm considering implementing MVI like described here https://medium.com/swlh/android-mvi-with-jetpack-compose-b0890f5156ac but without the "innovation" of letting the state to directly create the Compose views. I'd let the fragment create those in response to the state. Are there any problems with this approach?
Specifically I wonder whether not using
MutableState
or
@Model
but instead pushing down immutable objects with all the state will turn off optimizations or something?
a

Adam Powell

07/11/2020, 7:19 PM
If the objects are marked
@Immutable
then they will be compared to previous parameter values and a composable function call will be skipped if the parameters are stable and equal
(immutable being a stronger form of stable here)
i

iex

07/11/2020, 8:48 PM
good to know! The article doesn't mention this
thanks
l

Leland Richardson [G]

07/11/2020, 9:55 PM
we are still playing around with some ways to infer immutability via whole program analysis potentially (or other means) and so haven’t spoken loudly about the @Immutable annotation so far as it may become unnecessary at some point
but as adam mentions, the compiler will use the @Immutable contract to make optimizations. Compose very much likes immutable objects wherever possible. The MutableState object just creates a single point of mutation that compose can deal with properly (with some useful guarantees that MutableState provides you) since most applications will need to have a point of mutation somewhere as state changes over time
i

iex

07/12/2020, 4:22 PM
thanks again for all the infos!
View count: 3