Skip to content

Latest commit

 

History

History
108 lines (86 loc) · 3.66 KB

README.md

File metadata and controls

108 lines (86 loc) · 3.66 KB

Compose Expandable ✨

Use this template License Language

A fully customizable and state hoisted expandable view developed by Jetpack Compose

Prerequisites 👑

  • build.gradle.kts
     dependencies {
          /** .... **/
     	implementation("ir.mohammadesteki:compose-expandable:0.1.1")
     }

How to use 👣

You can see example provided in app module

  • Simple example

    val expanded = remember { mutableStateOf(false) }
    
    Expandable(
        expanded = expanded.value,
        onExpandChanged = {
            expanded.value = it
        },
        title = { /** Your Title **/ },
        content = { /** Your Content **/ },
    )
  • Advanced example

    val expanded = remember { mutableStateOf(false) }
        val expandAnimation: State<Float> = animateFloatAsState(
            targetValue = if (expanded.value) 540f else 0f,
            animationSpec = tween(1000, easing = FastOutSlowInEasing)
        )
    
        Expandable(
            modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
            expanded = expanded.value,
            onExpandChanged = {
                expanded.value = it
            },
            title = { /** Your Title **/ },
            content = { /** Your Content **/ },
            contentAnimation = spring(
                dampingRatio = Spring.DampingRatioHighBouncy,
                stiffness = Spring.StiffnessLow
            ),
            leading = {
                Icon(
                    modifier = Modifier,
                    imageVector = Icons.Filled.Call,
                    contentDescription = null
                )
                Spacer(modifier = Modifier.width(20.dp))
            },
            expandAnimation = expandAnimation,
            expand = { modifier ->
                IconButton(
                    modifier = modifier,
                    onClick = {
                        expanded.value = !expanded.value
                    }
                ) {
                    Icon(
                        imageVector = Icons.Filled.KeyboardArrowDown,
                        contentDescription = null
                    )
                }
            }
        )

Features 🎨

  • Fully customizable with compose functions
  • State hoisted
  • Default animations for expand icon and content expansion
  • 100% Kotlin.
  • Sample module (Android app).
  • 100% Gradle Kotlin DSL setup.
  • Dependency versions managed via buildSrc.

Demo ✨

Gradle Setup 🐘

This project is using Gradle Kotlin DSL as well as the Plugin DSL to setup the build.

Dependencies are centralized inside the Dependencies.kt file in the buildSrc folder. This provides convenient auto-completion when writing your gradle files.

Contributing 🤝

Feel free to open a issue or submit a pull request for any bugs/improvements.

LinkedIn