https://kotlinlang.org logo
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
benchmarks
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
confetti
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
lincheck
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
Title
n

Nick

08/19/2022, 3:41 PM
This requires at least 1 value passed, and the second value was to avoid collision with the other signatures I think. But it might be possible to remove the need for the second view.
a

ayodele

08/19/2022, 5:26 PM
@Nick You mentioned bundle size as reason why widgets like
label
needs a behavior or theme for it to render. Can you shed more light?
n

Nick

08/19/2022, 7:09 PM
The issue is that any default logic for rendering will be included in the bundle since it won't be removed by Dead Code Elimination (DCE, or tree-shaking). So the bundle size will have a larger minimum. Then it will grow if you choose to customize the look/feel a lot in your app using custom `Behavior`s. So most views just do nothing to avoid that cost. This forces you to use a
Theme
or a
Behavior
directly. `Theme`s are easy to use though, so you don't really have to manually set `Behavior`s in most cases. Let me know if that answers your question.
a

ayodele

08/19/2022, 9:23 PM
@Nick Few more questions 1. Is doodle production ready? 2. Does doodle support SVGs? 3. I came across
container
but still don't know it's difference from
layout
n

Nick

08/20/2022, 1:45 AM
It's fairly well tested and good enough for production use in my mind. It does support SVG, if you mean rendering images. The country flags in the docs are all SVG images. There is also support for paths using SVG data. You can see how these are used in the Contacts app. A Container is a View that holds other Views. Technically all Views can hold others, but the View class hides this by default to avoid leaking internal details. This avoids code reaching into a composite View and messing with its children without it explicitly allowing it. Container exposes these aspects. A Layout is not a View. Instead, it manages the positions/sizes of a View’s children. Installing one to a View will make sure it gets invoked whenever the View changes size etc..
a

ayodele

08/20/2022, 9:48 AM
@Nick I have a top view that holds other views, laying them out using
constraint
layout, but one of the view(which is the last) it holds is a top view too that uses constraint layout in itself. But the inner top view does not render. Like it was ignored. Is it due to constraint layout??
n

Nick

08/20/2022, 3:19 PM
It sounds like the missing view is a child of the first AND you added it to the Display (to make it too-level). Let me know if I got that right. The Display works just like a container for views. Adding a view to it will remove the view from its current parent container. Are you trying to achieve a single view with some children? If so, you'd do the following, assuming topLevelView is a Container. Of course it could be any custom view that lets you setup its children as well.
// create children and specify their Layouts if they have children

tooLevelView = container {
    this += … // add nested children
    layout = constrain(…) { … } // setup topLevelView’s layout
}

display += topLevelView // show the view and all its children
The order of these operations can change of course. But the end result would be that Display holds ONLY the views at the top of your hierarchy, and those views hold children etc. Display - Child1 - GrandChild1 - … - Child2 - … Let me know if that's clear. If not, it would be easier to help if you shared a code sample of what you're trying to achieve.
a

ayodele

08/20/2022, 4:24 PM
So this is my topView
class TopView(textMetrics: TextMetrics): View(){
    init {
        val but = Button("Click", textMetrics)
        val innerView = InnerView(textMetrics)
        children += listOf(but, innerView)
        layout = constrain(but,innerView){ b1, b2 ->
            <http://b1.top|b1.top> = <http://parent.top|parent.top>
            b1.left = parent.left
            <http://b2.top|b2.top> = b1.bottom
            b2.left = parent.left
        }
    }
}
This is my InnerView
class InnerView(textMetrics: TextMetrics): View(){
    init {
        val but = Button("ClickInner", textMetrics)
        children += listOf(but, but)
        layout = constrain(but,but){ b1, b2 ->
            <http://b1.top|b1.top> = <http://parent.top|parent.top>
            b1.left = parent.left
            <http://b2.top|b2.top> = b1.bottom
            b2.left = parent.left
        }
    }
}
Then my app:
val vi = TopView(textMetrics)
        display += vi
        display.layout = constrain(vi){view ->
            view.width = parent.width
            view.height = parent.height
        }
But i get
circular dependency
error. Can you tell me what I did wrong
n

Nick

08/20/2022, 4:35 PM
You are trying to constrain the same view multiple times:
constrain(but, but)
. You are also adding that view to InnerView twice. Adding twice doesn't matter, but the current constraint impl can't deal with self references. This happens because b1 == b2 since you are constraining the same view. Surely this isn't what you wanted.
a

ayodele

08/20/2022, 5:24 PM
Yeah that was a mistake. Thanks.
So im able to run it successfully, but only the button in
TopView
was shown
n

Nick

08/20/2022, 5:27 PM
Looks like you haven't given the inner view a size, just a position. Set its size to some value in the constraint block.
I'm guessing the button gets its size from measuring it's contained text. This is why you didn't need to be explicit with it.
a

ayodele

08/20/2022, 5:33 PM
Yea, when i added a size to the
init
block of the
InnerView
it showed. Why does the
TopView
not need a size for the view to be rendered, but InnerView does?
n

Nick

08/20/2022, 5:46 PM
You set a size for
TopView
in the layout you assigned to the
Display
. The `Display`’s layout will affect all its children.
a

ayodele

08/20/2022, 6:29 PM
@Nick Aye captain. Thanks for your help so far 🙂
@Nick is there something like a
matchparent
in views or I'll have to pass around the display object?
n

Nick

08/20/2022, 6:59 PM
You can get a View’s
parent
. This is a
View?
which will be
null
if the view is top-level (or hasn't been added to any other view). Top-level views always have a
null
parent
(
Display
is not a
View
). Is your goal to get the
Display
, or just a view’s parent? You'll have to pass the
Display
around if other parts of your app want to use it.
View
actually always knows it's
Display
(once it has been shown). But that value is internal for now. You'll also notice that a View’s parent is just a plain
View
. This is intentional, and avoids leaking information about a View through its children.
What is
matchparent
by the way? Do you mean telling a view to fit the size of its parent? If so, you can use a layout on the parent that sizes the view to it. A constraint is a simple way (like you did before for the top view).
a

ayodele

08/20/2022, 7:55 PM
@Nick you mean setting size within the constraint with the
parent.height
and
parent.width
?
n

Nick

08/20/2022, 7:56 PM
Constraints aren't the only way to do layout by the way. The docs explain a bit more.
a

ayodele

08/20/2022, 8:11 PM
Yes! I could just quickly relate with constraint layout since I worked with it mostly on Android. Believe me, I'm just getting my hands wet here 😅
On mobile when I tap to click a button, i get ripple effect on the whole screen. Any idea why?
n

Nick

08/20/2022, 9:45 PM
Not sure what you mean. Can you share a video? Also, have you added the PointerModule to your app to ensure clicks work?
The latest release has a new constraint layout system that removes a lot of the limitations of the previous one. This system will be the only one in the upcoming 0.9.0 release. But you can start experimenting with it in 0.8.2.