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

    mcpiroman

    11/06/2021, 8:40 PM
    After reading this thread it seems like using Android's `LiveData`has no benefits over using standard Compose's `State`or coroutines'
    Flow
    . Yet, official jetpack compose codelab does use it quite extensively (although switches out of it at the end). If the first line is true, I think this guide should not suggest it at all, maybe just mention it as a possibility. Even if `LiveData`is as OK as the former options it introduces unnecessary complexity and decision-branches.
    t
    i
    • 3
    • 3
  • a

    Android75

    11/07/2021, 4:06 AM
    I'm studying Compose, ok it's wonderful but i have some doubts how i can use it in app production. App with 40-60 fragments Ok i tried Compose Navigation so my questions are: 1. can i use a screen compose for every hypothetical fragment? there are a lot of screen. 2. can i use fragments with compose UI and i use normal navigation component? 3. other ways
    r
    i
    a
    • 4
    • 11
  • a

    AmrJyniat

    11/07/2021, 9:55 AM
    Is there
    Icons.Unspecified
    like
    Color.Unspecified
    so if I passed it nothing will show as Icon?
    c
    • 2
    • 3
  • r

    Rafiul Islam

    11/07/2021, 2:12 PM
    I had seen Jim once say about this
    val activity = LocalContext.current as Activity
    But I never found the answer.
    a
    • 2
    • 10
  • t

    thelumiereguy

    11/07/2021, 4:19 PM
    When using GLSurfaceView inside AndroidView, it doesn't show up in Preview? I tried with normal views, and it worked fine.
    r
    • 2
    • 2
  • a

    Alexander Suraphel

    11/07/2021, 4:36 PM
    why is
    inline operator fun <T> State<T>.getValue
    defined as
    inline
    ?
    z
    • 2
    • 1
  • l

    Lilly

    11/07/2021, 11:01 PM
    I'm using
    SnapshotStateMap<String, Any>
    . Is it possible to perform a recompose based on the change of a specific key?
    z
    • 2
    • 2
  • p

    Pedram Keyani

    11/08/2021, 12:24 AM
    Is there any news about jetpack compose working for iOS as well? I'm loving the frameworks for building Android and Desktop but need to start getting my app to work for iOS and considering starting over with Flutter
    a
    • 2
    • 1
  • r

    rsktash

    11/08/2021, 2:59 AM
    Anybody who encountered issue with BottomSheetScaffold error when sheet content is empty there is a workaround for it. If we pass a composable with minimum height
    else {
      Box(Modifier.height(Dp.Hairline))
    }
    it won't crash.
    a
    • 2
    • 2
  • w

    w_bianrytree

    11/08/2021, 3:27 AM
    Do we have a channel only for Glance?
    z
    • 2
    • 2
  • t

    Tim Scheuermann

    11/08/2021, 4:32 AM
    Hello humans, how would someone do this in compose? I mean specifically the indention in the menu bar with the floating button embedded in it.
    s
    • 2
    • 2
  • z

    Zoltan Demant

    11/08/2021, 7:58 AM
    Has anyone noticed any performance issues when targeting compose
    1.1.0-beta02
    ? I cant exactly pinpoint what is causing it, but jank seems to build up over time as you use the app when targeting this release (it sounds like a leak, but Ive tested for that thoroughly).
    f
    • 2
    • 3
  • z

    Zoltan Demant

    11/08/2021, 11:42 AM
    When using
    flow.collectAsState
    inside a composable, if the flow I pass in changes, the last value from the old flow seems to be collected again before the new flow kicks off. 🧵👀
    c
    j
    +2
    • 5
    • 26
  • r

    Rick Regan

    11/08/2021, 3:24 PM
    I'm tracing through composition during device rotation and I see behavior I wasn't expecting. I ran this composable in a Pixel 4A on the emulator:
    @Composable
    fun Dimensions() {
      BoxWithConstraints {
        val orientation = if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT) "P" else "L"
        println("$orientation: w = $maxWidth, h = $maxHeight")
      }
    }
    I started in portrait orientation and then rotated the device left 8 times (with
    android:screenOrientation="fullUser"
    to allow it to render upside down). There were three unexpected things about the output: (1) Duplicate messages for a given rotation (2) Change in orientation is not in sync with the change in dimensions (3) Incorrect intermediate dimensions (1) I suppose is just Compose working as advertised (duplicate recompositions), but (2) and (3) I don't understand. (See 🧵for details.)
    a
    • 2
    • 7
  • j

    Joseph Hawkes-Cates

    11/08/2021, 7:17 PM
    I’m working on creating a password field for my app using a TextField with a leading and trailing icon. My UI design calls for a different color for the leadingIcon background than the rest of the TextField. I tried to implement that by setting the background color on my IconButton in my LeadingIcon compose function, but it looks like there is some padding above and below the icon which is using the TextField’s background color. Is there any way to remove that padding or set the leadingIcon background color somewhere else so the entire leading section is one background color? I could build it out myself by moving the icon out of the TextField, but then I’ll lose a bunch of little default visual behaviors so I’d like to avoid that if possible. See code within the thread. The attached screenshot has what my preview looks like below.
    :thread-please: 1
    ✅ 1
    c
    a
    • 3
    • 20
  • k

    krzysztof

    11/08/2021, 9:19 PM
    I’m going through updated docs on Compose state handling and I have one question regarding one approach (more in 🧵 )
    z
    a
    a
    • 4
    • 15
  • s

    Skc

    11/08/2021, 11:22 PM
    Appreciate any help here, https://kotlinlang.slack.com/archives/C0B8M7BUY/p1636413414348900
    c
    • 2
    • 1
  • f

    Filip Wiesner

    11/09/2021, 10:41 AM
    Is Material Design 2 library going to be deprecated eventually? There are a lot of changes with M3 that I am not sure I want to do right now. But if I'll have to migrate, it might be better to do it sooner rather than later. What is the generally recommended approach since refactoring will be a lot of work.
    s
    s
    +3
    • 6
    • 13
  • a

    Arpit Shukla

    11/09/2021, 11:11 AM
    How to pass events to Composables? I have a composable
    C1
    which collects an event Flow from a view model.
    C1
    calls another composable
    C2
    passing some data and lambdas.
    C2
    contains a Scaffold. Now when my ViewModel sends an event of showing a snackbar (after doing some validation when user clicked a button), I want to pass that event to
    C2
    . How can I do this?
    👀 1
    z
    a
    a
    • 4
    • 10
  • m

    Mehdi Haghgoo

    11/09/2021, 12:53 PM
    When is it generally OK to use capital variable names? For example, is it fine to use
    LocalInfo.current.bottomBarItems
    as part of my CompositionLocal or should it be BottomBarItems?
    b
    a
    • 3
    • 2
  • a

    Arpit Shukla

    11/09/2021, 12:58 PM
    How bad is it to send a
    Flow
    from one composable to another? (The flow is created and its value is modified outside composition)
    z
    • 2
    • 1
  • m

    Mehdi Haghgoo

    11/09/2021, 12:59 PM
    I'm having a hard time aligning bottom navigation items. The icons stick to the top, no matter how I modify items or icons. More in thread.
    a
    • 2
    • 9
  • i

    iamthevoid

    11/09/2021, 1:38 PM
    I want to show 
    ModalBottomSheetLayout
     on user action. I have a component in app, that called 
    ActionSheet
     and wrap 
    ModalBottomSheetLayout
    . It pass 
    ModalBottomSheetState
     from outside by composable function params, other params for 
    ModalBottomSheetLayout
     assigns under the hood [thread]. Also there is 
    MutableStateFlow
     [somewhere in app, doesnt matter], that typed with 
    ActionSheetCommand
     type. When user do the action then concrete implementation of 
    ActionSheetCommand
     emits through the `MutableStateFlow`[thread]. 
    ActionSheetWrapper
     [thread] - another wrapper around 
    ActionSheet
    , collect these emits and show `ActionSheet`(
    ModalBottomSheetLayout
    ) using state, that initialized in 
    ActionSheetWrapper
    . Somewhy 
    ModalBottomSheetLayout
     opens only on first emit. All next emits even not printed inside
    emit
    function of collector. Why can it be? Looks like
    emit
    function in collector somehow deadlock queue and next emits just not pass through
    MutableStateFlow
    .
    • 1
    • 9
  • t

    tylerwilson

    11/09/2021, 2:23 PM
    I am constructing a UI with Compose, using .dp as units. And I am also using detectTapGestures / onTap to get an offset, but it appears to be in pixels, not dp. Is there a Compose way to get the dp value from the offset value? Thank you!
    c
    g
    a
    • 4
    • 5
  • m

    Mehdi Haghgoo

    11/09/2021, 2:58 PM
    I have created a state holder containing some states of my app, e.g. RECORDING, PLAYING, etc. But, changes I make to the state do not invoke recomposition. Continued...
    z
    • 2
    • 2
  • m

    Mehdi Haghgoo

    11/09/2021, 3:10 PM
    Why isn't the source code for Compose runtime 1.1.0-beta02 (like remember()) available in Android Studio? I tried downloading using the Download Sources button, but failed.
    ➕ 1
    • 1
    • 1
  • a

    Arjun Achatz

    11/09/2021, 5:19 PM
    Question : I'm using compose and listening to the interactionSource in my button to change colors on the on pressed. However if I tap gently I get a ripple, and if I press a little harder I get the on pressed state change ... What's with this lag ? Is this a known bug or just how compose works ?
    l
    • 2
    • 15
  • a

    alorma

    11/09/2021, 5:55 PM
    Some days ago our team was playing around with tests and I found a potential problem on using
    testTag
    as identifiers for composables, as those use String. And as we have it harcoded all around the composables (like
    Modifier.testTag("RowItem")
    ) and then use
    "RowItem"
    on tests... with possible issue when renaming one or other... I've played a bit with it and came up for possible solution on not duplicating the strings... Would these make sense on compose?
    m
    d
    • 3
    • 5
  • r

    Roberto Leinardi

    11/09/2021, 8:14 PM
    So, how bad would it be to persist the same instance of
    ScaffoldState
    across the entire application (e.g. via singleton in Hilt)? I have the feeling that would be really bad but I can't think of another way to solve this issue: https://stackoverflow.com/questions/69902988/how-to-show-snackbars-from-composables-or-viewmodels-on-a-multi-module-single-a
    ➕ 1
    t
    • 2
    • 16
  • s

    Steffen Funke

    11/09/2021, 9:19 PM
    I have a plain old
    BottomSheetDialogFragment
    (can’t change that to Compose unfortunately), which contains a
    LazyColumn
    . I am kind of stuck figuring out, why the scrolling does not work as expected, e.g. why the
    BottomSheetDialogFragment
    intercepts the
    LazyColumn
    scrolling. Is there any flag / setting / modifier for
    LazyColumn
    regarding nested scrolling, that I am missing? Expected behaviour would be that I can drag the Sheet down as soon as I have scrolled up completely, but not before. Cannot convert it to a
    Column
    though, since the items need to be lazy loaded. 👉 Video attached in 🧵. Any ideas welcomed. Thank you!
    w
    • 2
    • 17
Powered by Linen
Title
s

Steffen Funke

11/09/2021, 9:19 PM
I have a plain old
BottomSheetDialogFragment
(can’t change that to Compose unfortunately), which contains a
LazyColumn
. I am kind of stuck figuring out, why the scrolling does not work as expected, e.g. why the
BottomSheetDialogFragment
intercepts the
LazyColumn
scrolling. Is there any flag / setting / modifier for
LazyColumn
regarding nested scrolling, that I am missing? Expected behaviour would be that I can drag the Sheet down as soon as I have scrolled up completely, but not before. Cannot convert it to a
Column
though, since the items need to be lazy loaded. 👉 Video attached in 🧵. Any ideas welcomed. Thank you!
bottomsheet.mp4
This SO post is basically my problem: https://stackoverflow.com/questions/69770777/compose-lazycolumn-scrolling-behavior-inside-of-coordinatorlayout-via-composevie
w

Will Shelor

11/10/2021, 3:33 AM
I encountered this issue as well. BottomSheet has a method that it calls on the View class to identify if the class is scrollable. Compose does not implement this class, so unfortunately nested scrolling is not functional. I tried for about a day to find a workaround, but in the end did not find any. I ended up needing to implement my own, which subclassed DialogFragment and set a Compose scaffold as its content.
It was one of my first experiences with Compose. 🙂 I will say, implementing the Nested scrolling behavior was so much easier in compose than in the old system!
here’s a super quick idea of what it looks like (I removed all our custom classes, so it might not work out of the box- you’ll probably need to make some adjustments)
class ComposeBottomSheetDialogFragment(
    val sheetContent: @Composable ColumnScope.() -> Unit
) : DialogFragment() {
    private var onDismissListener: (() -> Unit)? = null

    @OptIn(ExperimentalMaterialApi::class)
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View {
        super.onCreateView(inflater, container, savedInstanceState)
        setStyle(STYLE_NO_FRAME, R.style.FullScreenDialog)
        dialog?.let {
            val width = ViewGroup.LayoutParams.MATCH_PARENT
            val height = ViewGroup.LayoutParams.MATCH_PARENT
            it.window?.setLayout(width, height)
            it.window?.setBackgroundDrawable(ColorDrawable(resources.getColor(R.color.transparent)))
        }

        return inflater.inflate(R.layout.fragment_checkout_landing_screen, container, false).apply {
            this.findViewById<ComposeView>(R.id.compose_view).apply {
                setContent {
                     // your content
                }
            }
        }
    }

    override fun getTheme() = R.style.FullScreenDialog

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
        onDismissListener?.invoke()
    }

    fun setOnDismissListener(function: () -> Unit) {
        this.onDismissListener = function
    }
}
and here is the theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="FullScreenDialog" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:padding">0dp</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowCloseOnTouchOutside">false</item>
    </style>
</resources>
note that some of this might be unnecessary for you.
s

Steffen Funke

11/10/2021, 5:18 AM
Hey @Will Shelor , awesome, thanks for taking your time 🙏 As I see it, this will then not allow swipe to dismiss, correct? So you would only be able to explicitely close the dialog via button, etc? Actually that is something I want to avoid. 🤔 I have also played around with
isCancelable
in the BottomSheetDialogFragment…. But swipe to dismiss is nice and I would like it to keep, if I can.
It was one of my first experiences with Compose.
Yeah feels like learning something new everyday again 😆
w

Will Shelor

11/10/2021, 5:20 AM
ha! You’ve gotten into complicated territory! We made a custom bottom sheet for just this reason. We copied the base idea of the accompanist bottom sheet scaffold and made our own with some custom behavior. It was a great introduction to the concepts of what compose does
🔥 1
🤔 1
s

Steffen Funke

11/10/2021, 5:22 AM
Update: I got at least the BottomSeetDialogFragment to not intercept my touch event with this Modifier here - but then my
LazyColumn
denies scrolling… But I feel I might have to dig deeper there, “halfway there”:
val lazyListState = rememberLazyListState()
val disallow = RequestDisallowInterceptTouchEvent()

LazyColumn(
    modifier = Modifier
        .pointerInteropFilter(requestDisallowInterceptTouchEvent = disallow, onTouchEvent = {
            when(it.action) {
                MotionEvent.ACTION_DOWN -> {
                    disallow(true)
                    return@pointerInteropFilter true
                }
                MotionEvent.ACTION_UP -> {
                    disallow(false)
                    return@pointerInteropFilter false
                }
            }
            true
        })
        .fillMaxWidth(),
    state = lazyListState
) {
.... items content
We made a custom bottom sheet for just this reason. We copied the base idea of the accompanist bottom sheet scaffold and made our own with some custom behavior.
So it keeps being swipe to dismissable? Mind to share some insights in how you tackled the nested scrolling part in the custom behavior? Probably would make a good stackoverlfow answer as well 😄
w

Will Shelor

11/10/2021, 5:26 AM
I added a quick version of this discussion to that question; it’d be tough without open sourcing it because there is so much required, and I’m not 100% sure it’s ready for it 😆 it’s pretty custom to our application at this point
:thank-you: 1
s

Steffen Funke

11/10/2021, 5:36 AM
There is a method on View called isNestedScrollingEnabled(), and Compose always returns false,
Mind if I ask where you found that call, and that compose returns false? Maybe subclassing
ComposeView
(like with those old ViewPager hacks to allow nested scrolling) would be worth looking into 🤔.
But then again, probably its easier to change my requirements 😬
I figured the
RequestDisallowInterceptTouchEvent
could be a lead, but no luck for now. I feel I’ll have to read myself back in touch event internals.
w

Will Shelor

11/10/2021, 7:02 AM
I found isNestedScrollingEnabled in BottomSheetBehavior in the Material library, line 1210, after a day of walking through and trying to figure out why it didn’t like my compose view as a nested scroll target. I also hunted for a way down the path you’re talking about here. I tried 6 or 7 things when I just decided to convert the whole thing to Compose. Our research found that was better for performance anyways, so it wasn’t a hard sell to the team. 🙂
View count: 4