Key Takeaways
@Composable — annotation that turns a function into a Composable. Composable functions are UI building blocks. They don't return a View, they emit elements into Composition. Composition — a UI tree built from Composable function calls. Compose compares the new tree with the old one and updates only the changed parts.
Recomposition — restart of Composable functions when state changes. Compose tracks which states are read in each function. When a state changes, Compose restarts only those functions that read this state (Smart Recomposition). Recomposition is optimistic: it can run multiple times, so functions must be pure (no side effects). Side effects go in LaunchedEffect or DisposableEffect. Composable functions cannot be suspend. They are called from other Composable functions. Call order is not guaranteed (Compose may reorder).
// Composable example with State Hoisting and LazyColumn
@Composable
fun ItemList(
items: List<String>,
onItemClick: (String) -> Unit
) {
LazyColumn(
modifier = Modifier.fillMaxSize()
) {
items(items) { item ->
Card(
modifier = Modifier
.fillMaxWidth()
.clickable { onItemClick(item) }
.padding(8.dp)
) {
Text(
text = item,
style = MaterialTheme.typography.bodyLarge
)
}
}
}
}
@Composable
fun MainScreen() {
var text by remember { mutableStateOf("") }
val items = listOf("Item 1", "Item 2", "Item 3")
Scaffold(
topBar = {
TopAppBar(title = { Text("Compose App") })
}
) { padding ->
ItemList(
items = items,
onItemClick = { selected -> text = selected }
)
}
}Composition — declarative tree. Recomposition — smart restart. IT Sectr recommends monitoring type stability — unstable types cause excessive recomposition.
CompositionLocal — implicit data passing in Compose. Analogous to @Environment in SwiftUI. CompositionLocalProvider — setting a value. current — reading. Used for: Theme (MaterialTheme), ContentScale, Density. Static CompositionLocal — for configuration without changes. Dynamic CompositionLocal — for mutable values (themes). IT Sectr recommends using CompositionLocal for global configurations and explicit parameters for data.
remember — preserves value between recompositions. mutableStateOf — creates observable state (MutableState<T>). When changed, triggers recomposition. State Hoisting — pattern: state is lifted to the parent component, child receives value + callback. State (immutable) — read only. MutableState — read + write. rememberSaveable — persists during rotation/process death.
State Hoisting — principle: state down, events up. State is stored in the parent and passed to child components via parameters. Child components report changes via lambdas (callback). Benefits: reusability, testability, single source of truth. Example: instead of MyTextField storing its own state, the parent stores the string and passes it via value + onValueChange.
derivedStateOf — computed state, recalculated only when dependencies change. Used for filtering, conversion, validation. snapshotFlow — converts State to Flow. Used for reactive chains. collectAsState — collects Flow into State inside Composable. IT Sectr recommends derivedStateOf for computed values and snapshotFlow for connecting State with coroutines.
Column — vertical layout (analogous to LinearLayout vertical). Row — horizontal layout. Box — stacking layout (analogous to FrameLayout). LazyColumn — vertical scrollable list with lazy loading. LazyRow — horizontal scrollable list. Scaffold — main screen scaffold: TopAppBar, BottomBar, FloatingActionButton, Snackbar. TopAppBar — top bar. BottomNavigation — bottom navigation (NavigationBar in Material 3). Modifier — chain: .fillMaxWidth().padding(8.dp).clickable { }. Modifier order matters — each creates a new wrapper.
LazyColumn — virtualized list. Renders only visible elements. Optimization: 1) key — unique key for item, 2) contentType — group items by type, 3) itemContent — minimize recomposition inside item, 4) LazyVerticalGrid / LazyHorizontalGrid — for grids. LazyLayout — custom lazy layout. Paging 3 + Compose — pagination via collectAsLazyPagingItems. IT Sectr recommends key(item) for all LazyColumn for predictable recomposition.
Navigation Compose — navigation library. NavController — manages destination stack. NavHost — container for navigation graph. composable("route") — register destination. navController.navigate("route") — navigate. popBackStack() — go back. Arguments: composable("detail/{id}", arguments = listOf(navArgument("id") { type = NavType.StringType })). Deep linking via intentFilter. BottomNavigation — integration with NavController: NavBarItem → navigate + popUpTo.
Multiple back stacks — separate back stack for each BottomNavigation tab. SavedStateHandle — preserve arguments during process death. NavArgs — type-safe arguments (Kotlin 2.0+). Deep links — URL schemes for external links. Predictive back gesture (Android 14+) — back gesture support with preview. IT Sectr recommends using NavArgs for type safety and multiple back stacks for BottomNavigation.
LaunchedEffect — launches suspend block in Composition. Canceled when leaving Composition. Restarted when keys change. Used for: data loading, timers, animations. DisposableEffect — for resources requiring cleanup: onDispose { } — unsubscribe from listeners, close connections. SideEffect — synchronous effect (each recomposition). Used for: logging, synchronizing with non-Compose code. IT Sectr recommends LaunchedEffect for data loading and DisposableEffect for cleanup.
| Parameter | Jetpack Compose | SwiftUI |
|---|---|---|
| UI Description | @Composable function + Modifier | View Protocol + @ViewBuilder |
| State | remember + mutableStateOf | @State, @StateObject |
| State Hoisting | State Hoisting | @Binding |
| List | LazyColumn | List |
| Navigation | NavController + NavHost | NavigationStack (iOS 16+) |
| Effects | LaunchedEffect, DisposableEffect | .task{}, .onAppear{} |
| Layout | Column, Row, Box | VStack, HStack, ZStack |
Compose — function + modifier. SwiftUI — struct + modifier. Concepts are similar, syntax is different. IT Sectr recommends learning both frameworks — understanding one makes learning the other easier.
rememberCoroutineScope — access to CoroutineScope outside LaunchedEffect (e.g., on button click). snapshotFlow — convert State to Flow for chains. produceState — convert non-Compose source to State. animateFloatAsState and animateColorAsState — animations via effects. IT Sectr recommends rememberCoroutineScope for UI events and LaunchedEffect for automatic loading.
MaterialTheme — global Compose theme. Colors, typography, shapes. MaterialTheme { } — wraps the entire app. Material3 (M3) — Google design system 2023+. Dynamic Colors — adaptation to wallpaper (Android 12+). TextStyle — text configuration: fontSize, fontWeight, lineHeight. Shape — corner rounding. Elevation — shadows. IT Sectr recommends Material3 by default and Dynamic Colors for modern devices.
@Composable
fun AppTheme(content: @Composable () -> Unit) {
val colorScheme = if (isSystemInDarkTheme()) {
darkColorScheme(
primary = Color(0xFFBB86FC),
secondary = Color(0xFF03DAC6)
)
} else {
lightColorScheme(
primary = Color(0xFF6200EE),
secondary = Color(0xFF03DAC6)
)
}
MaterialTheme(
colorScheme = colorScheme,
typography = Typography(
bodyLarge = TextStyle(fontSize = 16.sp)
)
) { content() }
}animateFloatAsState — animates Float value. animateColorAsState — animates color. animateDpAsState — animates size. AnimatedVisibility — show/hide with .animateEnterExit(). AnimatedContent — animation when content changes (crossfade, slide). updateTransition — animation based on enum state. Animatable — custom animation via Animatable interface. IT Sectr recommends AnimatedVisibility for lists and AnimatedContent for screen transitions.
@Composable
fun AnimatedCounter(count: Int) {
val animatedCount by animateFloatAsState(
targetValue = count.toFloat(),
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
)
AnimatedContent(targetState = count) { targetCount ->
Text(
text = "$targetCount",
style = MaterialTheme.typography.displayLarge,
modifier = Modifier.animateContentSize()
)
}
}Compose UI Test — testing Compose screens. createComposeRule() — JUnit rule. setContent { } — set Composable. onNodeWithText, onNodeWithTag, onNodeWithContentDescription — find elements. performClick, performTextInput, performScrollTo — actions. assertIsDisplayed, assertTextEquals — assertions. Semantics — Semantics tree for accessibility and tests. IdlingResource — wait for async operations. Screenshot tests — Papercuts, Roborazzi. IT Sectr recommends UI tests for every screen and Unit tests for ViewModel.
WindowSizeClass — adaptation to screen size (Compact, Medium, Expanded). Related to Material3 responsive layouts. Used in Adaptive Navigation Suite for automatic switching from BottomNavigation to NavigationRail. IT Sectr recommends WindowSizeClass for tablet and desktop Compose adaptation.
Paging 3 + Compose — pagination library from Google. PagingData — page stream. PagingConfig — settings (pageSize, prefetchDistance). collectAsLazyPagingItems() — collect in Compose. PagingSource — custom source. RemoteMediator — hybrid loading (network + DB). Paging 3 is the standard for infinite scroll lists in Compose.
Frequently Asked Questions
@Composable — annotation for UI functions. Composable function calls form Composition. Recomposition — restart when state changes.
State Hoisting — lifting state to parent. State down, events up. Reusable and testable components.
Recomposition — restart of Composable functions when state changes. Smart Recomposition — minimal function set.
NavController — destination stack. NavHost — graph container. composable("route") — registration. navigate() — transition.
LaunchedEffect — suspend block with auto-cancellation. DisposableEffect — resources with onDispose cleanup.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.