Slide 1

Slide 1 text

A guide to Compose on desktop for the curious Android dev Sebastiano Poggi What about... a desktop app? @seebrock3r

Slide 2

Slide 2 text

Setting expectations

Slide 3

Slide 3 text

Different mindset Desktop-only APIs may differ Same idea

Slide 4

Slide 4 text

Different mindset Desktop-only APIs may differ Same idea

Slide 5

Slide 5 text

Notable differences • Lifecycle is much easier • Window chrome, menu bars, tray icons • Less restrictions • E.g., full filesystem access, no permissions system • Some things require "going down" • Swing and/or P/Invoke via JNI

Slide 6

Slide 6 text

https://www.jetbrains.com/toolbox-app/ https://github.com/theapache64/stackzy

Slide 7

Slide 7 text

it's beta Some stuff may be missing or broken Builds upon Jetpack Compose stable

Slide 8

Slide 8 text

Getting started

Slide 9

Slide 9 text

GOTO: https:!"github.com/JetBrains/compose-jb/ Compose for Desktop sources repo

Slide 10

Slide 10 text

Hold on! Only one link to write down: https:!"go.sebastiano.dev/desktop-app-2021 Look out for the symbol

Slide 11

Slide 11 text

IDE support • Compose Multiplatform plugin • Also supports web • Android Studio and IntelliJ IDEA • Tooling is lagging behind Jetpack Compose's • No interactive preview and animation inspector • Missing many quality-of-life tweaks

Slide 12

Slide 12 text

Familiar faces • Core Compose libraries: runtime foundation ui material • Same packages and API names as Jetpack Compose • Compose compiler plugin • Requires Kotlin (duh)

Slide 13

Slide 13 text

What's different

Slide 14

Slide 14 text

Android-only APIs • No access to anything outside: • androidx.compose.* • java.* • kotlin.* • No permissions • No Android-only dependencies • Architecture Components • Other Jetpack libraries • Firebase • etc What's different Old-school UI Resources a11y UI testing

Slide 15

Slide 15 text

What's different • No Android Views • MapView, etc • No WebView equivalent • Interop with "classic" Java UI • Swing hosts Compose • Compose can wrap Swing • No activities and fragments • Different (easier) lifecycle • Swing windows Android-only APIs Old-school UI Resources a11y UI testing

Slide 16

Slide 16 text

What's different • Java resources system • No buckets • No concept of configuration • No orientation, display size, etc • I18n support is not built in • No RTL support yet • No animated GIFs • No animated vector drawables • Non-animated are supported • Resource refs not resolved • Lottie not supported yet • Maybe Skottie in the future? Android-only APIs Old-school UI Resources a11y UI testing

Slide 17

Slide 17 text

What's different • APIs are there, but not hooked up • semantics() • Work in progress • Should be there for 1.0.0 • Current state: • Mostly works on macOS • Other OSes done next • No clue about ETAs, sorry Android-only APIs Old-school UI Resources a11y UI testing

Slide 18

Slide 18 text

What's different • Not entirely true, it's mostly the same • UI testing is the same as on Android • Except, of course, (much) faster • Use createComposeRule() • Additional API (e.g., mouse scroll) • Fun idea: run your UI tests on CfD • Screenshot testing is different • TestComposeWindow • WIP: APIs for animations Android-only APIs Old-school UI Resources a11y UI testing

Slide 19

Slide 19 text

Unique features

Slide 20

Slide 20 text

Unique features • Desktop is different from mobile • Unique needs == unique features • Windowing • Multiple windows at the same time • Compose handles JFrames for you

Slide 21

Slide 21 text

Unique features • Enhanced keyboard support • Keyboard shortcuts • Tooltips • Menus, tray icons, desktop notifications • Native installers (msi/exe, dmg/pkg, deb/rpm) • Output size saving tips • Notarization for macOS

Slide 22

Slide 22 text

Unique features • Scrollbars • Yes, Jetpack Compose still doesn't have those • Works with scroll modifiers and LazyColumn/LazyRow • Mouse events • Pointer movement (hover) • Modifier keys and mouse buttons

Slide 23

Slide 23 text

Unique features • Desktop-only components & integrations • Split panel • Video player • CEF-based WebView (outdated) • LWJGL integration

Slide 24

Slide 24 text

Unique features • Desktop-only components & integrations • Split panel • Video player • CEF-based WebView (outdated) • LWJGL integration EXPERIMENTAL

Slide 25

Slide 25 text

Libraries

Slide 26

Slide 26 text

Libraries • A lot of JVM-only libraries out there • Some direct replacements • Some Android libs make no sense on desktop • Well, most don't • Some Accompanist libs work on desktop • Pager, Placeholder, FlowLayout, Swipe-to-Refresh (?)

Slide 27

Slide 27 text

Libraries • No Play Services • No Firebase • Java or REST APIs for some • No Architecture Components • No ViewModel, Navigation, Room, Hilt, etc

Slide 28

Slide 28 text

Library alternatives Navigation Decompose Room SqlDelight Hilt Dagger Timber Arbor Coil/Glide/Picasso/... Hand-rolled ! ViewModel Essenty's InstanceKeeper (but it's not really the same)

Slide 29

Slide 29 text

Theming

Slide 30

Slide 30 text

Theming • Material theme is fully supported • Material You will, as well • Material is not great on desktop • Huge touch targets for use with mouse • There is no "official" desktop-oriented UI framework

Slide 31

Slide 31 text

Kirill Aurora Grouchnikov's

Slide 32

Slide 32 text

Distribute your app

Slide 33

Slide 33 text

Distribute your app • Gradle tasks to build installers • OS-specific outputs • macOS is different • Requires notarisation • Signing to make Gatekeeper happy • Only required to distribute, not to run locally

Slide 34

Slide 34 text

Life outside app stores • No Play Store, Amazon Appstore, Samsung App Gallery • No auto-updates, built-in licensing and IAB • Some Java libs may help to compensate (e.g., update4j) • You may be able to publish on OS stores... • But mileage may vary • May be harder on macOS App Store

Slide 35

Slide 35 text

Closing remarks

Slide 36

Slide 36 text

Closing remarks • Kotlin Multiplatform support • Share business logic • Share some degree of UI code (Android and Desktop) • Web is totally different, hard to share • Check out Jake Wharton's Mosaic

Slide 37

Slide 37 text

Go and try it out! Report bugs File feature requests Have fun!

Slide 38

Slide 38 text

Go and try it out! Report bugs File feature requests Have fun!

Slide 39

Slide 39 text

...questions? https:!"go.sebastiano.dev/desktop-app-2021