Jetpack Compose Flashcards
What is jetpack compose
A modern toolkit for building native UI on Android using declarative syntax
What is a composable function
A function that describes UI and can be recomposed efficiently when data changes
What is state in jetpack compose
Data that can change and trigger recomposition of UI
What is remember in jetpack compose
A function to create state that persists across recompositions within a composable
How do you handle navigation in jetpack compose
Using the navigation component to manage different screens and their transitions
What is LazyColumn
A composable for efficiently displaying large lists of items vertically
What is a modifier in jetpack compose
A way to change the appearance or behaviour of a composable
What’s the difference between @Composable with @Preview
@Composable is used to define a composable function, while @Preview is used to display a preview of a composable in android studio layout editor
What are state composables and stateless composables
State composables hold state and can be recomposed when the data changes
Stateless composables don’t hold state and are recomposed when their inputs change
Explain how to handle user interactions with composables
Use modifiers like clickable, onLongClick or gesture detection APIs
How do you create custom composables
Define functions annotated with @Composable that describe the UI and logic
What are slot APIs in Jetpack Compose
Allow customization of composable layouts by providing content within them
Explain how to achieve theming consistency across your app
Use MaterialTheme to provide a theme throughout the app hierarchy
How do you handle accessibility in Jetpack Compose
Use semantic properties like contentDescription and follow accessibility best practices
What are animation APIs in jetpack compose
Use AnimatedVisibility or transition to animate composable appearances or changes
Explain how to perform data fetching and asynchronous operations in jetpack compose
Use LaunchedEffect or rememberCoroutineScope to launch coroutines within composables
How do you handle state hoisting in jetpack compose
Lift state to a common ancestor composable to avoid unnecessary recompositions
What is the difference between Surface and Box composables
Surface provides a material design background, while Box is a generic container for other composables
Explain how to implement navigation drawers in jetpack compose
Use the NavigationDrawer composable and handle navigation actions
How do you integrate bottom navigation with jetpack compose
Use the BottomNavigation composable and navigat to different destinations based on selections
What are Modifier.fillMaxSize and Modifier.wrapContentSize used for
FillMaxSize makes a composable fill it’s parents size, while wrapContentSize sizes the composable based on its content
Explain how to create custom modifiers in jetpack compose
Define functions that return new modifiers by combining existing ones or adding custom logic
How do you test composables in jetpack compose
Use the composeUiTest library to write unit and integration tests for composables
What are LazyColumnFor and LazyRowFor composables used for
Efficiently display large lists of items with access to their index
Explain how to handle errors and loading states in jetpack compose
Use composables like Box and If to conditionally display loading or error states based on data availability
How do you measure and optimize the performance of your jetpack compose UIs
Use tools like Android Studio Profiler and identify bottlenecks in recomposition
What are the benefits of using previews in jetpack compose
Allow for quick visual inspection of composable UIs during development
Explain the concept of concurrency and lifecycle awareness in jetpack compose
Use coroutines and LaunchedEffect to manage background tasks and ensure composables handle lifecycle events appropriately