https://kotlinlang.org logo
Docs
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
  • t

    Ttop

    09/10/2020, 2:39 PM
    Hi, I’m learning to use Compose and I’m trying to use Tab in a layout like this
    class TabContent(val header: String, val icon: Int, val content: @Composable () -> Unit)
    
    @Composable
    fun BodyContent() {
        var index = 0
        val updateTab : (currentIndex: Int) -> Unit = { index = it }
    
        val tabs = listOf(
            TabContent(
                header = stringResource(id = R.string.depenses_tab_title).toUpperCase(
                    Locale.getDefault()
                ),
                icon = R.drawable.ic_depenses
            ) { DepenseTabContent(Modifier) },
            TabContent(
                header = stringResource(id = R.string.equilibre_tab_title).toUpperCase(
                    Locale.getDefault()
                ),
                icon = R.drawable.ic_equilibres
            ) { Text ( text= "blop") }
        )
    
        BodyContent(index, updateTab, tabs)
    }
    
    @Composable
    fun BodyContent(
        selectedTabIndex: Int,
        updateTab: (Int) -> Unit,
        tabs: List<TabContent>,
        modifier: Modifier = Modifier
    ) {
        Column(modifier.fillMaxSize()) {
            TabRow(selectedTabIndex = selectedTabIndex) {
                tabs.forEachIndexed { index, tabContent ->
                    Tab(
                        selected = selectedTabIndex == index,
                        onClick = { updateTab(index) },
                        text = { Text(text = tabContent.header) },
                        icon = {
                            Icon(
                                vectorResource(id = tabContent.icon),
                                Modifier.width(24.dp).height(24.dp)
                            )
                        }
                    )
                }
            }
            Box {
                tabs[selectedTabIndex].content
            }
        }
    }
    My tab content is never displayed and I can’t refresh it by clicking in the tabRow. I don’t understand what I’v done wrong.
    👍 1
    t
    m
    • 3
    • 9
  • n

    Nat Strangerweather

    09/10/2020, 4:16 PM
    Could you please point me to resources about responsive layouts in Jetpack Compose? I have a UI which looks right on XL screens but really huge on smaller screens. I put my layout in a Column with max width and height so I thought the layout would be responsive in that sense, but it does not appear to be the case...
    r
    z
    +2
    • 5
    • 20
  • j

    jaqxues

    09/10/2020, 4:22 PM
    Is it intended behavior that the
    Switch
    invokes the
    onChangedActive
    after first composition? Because that sounds weird
    j
    m
    • 3
    • 8
  • m

    Mehmet Peker

    09/10/2020, 5:44 PM
    LazyColumnFor is cant smooth scrolling.What is the problem?
    z
    h
    • 3
    • 18
  • a

    andev

    09/10/2020, 6:10 PM
    Hi there, anyone managed to run compose + android kotlin extensions (synthetics)?
    c
    h
    • 3
    • 2
  • a

    andev

    09/10/2020, 6:10 PM
    still can not give it a try because of this issue
    s
    • 2
    • 1
  • l

    louiscad

    09/10/2020, 11:41 PM
    I'm curious about how we can make a manually scrollable marquee for long text, so I've asked how to on 😒tackoverflow: : https://stackoverflow.com/questions/63838973/how-to-make-a-manually-scrollable-marquee-by-touch-or-mouse-touchpad-scroll-in If one knows how, or if Jetpack Compose team can respond it's not supported yet, feel free to answer it.
    z
    • 2
    • 3
  • c

    Colton Idle

    09/11/2020, 5:19 AM
    Now that Kotlin 1.4.10 is out do I update this number in this block?
    composeOptions {
        kotlinCompilerExtensionVersion MyVersions.compose_version
        kotlinCompilerVersion '1.4.0' <====== This number
    }
    z
    • 2
    • 3
  • r

    Rafal

    09/11/2020, 8:16 AM
    Hi 👋 Is there any way to preview compose icons (e.g.
    Icons.Outlined.MailOutline
    ) in the IDE?
    ☝️ 1
    y
    • 2
    • 1
  • m

    Mehmet Peker

    09/11/2020, 9:28 AM
    How to programmatically take screenshot of composable function?
    ❓ 5
    m
    • 2
    • 2
  • r

    Rafal

    09/11/2020, 9:35 AM
    Noob question 🙈 - does
    Text
    have a way to all caps text or do I need to use
    String.toUpperCase()
    method?
    g
    • 2
    • 1
  • j

    Julius Marozas

    09/11/2020, 12:06 PM
    How can I animate FAB position from
    FabPosition.End
    to
    FabPosition.Center
    ?
    m
    • 2
    • 3
  • r

    Robert Menke

    09/11/2020, 2:46 PM
    So fwiw I do think I have my dagger hilt + compose example working as expected. I didn’t think that compose’s built in
    viewModel
    function would be compatible with Hilt’s system, which was my main mental hurdle. The following works just fine as far as I know. Are there any caveats to using this approach? Will this work fine for more complex scenarios?
    @AndroidEntryPoint
    class MainActivity: AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContent {
                MyApplicationTheme {
                    // A surface container using the 'background' color from the theme
                    Surface(color = MaterialTheme.colors.background) {
                        Counter()
                    }
                }
            }
        }
    }
    
    @Composable
    fun Counter() {
        val viewModel = viewModel<CounterViewModel>()
        val state by viewModel.counter.observeAsState(0)
    
        Column(
            modifier = Modifier
                .clickable(onClick = viewModel::increment)
                .padding(all = 36.dp)
        ) {
            Text(text = "Counter $state")
        }
    }
    
    @ActivityScoped
    class CounterViewModel @ViewModelInject constructor(): ViewModel() {
        private var _counter: MutableLiveData<Int> = MutableLiveData(1)
        val counter: LiveData<Int> = _counter
    
        fun increment() {
            _counter.value = _counter.value?.plus(1)
        }
    }
    h
    a
    s
    • 4
    • 5
  • a

    Arpan Sarkar

    09/11/2020, 2:48 PM
    when using
    repeatable { }
    is there any way to have a callback when the animation is repeated?
    d
    • 2
    • 4
  • g

    Guy Bieber

    09/11/2020, 4:38 PM
    I am using androidx.compose.material.Slider. Is there an easy way to change the orientation to vertical? Horizontal works great, but I can’t find a vertical example. It looks like material for angular has a simple vertical attribute.
    m
    • 2
    • 4
  • g

    Guy Bieber

    09/11/2020, 4:55 PM
    Is anyone having a problem with the Crane sample app not rendering google maps?
    ✋ 1
    a
    • 2
    • 1
  • d

    Daniele B

    09/11/2020, 5:28 PM
    I am starting to learn SwiftUI and it’s so much the same as JetpackCompose, much more than I expected! Just the syntax is different. At the same time, I also understand why JetpackCompose is not going to follow the same mobile cross-platform road of Flutter, by writing directly into the iOS canvas. I can see how SwiftUI is awesomely tight to the iOS framework, and how a “foreign” UI could never match that. I am very impressed by how the exact same SwiftUI control renders differently on iPhone, iPad, Mac or iWatch, and that is all managed by the OS framework. Given how similar the code structure between JetpackCompose and SwiftUI is, I believe transpiling from JetpackCompose to SwiftUI makes much more sense than JetpackCompose writing into iOS canvas. And I believe JetBrains is very much aware of that. Given their experience in this kind of stuff, they could probably create a JetpackCompose->SwiftUI transpiling tool that achieves perfection. For the same reason, I am really starting to understand the limitations of Flutter. It’s quite clear now that Flutter is just a toy project, which cannot stand the competition of native UIs. In the future much more than now, the quality of apps will depend on their native UI look and feel. Apps not implementing the native UI will be perceived of lower quality. I am pretty sure native UI in mobile is going increase its “market share” thanks to these new declarative UIs. In 2 years time we’ll see many more native UI apps than we see now. ReactNative, Xamarin or even Flutter will stand no chance.
    💯 1
    👏 5
    a
    c
    • 3
    • 5
  • c

    chris

    09/11/2020, 5:50 PM
    How can I get a composable preview to correctly tint a vector/drawable in an
    AndroidView
    based on the theme that is wrapping it? I'm using an
    AndroidView
    so that I can use an
    ImageView
    because I'm being passed a
    @DrawableRes
    and I don't know if it will be a vector or a drawable.
    z
    t
    • 3
    • 4
  • z

    zoha131

    09/11/2020, 9:09 PM
    Currently is there any way to create CollapsibleToolbarLayout in compose? With Scaffold compose?
    n
    y
    a
    • 4
    • 4
  • a

    Artem Kopan

    09/12/2020, 5:56 AM
    How to use AVD in Compose?
    n
    j
    k
    • 4
    • 3
  • v

    Venky

    09/12/2020, 10:43 AM
    can any one help me on getting compose samples into android studio. How should I do this? There always shows errors in Build log. Please tell me the correct way to import compose samples.
    y
    • 2
    • 3
  • n

    Nat Strangerweather

    09/12/2020, 10:59 AM
    I'm trying to understand how to use layouts. I have :
    Column(Modifier.fillMaxHeight()) {}
    Why are the bottom squares no reaching the bottom of the screen? I have not put any padding.
    y
    s
    • 3
    • 10
  • n

    Nat Strangerweather

    09/12/2020, 1:52 PM
    Is it possible to use
    val boxModifier = Modifier
        .fillMaxSize() or .fillMaxHeight()
        .weight(1f)
    while making sure that the box remains square, so basically, fill the maximum size/height as long as you are square? At the moment I have rectangles which is not looking great...
    h
    • 2
    • 2
  • i

    Ian Arbuckle

    09/12/2020, 2:03 PM
    Anybody receiving errors with Kotlin synthetic in 1.4.10 Kotlin with Compose in AS 4.2 Canary 10?
    e: java.lang.AssertionError: Unbound symbols not allowed
    My dependency versions: compose: 1.0.0-alpha02 kotlin: 1.4.10 android gradle plugin: 4.2.0.alpha10
    s
    r
    d
    • 4
    • 5
  • h

    Halil Ozercan

    09/12/2020, 3:04 PM
    Is there a reason why
    rememberDismissState
    doesn't receive
    vararg inputs: Any?
    kind of anchor to reset the state if some of the dependencies change? This certainly proved a challenge when I wanted to use
    SwipeToDismiss
    on list items. Because Lazy APIs reuse the same composable with different data, dismissState has to reset everytime the data changes.
    a
    s
    • 3
    • 5
  • m

    manueldidonna

    09/12/2020, 4:18 PM
    I tried to adapt the Activity Result api to compose but I don't think I've done a good job 😅 It works, but I believe there is a better way to do it. Any suggestions?
    @Stable
    @Composable
    fun <I, O> activityResultLauncher(
        contractKey: String,
        contract: ActivityResultContract<I, O>,
        activityResultCallback: ActivityResultCallback<O>,
    ): ActivityResultLauncher<I> {
        val lifecycleOwner = LifecycleOwnerAmbient.current
        val registry = ActivityResultRegistryAmbient.current
        val launcher = remember(contract, registry, contractKey) {
            registry.register(contractKey, lifecycleOwner, contract, activityResultCallback)
        }
        onDispose {
            launcher.unregister()
        }
        return launcher
    }
    
    @Composable
    fun ImportSaveDataFromFile(onImport: (SaveData?) -> Unit) {
        val context = ContextAmbient.current
        var launchActivity by savedInstanceState { false }
        val activityLauncher = activityResultLauncher("ImportSaveData", OpenDocumentContract) { uri: Uri? ->
            onImport(createSaveData(uri, context))
        }
        if (launchActivity) {
            launchActivity = false
            activityLauncher.launch(arrayOf("*/*"))
        }
        Surface(modifier = Modifier.fillMaxSize()) {
            Button(
                modifier = Modifier.fillMaxSize().wrapContentSize(Alignment.Center),
                onClick = { launchActivity = true }
            ) {
                Text(text = "IMPORT SAVE DATA")
            }
        }
    }
    a
    s
    • 3
    • 9
  • s

    Sourabh Rawat

    09/12/2020, 5:46 PM
    Getting external padding for topAppBar. Using MaterialTheme -> Surface -> Scaffold with topAppBar = TopAppBar(). (screenshot in the thread). Please help.
    m
    • 2
    • 6
  • v

    vipulasri

    09/12/2020, 8:44 PM
    Built JetInstagram an Instagram clone with Like Animation and Exoplayer integration for instagram reels feature. Code: https://github.com/vipulasri/JetInstagram
    👍 32
    👏 2
    h
    • 2
    • 2
  • e

    efemoney

    09/13/2020, 2:57 AM
    I’m trying to write a painter that can draw other Painters but I’m not sure what the draw code is supposed to look like. I have
    Contaner(val painters: List<Painter>): Painter {
      override val intrinsicSize = Size(
        painters.maxOf { it.width },
        painters.sumBy { it.heightRespectingAspectRatio }
      )
    
      override fun DrawScope.onDraw() {
        var offset = Offset.Zero
        painters.fastForEach { 
          it.??? // :( not sure what to place here, I dont have access to the draw method of the individual painters, how do I tell the painter to draw into the containers canvas 
        }
      } 
    }
    The end goal, if its clear from the
    Size
    calculation, is to create a painter that will place each individual painter, in a vertical column, kinda like stitching images together vertically. I want to then be able to run transformations on the container painter (scale, pan etc) driven by gestures.
    z
    n
    • 3
    • 2
  • e

    efemoney

    09/13/2020, 3:20 AM
    Algorithm is simple-ish, I want to track the offset of the current painter and draw it into the containers canvas, translating the canvas as necessary. With the
    View
    system I think it’ll be something like
    painters.forEach {
      canvas.withTranslate(offset.x, offset.y) {
        it.draw(canvas)
      }
      offset.y += it.heightRespectingAspectRatio
    }
    Not sure the equivalent in compose
    n
    • 2
    • 1
Powered by Linen
Title
e

efemoney

09/13/2020, 3:20 AM
Algorithm is simple-ish, I want to track the offset of the current painter and draw it into the containers canvas, translating the canvas as necessary. With the
View
system I think it’ll be something like
painters.forEach {
  canvas.withTranslate(offset.x, offset.y) {
    it.draw(canvas)
  }
  offset.y += it.heightRespectingAspectRatio
}
Not sure the equivalent in compose
n

Nader Jawad

09/16/2020, 1:02 AM
Painters are by default already translates such that the origin is always at (0, 0). This already happens by default within compose. If you want you can create a Painter implementation that wraps another Painter and translate the canvas accordingly for it as part of its onDraw implementation
View count: 1