agentsclimarketplace

Jetpack compose

Skill G1Joshi/Agent-Skills/skills/mobile/jetpack-compose

Jetpack Compose Android declarative UI. Use for Android.From its SKILL.md

Install
npx -y skills add G1Joshi/Agent-Skills --skill jetpack-compose

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 12 stars12 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

4.5 KB, 859 tokens by cl100k_base, as published. Nobody here has run it

Jetpack Compose

Jetpack Compose is Android's modern toolkit for building native UIs. It simplifies and accelerates UI development on Android with less code, powerful tools, and intuitive Kotlin APIs.

When to Use

  • New Android application development (Grid/List content, complex layouts).
  • Migrating existing View-based apps incrementally (Interoperability).
  • Sharing UI logic with Kotlin Multiplatform (Compose Multiplatform).

Quick Start

// build.gradle.kts needs composed enabled

// MainActivity.kt
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.lifecycle.viewmodel.compose.viewModel

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                MyApp()
            }
        }
    }
}

@Composable
fun MyApp(viewModel: CounterViewModel = viewModel()) {
    // Collecting state from ViewModel
    val count by viewModel.uiState.collectAsState()

    Scaffold(
        floatingActionButton = {
            FloatingActionButton(onClick = { viewModel.increment() }) {
                Text("+")
            }
        }
    ) { padding ->
        Text(
            text = "Count: $count",
            modifier = Modifier.padding(padding)
        )
    }
}

Core Concepts

Composable Functions

Functions annotated with @Composable are the building blocks. They describe specialized UI widgets or layouts. They can call other Composables.

Recomposition

When the state of a Composable changes, the framework re-executes the function to update the UI. Smart logic ensures only necessary parts are redrawn.

Modifiers

The Modifier object allows you to decorate or augment a composable (layout, appearance, interactions, etc.). They are chainable and order-sensitive.

Common Patterns

State Hoisting

State should be moved up to the caller to make components stateless and reusable.

  • Stateful: Owns state (remember { mutableStateOf(...) }).
  • Stateless: Receives state as parameters and emits events via lambdas.

ViewModel & StateFlow

Use ViewModel to hold business logic and expose screen state via StateFlow or Compose State. Collect it in the UI using collectAsStateWithLifecycle().

Navigation Compose

Define a NavHost with composable destinations. Pass arguments and navigate using a type-safe approach (library dependent) or string routes (default).

Best Practices

Do:

  • Use Material 3 (androidx.compose.material3) for the latest design specs.
  • Use remember and derivedStateOf to optimize performance.
  • Use LazyColumn / LazyRow for lists (equivalent to RecyclerView).
  • Use Preview annotations to visualize UI without running the app.

Don't:

  • Don't perform expensive operations in the composition phase (use LaunchedEffect or ViewModel).
  • Don't create state inside a loop.
  • Don't ignore the Modifier parameter in reusable components (always allow caller to pass one).

Troubleshooting

ErrorCauseSolution
@Composable invocations can only happen from context...Calling a composable from a standard function.Add @Composable annotation to the caller.
Infinite RecompositionUpdating state inside the composition without a side-effect wrapper.Move update logic to a callback or SideEffect/LaunchedEffect.
ViewModel state not updating UIUsing a non-observable type or forgetting collectAsState.Use StateFlow/MutableState and collect it properly.

References

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.