1 of 46

2 of 46

Build adaptive apps on Large Screens with Jetpack Compose

Ho Chi Minh City 2024

Luu Ngoc Lan

@Mobile Engineer - Kromlab

3 of 46

What’s needed?

Laptop(Windows/Mac/Linux)

Android Studio Koala or latest

JDK >= 11, Gradle >8.5, Kotlin >1.8

GitHub account

4 of 46

⇒ Clone repo LuuNgocLan/JetSpotify

⇒ Checkout branch feat/dev-fest-starter

Slide

5 of 46

6 of 46

Imagine your app on

Large Screens

7 of 46

8 of 46

What contents?

What is adaptive on large devices

Analyzing adaptive layout on Spotify

Coding time

More adaptive composable

9 of 46

What is adaptive on large devices?

10 of 46

Foldable devices

11 of 46

https://developer.android.com/large-screens/gallery

12 of 46

“More space

More contents

13 of 46

New decision layout

14 of 46

15 of 46

16 of 46

Considerations

17 of 46

Configuration and continuity

Multi-window and multi-resume

Camera preview and media projection

Keyboard, mouse, and trackpad

18 of 46

19 of 46

What is adaptive on large devices?

Spotify adaptive app

20 of 46

SPOTIFY

Responsive Navigation

Responsive content UI

21 of 46

Responsive Content Destination

22 of 46

23 of 46

SPOTIFY

24 of 46

What is adaptive on large devices?

Spotify adaptive app

Coding time

25 of 46

Output

  1. Adaptive Navigation
  2. App Continuity during resizing

26 of 46

27 of 46

Home Screen

Search

Library

Premium

NavHost

Bottom Navigation

NavHostController

Starter Project

28 of 46

Home Screen

Search

Library

Premium

NavHost

Bottom Navigation

NavHostController

Data

29 of 46

Output

  • Adaptive Navigation

30 of 46

Step by step

31 of 46

Use WindowSizeClasses

32 of 46

dependencies {

...

implementation(platform("androidx.compose:compose-bom:2024.09.03"))

implementation("androidx.activity:activity-compose:1.9.0")

implementation("androidx.compose.material:material-icons-extended")

implementation("androidx.compose.material3:material3")

implementation("androidx.compose.material3:material3-window-size-class")

implementation("androidx.compose.ui:ui")

...

}

build.gradle.kts

33 of 46

34 of 46

Decision layout

Navigation drawer

Navigation Rail

Navigation Bottom

35 of 46

36 of 46

PermanentNavigationDrawer(

drawerContent = {

PermanentDrawerSheet(Modifier.width(dimensionResource(R.dimen.drawer_width))) {

JetSpotifyDrawerContent(

selectedDestination = currentRoute?.let {

JetSpotifyTab.values().first { e -> e.name == it }

} ?: JetSpotifyTab.Home,

onTabPressed = { jetSpotifyTab ->

onTabPressed(jetSpotifyTab)

},

navItems = navigationItemContentList,

modifier = Modifier

.wrapContentWidth()

.fillMaxHeight()

.background(MaterialTheme.colorScheme.inverseOnSurface)

.padding(top = dimensionResource(R.dimen.drawer_padding_header))

.testTag(navigationDrawerContentDescription)

)

}

},

) {

/* Main Navigation Host*/

}

JetSpotifyMainScreen.kt

37 of 46

PermanentNavigationDrawer(

drawerContent = {

PermanentDrawerSheet(Modifier.width(dimensionResource(R.dimen.drawer_width))) {

JetSpotifyDrawerContent(

selectedDestination = currentRoute?.let {

JetSpotifyTab.values().first { e -> e.name == it }

} ?: JetSpotifyTab.Home,

onTabPressed = { jetSpotifyTab ->

onTabPressed(jetSpotifyTab)

},

navItems = navigationItemContentList,

modifier = Modifier

.wrapContentWidth()

.fillMaxHeight()

.background(MaterialTheme.colorScheme.inverseOnSurface)

.padding(top = dimensionResource(R.dimen.drawer_padding_header))

.testTag(navigationDrawerContentDescription)

)

}

},

) {

/* Main Navigation Host*/

}

JetSpotifyMainScreen.kt

38 of 46

Or can use NavigationSuiteScaffold

39 of 46

What is adaptive on large devices?

Spotify adaptive app

Coding time

More adaptive composable

40 of 46

41 of 46

ListDetailPaneScaffold

42 of 46

SupportingPaneScaffold

43 of 46

Key takeaways

    • Don’t clocked app orientation
    • Decision layouts with Window Size Classes base on Material Design 3 Guidance
    • New Material 3 adaptive UIs: NavigationSuiteScaffold, ListDetailPaneScaffold, SupportingPaneScaffold
    • Maintain state during configuration change
    • Support external Keyboard, Mouse, Trackpad, Stylus

44 of 46

References

45 of 46

Thank you!

Luu Ngoc Lan

@Mobile Engineer - Kromlab

46 of 46