Skip to content

uxlabspk/compose_examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Jetpack Compose Examples

A comprehensive Android application demonstrating various Jetpack Compose concepts and UI patterns. This project serves as a learning resource and reference for developers getting started with or advancing their knowledge of Jetpack Compose.

Kotlin Compose API License

πŸ“± About

This project showcases practical examples of building modern Android UIs using Jetpack Compose, Google's modern toolkit for building native UI. Each screen demonstrates different Compose concepts, from basic layouts to advanced custom composables.

✨ Features

The application includes the following example screens:

1. Profile Screen 🎨

A complete user profile UI demonstrating:

  • Circular profile images with Material 3
  • Sectioned settings layout
  • List items with icons and navigation
  • Material Design theming
  • Column layouts with proper spacing

2. Row & Column Demo πŸ“

Demonstrates fundamental layout concepts:

  • Vertical arrangement with Column
  • Horizontal arrangement with Row
  • Main and Cross axis alignment
  • Space distribution (SpaceEvenly, SpaceBetween)
  • Nested layouts

3. Box Layout Demo πŸ“¦

Shows overlapping and stacking composables:

  • Z-index layering
  • Alignment properties (TopStart, TopEnd, CenterEnd, etc.)
  • Circular shapes and borders
  • Background colors and custom shapes
  • Cut corner shapes

4. Flow Layout Demo 🌊

Demonstrates responsive wrapping layouts:

  • FlowRow for automatic line wrapping
  • Tag-based UI patterns
  • Spacing between items
  • Maximum items per row configuration
  • Responsive chip layouts

5. String Styling Demo ✍️

Advanced text styling techniques:

  • SpanStyle: Inline text styling with different fonts, sizes, and colors
  • ParagraphStyle: Line height, text indentation, and alignment
  • Brush/Gradient Text: Multi-color gradient effects on text
  • Annotated strings for complex text formatting

6. Slot API Pattern 🎯

Demonstrates composable reusability with slots:

  • Higher-order composables
  • Content slots for flexible UI
  • State hoisting
  • Interactive checkboxes
  • Toggle between different UI states (Linear/Circular progress, Image/Text)

7. CompositionLocal Demo 🌍

Shows how to share data implicitly across composables:

  • Creating custom CompositionLocal
  • Providing values with CompositionLocalProvider
  • Theme-aware color switching
  • Dark/Light mode handling

8. Custom Layout - Modifier πŸ”§

Creating custom layout modifiers:

  • Custom layout modifier implementation
  • Manual positioning of composables
  • Understanding the measure-and-place API
  • Custom offset implementation

9. Custom Layout - Composable πŸ—οΈ

Building custom layout composables from scratch:

  • Cascade/Staircase layout pattern
  • Using the Layout composable
  • Measuring and placing children
  • Custom spacing logic

10. ConstraintLayout Demo πŸ”—

Advanced constraint-based layouts:

  • Basic constraints with constrainAs
  • Guidelines for proportional positioning
  • Barriers for dynamic content alignment
  • Chains with different styles (Spread, SpaceBetween, Packed)
  • Complex layouts with minimal nesting

11. Intrinsic Size Demo πŸ“

Understanding intrinsic measurements:

  • IntrinsicSize.Max for matching widest child
  • IntrinsicSize.Min for matching narrowest child
  • Solving layout problems without custom layouts
  • Automatic width/height synchronization
  • Comparing layouts with and without intrinsic sizing

πŸ› οΈ Tech Stack

  • Language: Kotlin 2.0.21
  • UI Framework: Jetpack Compose
  • Architecture: Single Activity, Composable-based navigation
  • Build System: Gradle (Kotlin DSL)
  • Minimum SDK: 26 (Android 8.0)
  • Target SDK: 36

πŸš€ Getting Started

Clone the Repository

git clone https://github.com/yourusername/compose_examples.git
cd compose_examples

Open in Android Studio

  1. Launch Android Studio
  2. Select "Open an Existing Project"
  3. Navigate to the cloned repository
  4. Wait for Gradle sync to complete

Run the App

  1. Connect an Android device or start an emulator (API 26+)
  2. Click the "Run" button (▢️) in Android Studio
  3. Select your target device
  4. The app will build and install automatically

πŸ“‚ Project Structure

compose_examples/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”‚   β”œβ”€β”€ java/com/codehuntspk/compose_examples/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ MainActivity.kt              # Main entry point
β”‚   β”‚   β”‚   β”‚   └── ui/
β”‚   β”‚   β”‚   β”‚       β”œβ”€β”€ screens/
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ ProfileScreen.kt     # Profile UI example
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ RowColumnDemo.kt     # Row/Column layouts
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ BoxDemo.kt           # Box layout examples
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ FlowLayoutDemo.kt    # FlowRow examples
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ StringDemo.kt        # Text styling
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ SlotAPI.kt           # Slot pattern demo
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ LocalDemoScreen.kt   # CompositionLocal
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ CustomLayout.kt      # Custom modifiers
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ CustomLayoutComposable.kt # Custom layouts
β”‚   β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ ConstraintLayoutDemo.kt  # ConstraintLayout examples
β”‚   β”‚   β”‚   β”‚       β”‚   └── IntrinsiveMeasureDemo.kt # Intrinsic size examples
β”‚   β”‚   β”‚   β”‚       └── theme/
β”‚   β”‚   β”‚   β”‚           β”œβ”€β”€ Color.kt
β”‚   β”‚   β”‚   β”‚           β”œβ”€β”€ Theme.kt
β”‚   β”‚   β”‚   β”‚           └── Type.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ res/                             # Resources (drawables, strings, etc.)
β”‚   β”‚   β”‚   └── AndroidManifest.xml
β”‚   β”‚   β”œβ”€β”€ test/                                # Unit tests
β”‚   β”‚   └── androidTest/                         # Instrumented tests
β”‚   └── build.gradle.kts                         # App-level build config
β”œβ”€β”€ gradle/
β”‚   └── libs.versions.toml                       # Version catalog
β”œβ”€β”€ build.gradle.kts                             # Project-level build config
└── settings.gradle.kts                          # Project settings

πŸŽ“ Learning Path

If you're new to Jetpack Compose, we recommend exploring the examples in this order:

  1. RowColumnDemo - Learn basic layouts and alignment
  2. BoxDemo - Understand overlapping and stacking
  3. FlowLayoutDemo - Explore responsive wrapping layouts
  4. StringDemo - Master text styling techniques
  5. ProfileScreen - See a real-world UI example
  6. SlotAPI - Learn about composable reusability
  7. LocalDemoScreen - Understand implicit data sharing
  8. CustomLayout - Create custom layout modifiers
  9. CustomLayoutComposable - Build custom layout composables
  10. ConstraintLayoutDemo - Advanced constraint-based layouts
  11. IntrinsiveMeasureDemo - Master intrinsic size measurements

🎨 Material 3 Theming

The app uses Material 3 design principles with:

  • Dynamic color scheme support
  • Typography scaling
  • Consistent spacing and elevation
  • Material You components

πŸ“ Best Practices Demonstrated

  • βœ… State hoisting for better testability
  • βœ… Reusable composables with slot API
  • βœ… Proper separation of concerns
  • βœ… Preview annotations for rapid development
  • βœ… Material 3 design system
  • βœ… Modifier chains for styling
  • βœ… Custom layouts when needed
  • βœ… CompositionLocal for implicit data passing

🀝 Contributing

Contributions are welcome! If you'd like to add more examples or improve existing ones:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/NewExample)
  3. Commit your changes (git commit -m 'Add new example')
  4. Push to the branch (git push origin feature/NewExample)
  5. Open a Pull Request

Contribution Guidelines

  • Follow Kotlin coding conventions
  • Add preview functions for all composables
  • Document complex logic with comments
  • Ensure code passes lint checks
  • Add your example to this README

πŸ”— Resources

πŸ‘¨β€πŸ’» Author

Muhammad Naveed

🌟 Acknowledgments

  • Google Compose team for the amazing framework
  • Android developer community for inspiration
  • Material Design team for design guidelines

πŸ—ΊοΈ Roadmap

Future examples to be added:

  • Navigation Compose integration
  • Animations and transitions
  • Lazy lists (LazyColumn, LazyRow, LazyGrid)
  • ViewModel integration
  • Side effects (LaunchedEffect, DisposableEffect)
  • Gesture handling
  • Canvas and custom drawing
  • Paging 3 with Compose
  • Material 3 components showcase

⭐ If you find this project helpful, please consider giving it a star!

Happy Composing! πŸš€

Releases

No releases published

Packages

No packages published

Languages