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

    ziv kesten

    12/12/2020, 8:13 AM
    I get a crush when i try to scroll fast using
    collectAsLazyPagingItems.
    compose versons: compose_version = ‘1.0.0-alpha07’ nav_compose_version =‘1.0.0-alpha02’ paging_compose_version = ‘1.0.0-alpha02’ The crash is:
    com.zk.trackshows E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.zk.trackshows, PID: 22201
        java.lang.IllegalArgumentException: Layer is redrawn for LayoutNode in state NeedsRelayout [LayoutNode@56ee45a children: 1 measureBlocks: androidx.compose.ui.layout.SubcomposeLayoutState$createMeasureBlocks$1@772aaf4]
            at androidx.compose.ui.node.LayerWrapper.invoke(LayerWrapper.kt:167)
            at androidx.compose.ui.node.LayerWrapper.invoke(Unknown Source:3)
            at androidx.compose.ui.platform.RenderNodeApi29$record$1$1.invoke(RenderNodeApi29.kt:159)
            at androidx.compose.ui.platform.RenderNodeApi29$record$1$1.invoke(Unknown Source:0)
            at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:1721)
            at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:128)
            at androidx.compose.ui.platform.AndroidComposeView.observeLayerModelReads(AndroidComposeView.kt:494)
            at androidx.compose.ui.platform.RenderNodeApi29.record(RenderNodeApi29.kt:158)
            at androidx.compose.ui.platform.RenderNodeLayer.updateDisplayList(RenderNodeLayer.kt:192)
            at androidx.compose.ui.platform.AndroidComposeView.dispatchDraw(AndroidComposeView.kt:563)
            at android.view.View.draw(View.java:22175)
            at android.view.View.updateDisplayListIfDirty(View.java:21024)
            at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4441)
            at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4414)
            at android.view.View.updateDisplayListIfDirty(View.java:20984)
            at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4441)
            at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4414)
            at android.view.View.updateDisplayListIfDirty(View.java:20984)
            at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4441)
            at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4414)
            at android.view.View.updateDisplayListIfDirty(View.java:20984)
            at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4441)
            at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4414)
            at android.view.View.updateDisplayListIfDirty(View.java:20984)
            at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4441)
            at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4414)
            at android.view.View.updateDisplayListIfDirty(View.java:20984)
            at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:582)
            at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:588)
            at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:665)
            at android.view.ViewRootImpl.draw(ViewRootImpl.java:4048)
            at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3757)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3026)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1963)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8237)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
            at android.view.Choreographer.doCallbacks(Choreographer.java:1041)
            at android.view.Choreographer.doFrame(Choreographer.java:953)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1220)
            at android.os.Handler.handleCallback(Handler.java:883)
            at android.os.Handler.dispatchMessage(Handler.java:100)
            at android.os.Looper.loop(Looper.java:214)
            at android.app.ActivityThread.main(ActivityThread.java:7711)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
    The crash does not happen when scrolling slowly. I am using RemoteMediator with local and remote data sources.
    a
    • 2
    • 2
  • v

    v79

    12/12/2020, 9:00 AM
    Just started having a look at Jetback compose.... decided it's not for me when I saw a variable declaration as `
    val count = remember { mutableStateOf(0) }
    I mean, what does that even mean? What's wrong with
    var count = 0
    or
    val count: IntWrapper = IntWrapper(0)
    .
    remember
    isn't listed as in import, control-clicking doesn't take me to a declaration. It's wilfully obtuse!
    a
    z
    c
    • 4
    • 11
  • n

    Nat Strangerweather

    12/12/2020, 9:11 AM
    Does anybody know where I can find out how to pass a variable from one Composable to another?
    j
    a
    • 3
    • 17
  • s

    Shakil Karim

    12/12/2020, 10:48 AM
    I am facing performance issues on some devices while using Compose, Specially on scrolling, Is it a known issue?
    a
    • 2
    • 2
  • c

    carbaj0

    12/12/2020, 2:09 PM
    java.lang.NoSuchMethodError: No interface method withRestorableState(Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;I)V in class Landroidx/compose/runtime/savedinstancestate/RestorableStateHolder; or its super classes (declaration of 'androidx.compose.runtime.savedinstancestate.RestorableStateHolder' appears in /data/app/com.acv.composeland-V85a_e5F918MbctysYPnqQ==/base.apk)
            at androidx.navigation.compose.NavHostKt.withRestorableState(NavHost.kt:143)
            at androidx.navigation.compose.NavHostKt.access$withRestorableState(Unknown Source:0)
            at androidx.navigation.compose.NavHostKt$NavHost$5.invoke(NavHost.kt:130)
            at androidx.navigation.compose.NavHostKt$NavHost$5.invoke(Unknown Source:10)
            at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146)
            at androidx.compose.runtime.internal.ComposableLambda.invoke(Unknown Source:10)
            at androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:187)
            at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:126)
            at androidx.navigation.compose.NavHostKt$NavHost$6.invoke(Unknown Source:8)
            at androidx.navigation.compose.NavHostKt$NavHost$6.invoke(Unknown Source:10)
            at androidx.compose.runtime.RecomposeScope.compose(Composer.kt:286)
    j
    • 2
    • 9
  • a

    Adriano Celentano

    12/12/2020, 3:18 PM
    any idea why my TextField input is jumping ?
    Bildschirmvideo aufnehmen 2020-12-12 um 16.09.41.mov
    • 1
    • 1
  • l

    Leon K

    12/12/2020, 5:57 PM
    Hey, I'm currently trying to implement an android on-screen keyboard, doing the UI with Jetpack compose if possible. I've gotten errors about missing ViewTreeLifecycleOwner, ViewTreeViewModelStoreOwner, and ViewTreeSavedStateRegistryOwner.... is it even possible to do this? given that the keyboard stuff seems to be handled via a View, could these even have a ViewTreeViewModelStoreOwner and stuff like that? It seems as though the Compose stuff is bound to running inside of an activity, which - as far as i can tell - doesn't translate to the Input Method API
    a
    h
    • 3
    • 22
  • r

    robnik

    12/12/2020, 6:56 PM
    I notice the JetNews sample uses it's own navigation ViewModel, instead of NavController and NavHost as documented here https://developer.android.com/jetpack/compose/navigation. The JetNews code looks easier to understand, and I'm wondering if there is a good reason to bother with NavController. I don't think it supports multiple back stacks (one per tab), which I want.
    r
    • 2
    • 2
  • r

    robnik

    12/13/2020, 3:31 AM
    I know there is a bug where
    LazyColumnFor
    does not remember things when items are removed and shifted. I heard that
    key(...)
    provides a workaround. I tried this, but it didn't work:
    LazyColumnFor(items = nums) { listNum ->
       key(listNum) {
          val r = remember { Random.nextInt(300) }
          Text("Num: $listNum, remembered: $r")
       }
    }
    nums
    is mutable state. When I remove the first item, all the remembered numbers change.
    a
    c
    +2
    • 5
    • 7
  • k

    Kshitij Patil

    12/13/2020, 4:52 AM
    Does this remember scroll position and
    snapToIndex
    APIs for LazyColumn are added in
    alpha08
    ? I'm using
    alpha07
    and I do get behavior of remembering scroll position on putting app background but it's not working when I switch the tab and come back (I'm using multi backstack Navigation) so I was expecting it to work
    a
    j
    • 3
    • 3
  • z

    zsperske

    12/13/2020, 5:39 AM
    is there a way to achieve negative padding? I'm implementing swipe to dismiss on a list and while I want my list item's content to be padded from the edge, I would like the red bar which appears as you swipe to have no padding and emerge from the edge
    r
    • 2
    • 1
  • s

    Spikey Sanju

    12/13/2020, 7:34 AM
    How to change the TextField text color in Jetpack Compose?
    val username = remember { mutableStateOf(TextFieldValue()) }
    TextField(
        modifier = Modifier.fillMaxWidth().padding(16.dp, 0.dp, 16.dp, 0.dp)
            .constrainAs(et_username) {
                top.linkTo(title.bottom, margin = 30.dp)
            },
        label = { Text(text = "Username") },
        leadingIcon = { Icon(Icons.Outlined.Person) },
        textStyle = typography.subtitle1,
        backgroundColor = MaterialTheme.colors.background,
        value = username.value,
        onValueChange = { username.value = it }
    )
    d
    k
    • 3
    • 3
  • z

    ziv kesten

    12/13/2020, 9:32 AM
    Having problems upgrading to compose alpah08. Project wont compile now with error:
    e: java.lang.NoSuchMethodError: e: java.lang.NoSuchMethodError:
    'org.jetbrains.kotlin.descriptors.DescriptorVisibility org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor.getVisibility()'
    compose versons: compose_version = ‘1.0.0-alpha08’ nav_compose_version =‘1.0.0-alpha02’ paging_compose_version = ‘1.0.0-alpha02’ kotlin version = ‘1.4.20’ Tried invalidating caches, restart, restart AS, restart Whole machine.
    j
    j
    v
    • 4
    • 6
  • t

    tieskedh

    12/13/2020, 2:59 PM
    How to align two texts of different sizes by their top?
    Row {
        Text(
            "h4 text",
            style = MaterialTheme.typography.h4,
        )
        Text("my icon")
    }
    I saw that fontsize had a lineHeight, and a baselineshift. The thing I don't get is that the baselineshift is a multiplier. How can I compute the top with it? Or is there some other way?
    d
    k
    v
    • 4
    • 15
  • r

    robnik

    12/13/2020, 3:01 PM
    Is there a good way to search the docs for given name/symbol from Jetpack Compose? For example, if I go to developer.android.com and search for "Text", all I get are two hits for org.w3c.dom.Text, and some other things - none of which are the Text composable.
    ➕ 2
    t
    b
    v
    • 4
    • 4
  • n

    Nat Strangerweather

    12/13/2020, 5:26 PM
    I'm testing this part of the documentation: https://developer.android.com/jetpack/compose/state#stateless-composables The problem is that
    observeAsState
    comes up as Unresolved Reference. Any ideas? I tried importing
    import androidx.compose.runtime.livedata.observeAsState
    but
    livedata
    is Unresolved...
    a
    • 2
    • 2
  • p

    Piotr

    12/14/2020, 2:29 PM
    Hi, i have a question regarding rtl support, is it possible to disable item (in this case linear progress indicator) from changing? I have an issue, that when i change to from ltr to rtl, the progress indicator, also changes positions(so it displays progress from right), i would like to disable that Thanks
    a
    • 2
    • 1
  • k

    Kshitij Patil

    12/14/2020, 9:27 PM
    A Custom View implementing
    onTouchEvent
    to handle some gestures doesn't allow gestures when used in a Composable using
    AndroidView
    . It used to work with compose
    alpha04
    (the last time I checked this Custom View). Currently I'm using
    alpha07
    and it's not working anymore. I tried putting that View in a xml file and inflating that layout instead which also didn't work. When I write entire screen in xml and use this View, everything works fine.
    r
    • 2
    • 1
  • s

    Sam

    12/14/2020, 10:05 PM
    Is there any way to create a pinterest (waterfall) style layout in jetpack compose? Ideally there would be a
    lazyGridFor
    that could have multiple columns that don’t require even-height rows, but i’d settle for fully rendering if it’s currently possible

    https://user-images.githubusercontent.com/29085/56487936-b3bc2c00-6491-11e9-8493-bb89c4f00a92.png▾

    a
    t
    • 3
    • 12
  • g

    gbaldeck

    12/15/2020, 1:48 AM
    Hi, I'm currently learning compose and am finishing up the Layouts codelab in the official docs. I am not a fan of how modifiers work, but it may be because I don't fully understand them yet. The main issue I have is this... order matters when placing modifiers, constraints flow right and size flows left. But how are you supposed to know if a constraint was changed or not? A good example is the padding and size modifiers example in the codelab. Padding does not change constraints, but size does. So placing padding before size and visa versa will have different results. It's not immediately apparent that padding does not change the constraints though. Unless there is something I'm missing, there isn't any way of knowing. With all the different types of modifiers that will be available, I can see loads of bugs arising from this. Is there any way to tell what constraints a modifier changes without looking at the source code?
    👍 1
    a
    c
    k
    • 4
    • 40
  • p

    Piotr

    12/15/2020, 2:07 PM
    Is there a way in compose to do some equivalent of
    android:includeFontPadding="false"
    I have a problem with font that, I believe, could be solved by using something like that, doing modifier.padding didnt work (border added to show whats going on):
    j
    • 2
    • 2
  • v

    Vincent tiensi

    12/15/2020, 2:10 PM
    Not sure if this is a bug or not but, when I create a scaffold, I have an event that triggers opening the drawer. However this only works once, once I fire more close events it doesn’t close the drawer.
    val state = viewModel.state.observeAsState().value ?: return
    val scaffoldState = rememberScaffoldState()
    when (state.drawerEvent?.consume()) {
        DrawerState.OPEN -> {
            scaffoldState.drawerState.open()
        }
        DrawerState.CLOSE -> {
            scaffoldState.drawerState.close()
        }
    }
    Scaffold(scaffoldState = scaffoldState)
    d
    • 2
    • 3
  • r

    robnik

    12/15/2020, 6:56 PM
    Documentation question... it took me too long to discover the extension function
    Bitmap.asImageBitmap(): ImageBitmap
    that I needed. It's not listed in either class's reference page. How is one supposed to find a function like that?
    d
    • 2
    • 4
  • n

    Nat Strangerweather

    12/15/2020, 9:14 PM
    Hi, I'm wondering if anyone would be willing to look at my code (a couple of composables) on Pastebin. The problem is that I am trying to pass my accentColor.value down from my first to my second Composable, and for some reason, this is only working for the last of my four accentColor values. I'm still learning and would be grateful for the help... 😊
    z
    r
    j
    • 4
    • 33
  • l

    laith

    12/15/2020, 9:22 PM
    Is Jactpack compose going to be widget rich same as flutter ?
    s
    z
    +2
    • 5
    • 12
  • v

    Vinay Gaba

    12/15/2020, 10:07 PM
    Nice comparison between Compose and Classic Android on certain parameters by @cb - https://twitter.com/AndroidDev/status/1338967071737196544
    🎉 19
    c
    c
    a
    • 4
    • 3
  • r

    robnik

    12/15/2020, 10:37 PM
    How do you observe a mutable object that fires events when it changes? Code that doesn't work...
    @Composable fun Things(model: MyViewModel) {
        val mutableThing = model.thing
        mutableThing.addChangeListener { recomposeThisStuff() }  
        Text("${mutableThing.size} ...")
    So "model.thing" may always be the same reference/object. But it changes internally.
    l
    a
    • 3
    • 13
  • d

    Dominaezzz

    12/16/2020, 12:09 AM
    There's a typo in the doc for
    InlineTextContent.children
    .
    j
    • 2
    • 2
  • l

    Luis Daivid

    12/16/2020, 8:41 AM
    When I have a Box component, I want to show the width from x=0px to x=100px transparently. How can I do it?
    d
    • 2
    • 3
  • a

    allan.conda

    12/16/2020, 8:48 AM
    maybe Modifier.drawBehind?
    l
    r
    n
    • 4
    • 16
Powered by Linen
Title
a

allan.conda

12/16/2020, 8:48 AM
maybe Modifier.drawBehind?
l

Luis Daivid

12/16/2020, 9:09 AM
Could it be implemented using clips?
drawBehind is so difficult..
a

allan.conda

12/16/2020, 9:11 AM
you wanted custom background behavior. I think it’s the only option
l

Luis Daivid

12/16/2020, 9:13 AM
I don’t want a custom background. I just want to crop part of the view.
r

robnik

12/16/2020, 11:51 AM
Crop or transparency? Those sound different to me. I just did something with cropping using
Modifier.clip(myShape)
where
myShape
is a
GenericShape { ... }
. In my preview I have a Slider that changes the width of the clip shape from 0 to 100%.
l

Luis Daivid

12/16/2020, 11:55 AM
@robnik Can i see code of myShape??
I think that is What i want!
r

robnik

12/16/2020, 12:04 PM
val myClip = GenericShape { size ->
    val right = size.width * fraction
    lineTo(right, 0f)
    lineTo(right, size.height)
    lineTo(0f, size.height)
    close()
}
And fraction is a float from state, getting moved by a slider.
l

Luis Daivid

12/16/2020, 12:04 PM
Thank you 😃
👍 1
n

Nader Jawad

12/16/2020, 6:33 PM
Just FYI,
GenericShape
will work here as a parameter to the clip modifier, however, because this is a rectangle, using
RectangleShape
to provide the clipping bounds will be more efficient as it would avoid software rasterization of paths
r

robnik

12/16/2020, 8:58 PM
@Nader Jawad The
RectangleShape
I see is a
val
. How do I use it? How do I give it a narrower width so that it actually clips the thing I'm trying to clip/crop?
n

Nader Jawad

12/16/2020, 8:58 PM
Just pass in that instance of
RectangleShape
Or you can create your own instance of Shape that creates a rectangle based on the percentage offset you wish to clip by
r

robnik

12/16/2020, 9:03 PM
Okay, I see - override
Shape
and return an
Outline
that is a
Rectangle
instead of a
Generic
, and get that performance benefit. Thanks!
l

Luis Daivid

12/17/2020, 12:48 PM
https://github.com/wooooooak/DragToPeekSurface-Compose I did it thanks to you guys. Thank you.
👍 1
a

allan.conda

12/17/2020, 2:16 PM
cool
View count: 4