### Jetpack Compose Project Setup Source: https://foso.github.io/Jetpack-Compose-Playground/cookbook/how_to_use_compose_in_viewgroup Guides through the initial setup of a Jetpack Compose project. This includes adding necessary dependencies to your `build.gradle` file. ```kotlin // build.gradle (app level) dependencies { implementation("androidx.compose.ui:ui:1.x.x") implementation("androidx.compose.material:material:1.x.x") implementation("androidx.compose.ui:ui-tooling-preview:1.x.x") implementation("androidx.activity:activity-compose:1.x.x") // ... other dependencies } ``` -------------------------------- ### Jetpack Compose Project Setup Source: https://foso.github.io/Jetpack-Compose-Playground/layout/column Guides on setting up a new Jetpack Compose project, including necessary dependencies and configurations in the build files. ```kotlin // build.gradle (app level) dependencies { implementation("androidx.compose.ui:ui:1.x.x") implementation("androidx.compose.material:material:1.x.x") implementation("androidx.activity:activity-compose:1.x.x") } ``` -------------------------------- ### Project Setup Source: https://foso.github.io/Jetpack-Compose-Playground/foundation/lazycolumn Guides users through the process of setting up the Jetpack Compose Playground project in their development environment. ```APIDOC Project Setup: Prerequisites: - Android Studio (latest stable version recommended). - Kotlin programming language knowledge. Steps: 1. Clone the repository: `git clone ` 2. Open the project in Android Studio. 3. Ensure Gradle sync completes successfully. 4. Run the application on an emulator or physical device. Dependencies: - Jetpack Compose libraries (managed by Gradle). - Kotlin standard library. ``` -------------------------------- ### Compose Project Setup Source: https://foso.github.io/Jetpack-Compose-Playground/material/floatingactionbutton Guides on setting up a new Jetpack Compose project, including necessary dependencies and configurations. ```kotlin // In your app/build.gradle file: // Add Compose dependencies composeOptions { kotlinCompilerExtensionVersion '1.5.1' } buildFeatures { compose true } dependencies { implementation("androidx.compose.ui:ui:1.5.4") implementation("androidx.compose.material:material:1.5.4") implementation("androidx.compose.ui:ui-tooling-preview:1.5.4") implementation("androidx.activity:activity-compose:1.7.2") } ``` -------------------------------- ### Compose Project Setup Source: https://foso.github.io/Jetpack-Compose-Playground/material/button Provides guidance on setting up a new Jetpack Compose project. This includes essential steps and configurations required to start developing Compose UI. ```kotlin // Add Compose dependencies to your app/build.gradle file: // implementation("androidx.compose.ui:ui:1.x.x") // implementation("androidx.compose.material:material:1.x.x") // implementation("androidx.compose.ui:ui-tooling-preview:1.x.x") // implementation("androidx.activity:activity-compose:1.x.x") ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/platform/composeview Practical examples from the Jetpack Compose Cookbook, demonstrating how to handle text field changes, use Compose in a ViewGroup, load images, integrate Android Views, get Android Context, detect dark mode, and create custom shapes. ```kotlin Handle changes to a text field How to use Compose in a ViewGroup How to load an Image How to use an Android View in Compose How to get Android Context How to detect dark mode How to create a custom shape ``` -------------------------------- ### Jetpack Compose General Concepts Source: https://foso.github.io/Jetpack-Compose-Playground/general/compose_lifecycle Covers fundamental concepts in Jetpack Compose, including project setup, Hello World examples, modifiers, state management, composition locals, previewing composables, and navigation. ```kotlin // Project Setup: Typically involves adding Compose dependencies to build.gradle. // Hello World Compose @Composable fun HelloWorld() { Text("Hello, Jetpack Compose!") } // Modifier Usage @Composable fun ModifiableText() { Text( "Styled Text", modifier = Modifier .padding(16.dp) .background(Color.Blue) .fillMaxWidth() ) } // State Management @Composable fun StateExample() { var counter by remember { mutableStateOf(0) } Button(onClick = { counter++ }) { Text("Count: $counter") } } // CompositionLocalProvider @Composable fun ProvideTheme() { MaterialTheme { CompositionLocalProvider(LocalContentColor provides Color.Red) { Text("Red Text") } } } // Preview @Preview(showBackground = true) @Composable fun PreviewHelloWorld() { HelloWorld() } // PreviewParameter @Preview @Composable fun PreviewWithParameter(@PreviewParameter(SampleDataProvider::class) data: String) { Text(data) } class SampleDataProvider : PreviewParameterProvider { override val values: Sequence = sequenceOf("Data 1", "Data 2") } // Navigation (Conceptual - requires Navigation Compose library) /* @Composable fun AppNavigation() { val navController = rememberNavController() NavHost(navController = navController, startDestination = "home") { composable("home") { HomeScreen(navController) } composable("details") { DetailsScreen() } } } */ ``` -------------------------------- ### Jetpack Compose General Concepts Source: https://foso.github.io/Jetpack-Compose-Playground/layout/constraintlayout Covers fundamental concepts in Jetpack Compose, including project setup, hello world examples, modifiers, state management, navigation, previewing composables, and UI testing. These are essential for building Compose applications. ```kotlin Project Setup: // Refer to the 'Project Setup' link for detailed instructions on setting up a new Jetpack Compose project. Hello World Compose: @Composable fun HelloWorld() { Text("Hello, Jetpack Compose!") } Modifier: // Modifiers are used to decorate or augment a composable. @Composable fun MyComponentWithModifier() { Text("Styled Text", modifier = Modifier.padding(16.dp).background(Color.Blue)) } State: // State is how you observe changes in your UI. @Composable fun Counter() { var count by remember { mutableStateOf(0) } Button(onClick = { count++ }) { Text("Clicked ${count} times") } } Navigation: // Jetpack Compose Navigation handles moving between screens. // Requires the navigation-compose dependency. // Example: // val navController = rememberNavController() // NavHost(navController, startDestination = "home") { // composable("home") { HomeScreen() } // composable("details") { DetailsScreen() } // } Preview: // Previews allow you to see your composables without running the app. @Preview(showBackground = true) @Composable fun PreviewHelloWorld() { HelloWorld() } PreviewParameter: // PreviewParameter provides different data to your previews. class NameProvider : PreviewParameterProvider { override val values = sequenceOf("Alice", "Bob") } @Preview @Composable fun PreviewWithParameter(@PreviewParameter(NameProvider::class) name: String) { Text("Hello, $name!") } UI Testing: // UI testing in Compose uses Espresso or Compose testing APIs. // Example: // @RunWith(AndroidJUnit4::class) // class MyComposeTest { // @get:Rule // val composeTestRule = createComposeRule() // // @Test // fun testHelloWorld() { // composeTestRule.setContent { HelloWorld() } // composeTestRule.onNodeWithText("Hello, Jetpack Compose!").assertExists() // } // } ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/foundation/image Practical examples from the Jetpack Compose Cookbook, demonstrating how to handle text field changes, use Compose in a ViewGroup, load images, use Android Views in Compose, get Android Context, detect dark mode, and create custom shapes. ```kotlin import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import androidx.core.content.ContextCompat import coil.compose.rememberAsyncImagePainter import coil.request.ImageRequest import android.content.Context import android.graphics.BitmapFactory import android.graphics.drawable.BitmapDrawable import android.view.View import android.widget.FrameLayout import androidx.compose.foundation.Canvas import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.platform.LocalConfiguration // Handle changes to a text field @Composable fun TextFieldChangesExample() { var text by remember { mutableStateOf("") } TextField( value = text, onValueChange = { text = it }, label = { Text("Enter text") }, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text) ) Text("Current value: $text") } // How to use Compose in a ViewGroup @Composable fun ComposeInViewGroupExample() { AndroidView( modifier = Modifier.fillMaxSize(), factory = { context -> FrameLayout(context).apply { // Add your Android View here } }, update = { frameLayout -> // Update your Android View here } ) } // How to load an Image @Composable fun LoadImageExample(url: String) { val painter = rememberAsyncImagePainter(url) Image(painter = painter, contentDescription = "Loaded Image") } // How to use an Android View in Compose @Composable fun AndroidViewInComposeExample() { val context = LocalContext.current AndroidView( modifier = Modifier.wrapContentSize(), factory = { View(context).apply { // Configure your Android View } } ) } // How to get Android Context @Composable fun GetAndroidContextExample() { val context = LocalContext.current Text("Android Context Package: ${context.packageName}") } // How to detect dark mode @Composable fun DetectDarkModeExample() { val configuration = LocalConfiguration.current val isDarkMode = configuration.isNightModeActive Text(if (isDarkMode) "Dark Mode is ON" else "Light Mode is ON") } // How to create a custom shape @Composable fun CustomShapeExample() { Canvas(modifier = Modifier.size(100.dp)) { val canvasWidth = size.width val canvasHeight = size.height drawCircle( color = Color.Blue, center = Offset(x = canvasWidth / 2f, y = canvasHeight / 2f), radius = size.minDimension / 2f, style = Stroke(width = 4f) ) } } ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/general/roadmap Provides practical examples and recipes for common tasks in Jetpack Compose, such as handling text field changes, using Compose in a ViewGroup, loading images, using Android Views in Compose, getting Android Context, detecting dark mode, and creating custom shapes. ```kotlin Handle changes to a text field How to use Compose in a ViewGroup How to load an Image How to use an Android View in Compose How to get Android Context How to detect dark mode How to create a custom shape ``` -------------------------------- ### Jetpack Compose UI Testing Setup Source: https://foso.github.io/Jetpack-Compose-Playground/general/testing Demonstrates the basic setup for UI testing in Jetpack Compose, including the necessary dependencies and the creation of a test rule. ```kotlin import androidx.compose.ui.test.junit4.createComposeRule import org.junit.Rule import org.junit.Test class MyComposeTest { @get:Rule val composeTestRule = createComposeRule() @Test fun myTest() { // Test code here } } ``` -------------------------------- ### Jetpack Compose - Hello World Example Source: https://foso.github.io/Jetpack-Compose-Playground/general/getting_started A basic 'Hello World' example demonstrating the fundamental structure of a Jetpack Compose UI. It shows how to define a composable function and display text. ```kotlin import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.material.Text import androidx.compose.runtime.Composable class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Greeting("Android") } } } @Composable fun Greeting(name: String) { Text(text = "Hello $name!") } ``` -------------------------------- ### Jetpack Compose General Concepts Source: https://foso.github.io/Jetpack-Compose-Playground/general/codelabs Explanations and examples of fundamental Jetpack Compose concepts, including Codelabs, Compose Confusion, Compiler Plugin, Compose for Android/SwiftUI Developers, Compose Lifecycle, CompositionLocal, CompositionLocalProvider, Hello World, Modifiers, Navigation, Preview, Roadmap, Project Setup, State, and UI Testing. ```kotlin Codelabs: Links to various Jetpack Compose codelabs for hands-on learning. Compose Confusion: Explains common pitfalls and solutions in Jetpack Compose. Compiler Plugin: Information about the Jetpack Compose compiler plugin. Compose for Android/SwiftUI Developers: Guides for developers transitioning from Android or SwiftUI to Jetpack Compose. Compose Lifecycle: Details on the lifecycle of composables. CompositionLocal & CompositionLocalProvider: Explains how to pass data down the composable tree. Hello World Compose: A basic "Hello World" example. Modifier: Demonstrates how to use Modifiers to decorate or augment composables. Navigation: Covers navigation within Jetpack Compose applications. Preview: Shows how to use the @Preview annotation for designing composables. Roadmap: Information on the future development of Jetpack Compose. Project Setup: Steps for setting up a new Jetpack Compose project. State: Explains state management in Compose. UI Testing: Guidance on writing UI tests for Compose applications. ``` -------------------------------- ### Hello World Compose Source: https://foso.github.io/Jetpack-Compose-Playground/general/helloworld Demonstrates the basic setup and structure for a 'Hello World' application using Jetpack Compose. It covers project setup, writing a simple Compose function, and integrating it into an Android app. ```kotlin /* * Setup the project * Write a simple Compose function * Use a Compose function as a view in your android app */ // Example of a simple Compose function: @Composable fun Greeting(name: String) { Text(text = "Hello $name!") } // Example of using the Compose function in an Android Activity: class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Greeting("Android") } } } ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/general/compose_lifecycle Provides practical examples for common tasks in Jetpack Compose, such as handling text field changes, loading images, integrating Android Views, and detecting dark mode. ```kotlin // Handle changes to a text field @Composable fun TextFieldChangeHandler() { var text by remember { mutableStateOf("") } TextField( value = text, onValueChange = { text = it // Handle text change logic here }, label = { Text("Type here") } ) } // How to load an Image @Composable fun ImageLoader() { Image( painter = painterResource(id = R.drawable.my_image), // Assuming R.drawable.my_image exists contentDescription = "My Image", modifier = Modifier.size(100.dp) ) } // How to use an Android View in Compose @Composable fun AndroidViewIntegration() { AndroidView( factory = { context -> // Create and configure your Android View here TextView(context).apply { text = "Hello from Android View" } }, update = { textView -> // Update the Android View if needed } ) } // How to get Android Context @Composable fun GetContextExample() { val context = LocalContext.current Button(onClick = { /* Use context, e.g., Toast.makeText(context, "Hello", Toast.LENGTH_SHORT).show() */ }) { Text("Get Context") } } // How to detect dark mode @Composable fun DarkModeDetector() { val configuration = LocalConfiguration.current val isDarkMode = configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES Text(if (isDarkMode) "Dark Mode is ON" else "Light Mode is ON") } ``` -------------------------------- ### Jetpack Compose General Concepts Source: https://foso.github.io/Jetpack-Compose-Playground/material/scaffold This section covers fundamental concepts in Jetpack Compose, including project setup, hello world examples, modifiers, state management, composition, lifecycle, navigation, and UI testing. It also touches upon compiler plugins and how to adapt Compose for different development backgrounds. ```kotlin import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.compose.foundation.layout.Column import androidx.compose.material.Text import androidx.compose.ui.unit.dp import androidx.compose.foundation.layout.padding import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText import org.junit.Rule import org.junit.Test // Project Setup & Hello World // Typically involves setting up your Android project with Compose dependencies. // A basic Composable function: @Composable fun HelloWorld() { Text("Hello, Jetpack Compose!") } // Modifier @Composable fun ModifierExample() { Text("Styled Text", modifier = Modifier.padding(16.dp)) } // State Management @Composable fun StateExample() { var count by remember { mutableStateOf(0) } Column { Text("Count: $count") Button(onClick = { count++ }) { Text("Increment") } } } // CompositionLocal @Composable fun CompositionLocalExample() { val context = LocalContext.current Text("Context: $context") } // Navigation @Composable fun NavigationExample() { val navController = rememberNavController() NavHost(navController = navController, startDestination = "home") { composable("home") { Text("Home Screen") } composable("details") { Text("Details Screen") } } } // UI Testing class MyComposeTest { @get:Rule val composeTestRule = createComposeRule() @Test fun testHelloWorld() { composeTestRule.setContent { HelloWorld() } composeTestRule.onNodeWithText("Hello, Jetpack Compose!").assertExists() } } // Compose for Android/SwiftUI Developers // These sections likely discuss bridging Compose with existing Android Views or adapting concepts for SwiftUI developers. // Compose Lifecycle // Refers to how composables enter, update, and leave the composition. // Roadmap, Codelabs, Compose Confusion // These are references to external resources or specific learning modules. ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/contributing Provides practical solutions for common Jetpack Compose tasks, including handling text field changes, loading images, integrating with Android Views, getting Android Context, detecting dark mode, and creating custom shapes. -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/general/compiler_plugin Practical examples demonstrating how to perform common tasks in Jetpack Compose, such as handling text field changes, loading images, using Android Views in Compose, and accessing the Android Context. ```kotlin Handle changes to a text field How to use Compose in a ViewGroup How to load an Image How to use an Android View in Compose How to get Android Context ``` -------------------------------- ### Jetpack Compose General Concepts Source: https://foso.github.io/Jetpack-Compose-Playground/material/topappbar Illustrates fundamental concepts in Jetpack Compose, including project setup, modifiers, state management, composition, previewing, and navigation. These examples are crucial for understanding the core principles of declarative UI development with Compose. ```kotlin import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.foundation.layout.Column import androidx.compose.material.Text import androidx.compose.ui.unit.dp import androidx.compose.foundation.layout.padding import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController // Example of Project Setup (Conceptual - actual setup is in build.gradle) // dependencies { // implementation("androidx.core:core-ktx:1.9.0") // implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1") // implementation("androidx.activity:activity-compose:1.7.2") // implementation(platform("androidx.compose:compose-bom:2023.08.00")) // implementation("androidx.compose.ui:ui") // implementation("androidx.compose.ui:ui-graphics") // implementation("androidx.compose.ui:ui-tooling-preview") // implementation("androidx.compose.material3:material3") // testImplementation("junit:junit:4.13.2") // androidTestImplementation("androidx.test.ext:junit:1.1.5") // androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") // androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00")) // androidTestImplementation("androidx.compose.ui:ui-test-junit4") // debugImplementation("androidx.compose.ui:ui-tooling") // debugImplementation("androidx.compose.ui:ui-test-manifest") // } // Example of Modifier @Composable fun MyTextWithModifier() { Text( "Hello Compose", modifier = Modifier .padding(16.dp) .clickable { /* Handle click */ } ) } // Example of State @Composable fun Counter() { var count by remember { mutableStateOf(0) } Column { Text("Count: $count") Button(onClick = { count++ }) { Text("Increment") } } } // Example of Preview @Preview(showBackground = true) @Composable fun PreviewMyText() { MyTextWithModifier() } // Example of Navigation @Composable fun AppNavigation() { val navController = rememberNavController() NavHost(navController = navController, startDestination = "home") { composable("home") { HomeScreen(navController = navController) } composable("details") { DetailsScreen() } } } @Composable fun HomeScreen(navController: NavController) { Column { Text("Home Screen") Button(onClick = { navController.navigate("details") }) { Text("Go to Details") } } } @Composable fun DetailsScreen() { Text("Details Screen") } // Example of CompositionLocal (Conceptual) // val LocalMyCustomValue = compositionLocalOf { error("No value provided") } // @Composable // fun MyComponent() { // CompositionLocalProvider(LocalMyCustomValue provides "MyValue") { // ChildComponent() // } // } // @Composable // fun ChildComponent() { // val value = LocalMyCustomValue.current // Text(value) // } ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/general/helloworld Offers practical solutions and code examples for common Jetpack Compose tasks. This includes handling text field changes, integrating Compose within existing Android ViewGroups, and loading images. ```kotlin // Example: Handle changes to a text field @Composable fun TextFieldWithChangeHandler() { var text by remember { mutableStateOf("") } TextField( value = text, onValueChange = { text = it // Handle text change logic here println("Text changed: $it") }, label = { Text("Type here") } ) } // Example: How to use Compose in a ViewGroup (conceptual) // This typically involves using ComposeView within an XML layout or programmatically. // In an Activity: // val composeView = ComposeView(this) // composeView.setContent { MyComposableContent() } // // Add composeView to your ViewGroup // Example: How to load an Image @Composable fun ImageLoaderExample() { Image( painter = painterResource(id = R.drawable.my_image), // Assuming R.drawable.my_image exists contentDescription = "Example Image", modifier = Modifier.size(100.dp) ) } ``` -------------------------------- ### Jetpack Compose General Concepts Source: https://foso.github.io/Jetpack-Compose-Playground/material/badgedbox Explores fundamental concepts in Jetpack Compose, including project setup, state management, modifiers, composition, and navigation. These examples provide a foundation for building Compose UIs. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.runtime.mutableStateOf import androidx.compose.material.Text import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @Composable fun HelloWorldCompose() { Text("Hello, Compose!") } @Composable fun StateExample() { val count = remember { mutableStateOf(0) } Column { Text("Count: ${count.value}") Button(onClick = { count.value++ }) { Text("Increment") } } } @Composable fun ModifierExample() { Text("Styled Text", modifier = Modifier.padding(16.dp)) } import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.staticCompositionLocalOf val LocalCustomValue = staticCompositionLocalOf { "Default Value" } @Composable fun CompositionLocalExample() { CompositionLocalProvider(LocalCustomValue provides "My Custom Value") { ChildComposable() } } @Composable fun ChildComposable() { Text("Value from CompositionLocal: ${LocalCustomValue.current}") } import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import androidx.compose.runtime.Composable @Composable fun NavigationExample() { val navController = rememberNavController() NavHost(navController = navController, startDestination = "screen1") { composable("screen1") { Text("Screen 1") } composable("screen2") { Text("Screen 2") } } } ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/desktop/overview Provides practical examples and solutions for common tasks and challenges when working with Jetpack Compose. This includes handling text field changes, loading images, using Android Views in Compose, and detecting dark mode. ```kotlin Handle changes to a text field How to use Compose in a ViewGroup How to load an Image How to use an Android View in Compose How to get Android Context How to detect dark mode How to create a custom shape ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/general/composeconfusion Offers practical examples from the Jetpack Compose Cookbook, demonstrating how to handle text field changes, use Compose within a ViewGroup, load images, and integrate Android Views into Compose. ```kotlin // Handle changes to a text field // How to use Compose in a ViewGroup // How to load an Image // How to use an Android View in Compose ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/cookbook/overview Practical examples from the Jetpack Compose cookbook, covering common tasks such as handling text field changes, integrating Compose into ViewGroups, loading images, using Android Views within Compose, obtaining Android Context, detecting dark mode, and creating custom shapes. ```kotlin Handle changes to a text field: https://foso.github.io/Jetpack-Compose-Playground/cookbook/textfield_changes/ How to use Compose in a ViewGroup: https://foso.github.io/Jetpack-Compose-Playground/cookbook/how_to_use_compose_in_viewgroup/ How to load an Image: https://foso.github.io/Jetpack-Compose-Playground/cookbook/loadimage/ How to use an Android View in Compose: https://foso.github.io/Jetpack-Compose-Playground/cookbook/how_to_use_an_android_view_in_compose/ How to get Android Context: https://foso.github.io/Jetpack-Compose-Playground/cookbook/get_android_context/ How to detect dark mode: https://foso.github.io/Jetpack-Compose-Playground/cookbook/detect_darkmode/ How to create a custom shape: https://foso.github.io/Jetpack-Compose-Playground/cookbook/how_to_create_custom_shape/ ``` -------------------------------- ### Jetpack Compose Example Applications Source: https://foso.github.io/Jetpack-Compose-Playground/compose_projects A collection of diverse applications built with Jetpack Compose, showcasing different features and architectural patterns. These examples range from Pokedex apps to UI clones and multiplatform projects. ```Kotlin Project: Jetpack Compose Playground Description: Collection of Jetpack Compose example code Link: https://github.com/Foso/Jetpack-Compose-Playground Project: Compose Pokedex Description: Pokedex on Jetpack Compose. Link: https://github.com/zsoltk/compose-pokedex Project: Compose Samples Repository Description: This repository contains a set of individual Android Studio projects to help you learn about Compose in Android. Link: https://github.com/android/compose-samples Project: PeopleInSpace Description: Minimal Kotlin Multiplatform project using Jetpack Compose and SwiftUI Link: https://github.com/joreilly/PeopleInSpace Project: ComposeClock Description: Particle clock created with Jetpack Compose framework Link: https://github.com/adibfara/composeclock Project: JetDelivery Description: JetDelivery is a sample food delivery app, built with Jetpack Compose. Link: https://github.com/vipulasri/JetDelivery Project: Learn Jetpack Compose By Example Description: This project contains various examples that show how you would do things the “Jetpack Compose” way Link: https://github.com/vinaygaba/Learn-Jetpack-Compose-By-Example Project: Full Compose Cookbook with Demo UIs Description: This project showcase all UI, Widgets, Animations and Demo UI samples. Link: https://github.com/Gurupreet/ComposeCookBook Project: JetInstagram Description: An Instagram UI clone app built with “Jetpack Compose” with Like Button Animation and instagram reels feature with exoplayer. Link: https://github.com/vipulasri/JetInstagram Project: DisneyCompose Description: A demo Disney app using compose and Hilt based on modern Android tech-stacks and MVVM architecture. Fetching data from the network and integrating persisted data in the database via repository pattern. Declarative UI version of the DisneyMotions using compose. Link: https://github.com/skydoves/DisneyCompose Project: Compose Slack Desktop Description: A Slack demo app for desktop using Jetpack Compose UI toolkit Link: https://github.com/vipulasri/ComposeSlackDesktop Project: FlappyBird Description: FlappyBird made with Jetpack Compose. Link: https://github.com/Nthily/FlappyBird Project: JetSpotify Description: This is a Spotify App made in Jetpack Compose having Spotify Android UI and functionality using Spotify SDK and web API. Link: https://github.com/sunny52525/JetSpotify Project: JetPic Express Description: A simple photo editing app that allows you to apply stunning filters and share it to the world. This app was built using the latest Jetpack Compose UI for Modern Native Android UI development. Link: https://github.com/la-colinares/JetPicExpress Project: CoolWheatherApp Description: A cool modern weather application build with (JetpackCompose UI , coroutine,retrofit , MVVM Architecture , LiveData) Link: https://github.com/markoeltiger/CoolWheatherApp ``` -------------------------------- ### Jetpack Compose General Concepts Source: https://foso.github.io/Jetpack-Compose-Playground/resources Explores fundamental concepts in Jetpack Compose, including codelabs, understanding Compose confusion, the compiler plugin, Compose for different platforms (Android, SwiftUI), lifecycle management, CompositionLocal, CompositionLocalProvider, basic 'Hello World' examples, modifiers, navigation, previewing composables, preview parameters, roadmap, project setup, state management, and UI testing. ```kotlin Codelabs Compose Confusion Compiler Plugin Compose for Android Developers Compose for SwiftUI Developers Compose Lifecycle CompositionLocal CompositionLocalProvider Hello World Compose Modifier Navigation Preview PreviewParameter Roadmap Project Setup State UI Testing ``` -------------------------------- ### Install MkDocs Plugins Source: https://foso.github.io/Jetpack-Compose-Playground/contributing Installs the required plugins for MkDocs to manage and enhance the documentation site. These plugins include minify, git revision date localization, and macros. ```bash pip3 install mkdocs-minify-plugin pip3 install mkdocs-git-revision-date-localized-plugin pip3 install mkdocs-minify-plugin pip3 install mkdocs-macros-plugin ``` -------------------------------- ### Jetpack Compose State Example Source: https://foso.github.io/Jetpack-Compose-Playground/general/state Provides a practical example of using state in Jetpack Compose to create a simple counter UI. It shows how state changes trigger recomposition. ```kotlin import androidx.compose.foundation.layout.Column import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.* @Composable fun CounterScreen() { var count by remember { mutableStateOf(0) } Column { Text(text = "Count: $count") Button(onClick = { count++ }) } } ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/material/modalbottomsheetlayout This section offers practical cookbook examples for common Jetpack Compose development scenarios. It provides solutions for tasks like handling text field changes, loading images, integrating Android Views, and managing context. ```kotlin Handle changes to a text field How to use Compose in a ViewGroup How to load an Image How to use an Android View in Compose How to get Android Context How to detect dark mode How to create a custom shape ``` -------------------------------- ### Implementing PreviewParameterProvider Source: https://foso.github.io/Jetpack-Compose-Playground/general/preview/previewparameter An example implementation of the PreviewParameterProvider interface to supply a sequence of User objects for previews. ```kotlin class SampleUserProvider : PreviewParameterProvider { override val values = sequenceOf(User("Jens", 31), User("Jim", 44)) } ``` -------------------------------- ### Jetpack Compose Cookbook Examples Source: https://foso.github.io/Jetpack-Compose-Playground/resources Provides practical examples and solutions for common tasks in Jetpack Compose development. This includes handling text field changes, integrating Compose within ViewGroups, loading images, using Android Views in Compose, accessing the Android Context, detecting dark mode, and creating custom shapes. ```kotlin Handle changes to a text field How to use Compose in a ViewGroup How to load an Image How to use an Android View in Compose How to get Android Context How to detect dark mode How to create a custom shape ``` -------------------------------- ### Jetpack Compose Switch Example Source: https://foso.github.io/Jetpack-Compose-Playground/material/checkbox Provides an example of using the Switch composable in Jetpack Compose. This demonstrates how to control the switch's state and react to changes. ```kotlin import androidx.compose.foundation.layout.Row import androidx.compose.material.Switch import androidx.compose.material.Text import androidx.compose.runtime.* @Composable fun SwitchExample() { var isChecked by remember { mutableStateOf(false) } Row { Switch( checked = isChecked, onCheckedChange = { isChecked = it } ) Text("Is switched: $isChecked") } } ``` -------------------------------- ### Jetpack Compose - Cookbook: Overview Source: https://foso.github.io/Jetpack-Compose-Playground/general/getting_started An introductory section to the Jetpack Compose Cookbook, providing a high-level overview of the recipes and examples available for common UI development tasks. -------------------------------- ### Jetpack Compose Material: AlertDialog Source: https://foso.github.io/Jetpack-Compose-Playground/foundation/layout/boxwithconstraints Provides an example of how to implement an AlertDialog, a dialog that interrupts the user to get a response for a critical action. ```kotlin var showDialog by remember { mutableStateOf(false) } Button(onClick = { showDialog = true }) { Text("Show Dialog") } if (showDialog) { AlertDialog( onDismissRequest = { showDialog = false }, title = { Text("Title") }, text = { Text("Description") }, confirmButton = { Button(onClick = { showDialog = false }) { Text("Confirm") } }, dismissButton = { Button(onClick = { showDialog = false }) { Text("Cancel") } } ) } ``` -------------------------------- ### Snackbar Example Source: https://foso.github.io/Jetpack-Compose-Playground/foundation/basictextfield Demonstrates how to display a Snackbar, which provides brief feedback about an operation. ```kotlin @Composable fun MySnackbarHost() { val snackbarHostState = remember { SnackbarHostState() } Scaffold( snackbarHost = { SnackbarHost(snackbarHostState) }, floatingActionButton = { FloatingActionButton(onClick = { scope.launch { snackbarHostState.showSnackbar("Action performed!") } }) } ) { // Content of your screen } } ``` -------------------------------- ### Hello World Compose Source: https://foso.github.io/Jetpack-Compose-Playground/foundation/lazycolumn A basic 'Hello World' example demonstrating the fundamental structure of a Jetpack Compose UI. ```kotlin import androidx.compose.material.Text import androidx.compose.runtime.Composable @Composable fun HelloWorld() { Text(text = "Hello, World!") } ``` -------------------------------- ### AlertDialog in Jetpack Compose Source: https://foso.github.io/Jetpack-Compose-Playground/material/radiobutton Demonstrates how to create and display an AlertDialog, a modal dialog that interrupts user interaction to get a response. Includes basic setup for title, text, and buttons. ```kotlin import androidx.compose.material.AlertDialog import androidx.compose.material.Text import androidx.compose.material.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @Composable fun MyAlertDialogExample() { val openDialog = remember { mutableStateOf(true) } if (openDialog.value) { AlertDialog( onDismissRequest = { openDialog.value = false }, title = { Text(text = "Dialog Title") }, text = { Text(text = "This is the dialog content.") }, confirmButton = { TextButton(onClick = { openDialog.value = false }) { Text("Confirm") } }, dismissButton = { TextButton(onClick = { openDialog.value = false }) { Text("Dismiss") } } ) } } ``` -------------------------------- ### Getting Android Context in Compose Source: https://foso.github.io/Jetpack-Compose-Playground/viewinterop/androidview Explains how to access the Android Context within a Jetpack Compose composable. The Context is often required for various Android operations, such as accessing resources or starting activities. ```kotlin import android.content.Context import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext @Composable fun GetContextExample() { val context: Context = LocalContext.current // Now you can use the context for various operations // For example: context.getString(R.string.app_name) } ``` -------------------------------- ### Jetpack Compose Card Example Source: https://foso.github.io/Jetpack-Compose-Playground/material/card Demonstrates the basic usage of the Card composable in Jetpack Compose. This includes setting up a Card with content and basic styling. ```kotlin import androidx.compose.foundation.layout.padding import androidx.compose.material3.Card import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @Composable fun SimpleCard() { Card(modifier = Modifier.padding(16.dp)) { Text(text = "This is a simple Card", modifier = Modifier.padding(16.dp)) } } ``` -------------------------------- ### Jetpack Compose Hello World Source: https://foso.github.io/Jetpack-Compose-Playground/material/floatingactionbutton A basic "Hello World" example demonstrating the structure of a minimal Jetpack Compose application. ```kotlin import androidx.compose.material.Text import androidx.compose.runtime.Composable @Composable fun HelloWorld() { Text("Hello, Jetpack Compose!") } ``` -------------------------------- ### AlertDialog Example Source: https://foso.github.io/Jetpack-Compose-Playground/foundation/basictextfield Demonstrates how to implement an AlertDialog, which presents a dialog window with an optional title, message, and actions. ```kotlin @Composable fun MyAlertDialog() { var showDialog by remember { mutableStateOf(false) } Button(onClick = { showDialog = true }) { Text("Show Dialog") } if (showDialog) { AlertDialog( onDismissRequest = { showDialog = false }, title = { Text("Alert Title") }, text = { Text("This is an alert message.") }, confirmButton = { Button(onClick = { showDialog = false }) { Text("OK") } } ) } } ``` -------------------------------- ### Linking Composables with Constraints Source: https://foso.github.io/Jetpack-Compose-Playground/layout/constraintlayout Demonstrates how to establish layout constraints between Composables using the `linkTo` method within the `constrainAs` scope. This example shows linking the top and start edges of one Box to the bottom and end edges of another, respectively. ```kotlin .constrainAs(blueBox){ top.linkTo(redBox.bottom) start.linkTo(redBox.end) } ``` -------------------------------- ### Jetpack Compose Tutorial Source: https://foso.github.io/Jetpack-Compose-Playground/resources A tutorial for learning Jetpack Compose, likely covering basic concepts and implementation. ```english A tutorial for learning Jetpack Compose, likely covering basic concepts and implementation. ``` -------------------------------- ### Jetpack Compose Modifiers Source: https://foso.github.io/Jetpack-Compose-Playground/general/modifier A detailed guide to Jetpack Compose modifiers, explaining how to combine them for various UI effects and behaviors. It covers layout, drawing, and gesture modifiers, including specific examples like width, height, padding, background, and click handling. ```kotlin // Combine modifiers: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#combine-modifiers // LayoutModifier: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#layoutmodifier // Modifier.width(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierwidth) // Modifier.height(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierheight) // Modifier.size(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifiersize) // Modifier.fillMaxHeight(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierfillmaxheight) // Modifier.fillMaxWidth(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierfillmaxwidth) // Modifier.fillMaxSize(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierfillmaxsize) // Modifier.padding(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierpadding) // DrawModifier: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#drawmodifier // Modifier.background(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierbackground) // Modifier.clip(): https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierclip) // GestureModifier: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#gesturemodifier // Modifier.clickable: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierclickable) // Modifier.scrollable: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierscrollable) // Modifier.draggable: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierdraggable) // Modifier.swipeable: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#modifierswipeable) // Multitouch: Panning, zooming, rotating: https://foso.github.io/Jetpack-Compose-Playground/general/modifier/#multitouch-panning-zooming-rotating) ```