Basic Scaffolds in Jetpack Compose

ibrahimcanerdogan
5 min readFeb 7, 2024

--

Scaffold is a composable in Jetpack Compose that provides a foundation for building an app. It takes a set of composables and arranges them in a consistent manner to create a consistent look and feel across all screens in your app.

🟢 ANDROID WITH MACHINE LEARNING! (COURSE)

🟢 KOTLIN INTERVIEW BOOTCAMP! (COURSE)

In this reading, you will cover the advantages and disadvantages of Bottom Sheet Scaffolds, Backdrops Scaffolds, and Navigation Drawer Scaffolds.

Using Scaffold

Scaffold provides the basic structure to build our app, with components such as a top AppBar, a bottom NavigationBar, and a DrawerLayout that can be used to navigate between different screens. Scaffold also provides a consistent layout to work with when creating a UI, like setting margins and padding, setting up a column or row of composables and styling them with background and foreground colors. Scaffold is also designed to be flexible and extensible, allowing developers to add custom composables and change the layout as needed.

Bottom Sheet Scaffold

A bottom sheet scaffold is a UI pattern that slides up from the bottom of the screen to display additional content or options. It is typically used to show contextual information such as a list of options or a list of recently accessed items. Bottom sheet scaffolds are often used to provide a distraction-free environment for users to access additional information when it is needed, without taking up too much screen real estate.

An example of using Bottom Sheet Scaffold

The following is an example of a Bottom Sheet Scaffold:

@Composable
fun BottomSheetScaffold() {
BottomSheetScaffold(
bottomSheet = {
BottomSheet(
onCloseRequest = {
// Add logic to handle the bottom sheet closing
}
) {
// Add content to be displayed in the bottom sheet
}
},
bodyContent = {
// Add content to be displayed in the body
}
)
}

Advantages

The Bottom Sheet Scaffold component is a great way to display information without taking up too much screen space. It also allows users to quickly access and interact with content without having to navigate away from their current screen. Additionally, the component is easy to customize and can be used to create a unique user interface.

Disadvantages

The Bottom Sheet Scaffold component can be confusing for users and can be overwhelming if there is too much content in it. Additionally, it can be difficult to use on smaller screens, as the bottom sheet can take up a large portion of the screen.

Backdrop Scaffold

The Backdrop Scaffold is a powerful tool for creating dynamic layouts in Jetpack Compose. It provides a way to easily create a flexible, responsive layout for an app and allows for easy customization of the look and feel. The Backdrop scaffold is a UI pattern that provides a full-screen overlay when triggered. It is typically used to display additional content such as a menu, search bar, or other options related to the main content on the screen. The backdrop scaffold is useful for providing an extra layer of context and options to the user. You can also use the BackdropScaffold API to animate the background, font size and other elements of the layout. This will help make the layout more engaging and interactive.

An example of using Backdrop Scaffold

The following is an example of how to create a basic composable function that uses BacdkropScaffold: Bottom Sheet Scaffold:

@Composable
fun MyScreen() {
BackdropScaffold(
scaffoldState = rememberScaffoldState(),
topBar = {
TopAppBar(
title = { Text("My Screen") }
)
},
bodyContent = {
// Your content here
// ...
},
backLayer = {
// Your content here
// ...
},
frontLayer = {
// Your content here
// ...
}
)
}

Advantages

The Backdrop component is a great way to display additional information without taking up too much screen space. It also allows users to quickly access and interact with content without having to navigate away from their current screen. Additionally, the component is easy to customize and can be used to create a unique user interface.

Disadvantages

The Backdrop component can be difficult to use on smaller screens, as the panel can take up a large portion of the screen. Additionally, the component can be confusing for users and can be overwhelming if there is too much content in it.

Navigation Drawer Scaffold

A navigation drawer scaffold is a UI pattern that provides a side-panel for navigating between different parts of the application. It is commonly used to provide access to an application’s top-level navigation items, as well as any additional content. Navigation drawers are often used to provide quick access to important content or features when needed. It also provides an easy way to programmatically set up and control the navigation drawer. The Navigation Drawer Scaffold also makes it easy to add icons, headers and other components to the navigation drawer. Additionally, it provides a way to quickly move between different screens without having to manually create navigation logic. This allows you to quickly create a navigation-style user interface in your app with minimal effort.

An example of using Navigation Drawer Scaffold

The following is an example of a Navigation Drawer Scaffold:

@Composable
fun MyApp() {
val navigation = NavigationDrawerController()
MaterialTheme {
Scaffold(
topBar = {
TopAppBar(
title = { Text(text = "My App") },
navigationIcon = {
NavigationDrawerIcon(
drawerState = navigation.drawerState,
onStateChange = navigation.updateDrawerState
)
}
)
},
drawerContent = {
var context = ContextAmbient.current
MyDrawerContent(
closeDrawer = {
navigation.updateDrawerState(DrawerState.Closed)
},
navigateToScreen = { screen ->
// Handle navigation
}
)
}
) {
// The main content of your screen
Text(text = "This is the main content")
}
}
}

Advantages

The Navigation Drawer Scaffold component is a great way to provide users with an easy way to navigate between different areas of an application. Additionally, it is easy to customize and can be used to create a unique user interface.

Disadvantages

The Navigation Drawer Scaffold component can be difficult to use on smaller screens, as the panel can take up a large portion of the screen. Additionally, the component can be confusing for users if there are too many navigation options.

Conclusion

In conclusion, each of the components discussed in this reading has both advantages and disadvantages. Bottom Sheet Scaffolds, Backdrops, and Navigation Drawer Scaffolds all provide developers with powerful tools for creating unique user interfaces. However, it is important to consider the user experience when choosing which components to use in a Jetpack Compose UI development project.

İbrahim Can Erdoğan

LINKEDIN

YOUTUBE

UDEMY

GITHUB

--

--

ibrahimcanerdogan

Hi, My name is Ibrahim, I am developing ebebek android app within Ebebek. I publish various articles in the field of programming and self-improvement.