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
hiring-french
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
e

Eko Prasetyo

05/15/2022, 2:10 PM
Hi everyone. I want to build authentication system for my app, and still a bit confuse on how to handle the flow. I always implement the A flow before, but the problem is I always see my Login Screen first, even it is only a glimpse. Which do you prefer between these flows? Is doing the B approach even possible?
t

trevjones

05/15/2022, 4:35 PM
B is how I implemented it in the Aetna Attain project. I did it as the chunk of logic that needs to run before dismissing the splash screen. Roughly 1- read state from disk and determine start destination 2- setup the nav graphs 3- callback at the end of first composition pass to dismiss
be warned if you go the splash screen route that you cant put critical logic in the exit anim listener. https://issuetracker.google.com/issues/216136037
c

Colton Idle

05/15/2022, 6:08 PM
Going off of the android nav docs (not even the compose specific docs) they tell you to use your "main" screen as your start destination. So then basically on that "main" screen you should check the state to see if you're logged in. If so, then you send the user to the login screen. When login completes, then you call pop back stack and the user is now back where they came from. This is super handy for cases where the user hasn't logged in yet, but maybe clicks on a deep link that takes them deep into the app somewhere. Login check occurs, then takes you to login screen if the check fails. User logs in. Pop backstack. Bam, you're taken right to the deep link.
Doing the login check per screen (or per destination) can sometimes eem a little backwards, but there are legit use cases for it. Ian taught me this. SO like if you're building twitter. There are a bunch of screens where login is optional. For example. You can install twitter, not use it. Then in an email click on a link to twitter. the twitter app opens to show you the tweet but it doesn't require you to be logged in. Once you click "like" tweet, then at that point your login screen might show. For apps that are like "I ALWAYS NEED MY USER TO BE LOGGED IN" I would still follow the idea that the home screen is the start destination but I'd maybe try to come up with some single helper to call everywhere.
z

Zach Klippenstein (he/him) [MOD]

05/15/2022, 8:31 PM
The best thing to do in a fully declarative/compose app is have some top-level thing in your UI determine whether there's a session or not, and then show the correct screen directly. Introducing the indirection of “imperative” navigation doesn't mean bugs like this are inevitable, but it's a lot easier to introduce them.
c

Colton Idle

05/15/2022, 10:19 PM
@ Zach does that still hold true for like the twitter scenario though? In that case wouldn't you want to handle it per destination? (e.g. viewing a tweet you can do while being logged out, but viewing a timeline requires you to be logged in)
z

Zach Klippenstein (he/him) [MOD]

05/15/2022, 10:59 PM
Absolutely. The screens requiring login can be wrapped in a composable that does the check and shows the login UI.
2
c

Colton Idle

05/15/2022, 11:03 PM
Thanks. I'm still learning but this login stuff legit makes my head hurt. It's like. It either works or it doesn't. But I'm also secretly scared that I'm introducing some sort of security hole by potentially doing this the wrong way. I.e what if the person can somehow get around the login screen and see the content underneath? I'm sure most of my worries are unjustified, but it's just something that always kind of lingers over my head
e

Eko Prasetyo

05/16/2022, 1:42 AM
I think I'll go with MAIN screen as my start destination, and wrap some features that require the user to be logged with conditional check. I guess it will make a better user experience as the user can see what are inside our app at the first launch and not forced to login. Thank you so much! @trevjones @Zach Klippenstein (he/him) [MOD] @Colton Idle
:kotlin-intensifies: 3
c

Colton Idle

05/26/2022, 8:38 PM
@Zach Klippenstein (he/him) [MOD] kinda come back to this late in the game... but I was thinking about what you said last night
The best thing to do in a fully declarative/compose app is have some top-level thing in your UI determine whether there's a session or not, and then show the correct screen directly. Introducing the indirection of “imperative” navigation doesn't mean bugs like this are inevitable, but it's a lot easier to introduce them.
So. That makes sense to me. Like total sense. (this is actually like week 1 of me being an android dev in 2012 and just swapping out R.layout.signin and R.layout.homescreen based on an if statement). BUT since this makes a ton of sense for me in the compose world... why do we even need compose-navigation? Wouldn't I want to modify that navigation stack directly instead of using this "event" based technique where the event callback bubbles up to the NavHost and the navhost calls
.navigate(OtherScreen)
?
z

Zach Klippenstein (he/him) [MOD]

05/26/2022, 8:52 PM
why do we even need compose-navigation
Short answer: Exactly! We don’t! 🙂 Longer answer: There are some navigation-related things that are pretty boilerplaty and helpful to factor out (e.g. state saving/restoration, maybe some common transition animations). I think an ideal navigation library for Compose would help solve those problems, but not try to manage its own source of truth for actual navigation. There are already a few libraries out there that do exactly that. I think (my personal opinion, not my employer’s) the only reason compose-navigation really exists is because it already existed for fragments, it’s been the “official” recommendation for navigation for some time, and it can be helpful when migrating a large app incrementally. It’s a lot easier to answer 100 “how do we do navigation” questions with “the same as before” than trying to get everyone to reconceptualize what “navigation” even is, and there are a limited number of devrels 😅
👍 1
This was the whole motivation behind compose-backstack, although that’s not maintained anymore and i think there are other, better, KMP, etc libraries out there at this point.
c

Colton Idle

05/27/2022, 2:16 PM
Thanks. Yeah I guess that's kinda my big light bulb moment a few months ago where it was like... wait... life is easier if i manage the state of my app. and then Adam gave great guidance on state vs events and stuff. but then it was like. wait. why dont i just have a NavBackStackState or something.
t

trevjones

05/27/2022, 2:19 PM
Same thinking applies to DI IMO. Why don't my DI scopes model my domain lifecycles instead of platform lifecycles? It's hard to do well. but quite nice when you get things all setup
🤯 1
1