RecursiveAccordion
Screen_recording_20251010_010405.webm
Android 向けの再帰的なアコーディオン UI コンポーネントライブラリです。Jetpack Compose
を使用して、ツリー構造のデータを階層的に表示できます。
特徴
- 🎨 柔軟なカスタマイズ - コンテンツ、アクション、スタイルを自由にカスタマイズ可能
- 🎬 スムーズなアニメーション - 展開・折りたたみ時の滑らかなアニメーション
- 📱 Compose Multiplatform 対応 - Android だけでなく iOS にも対応
- 🔄 無限の階層 - 任意の深さのツリー構造に対応
- 🎯 シンプルな API - 直感的で使いやすい API 設計
インストール
build.gradle.kts に以下を追加してください:
dependencies {
implementation("com.legstart:recursive-accordion-android:1.0.2")
}
基本的な使い方
1. データモデルの作成
val item = RecursiveItem(
id = "1",
value = "親アイテム",
children = listOf(
RecursiveItem(id = "1-1", value = "子アイテム 1"),
RecursiveItem(id = "1-2", value = "子アイテム 2"),
RecursiveItem(
id = "1-3",
value = "子アイテム 3",
children = listOf(
RecursiveItem(id = "1-3-1", value = "孫アイテム 1"),
RecursiveItem(id = "1-3-2", value = ),
)
)
)
)
2. RecursiveAccordion の使用
@Composable
fun MyScreen() {
val expandedIds = remember { mutableStateSetOf<String>() }
RecursiveAccordion(
item = item,
expandedIds = expandedIds,
onToggle = { toggledItem ->
(toggledItem.id expandedIds) {
expandedIds.remove(toggledItem.id)
} {
expandedIds.add(toggledItem.id)
}
},
action = { current, isExpanded, onToggle ->
IconButton(onClick = onToggle) {
Icon(
imageVector = Icons.Default.ArrowDropDown,
contentDescription = ,
modifier = Modifier.graphicsLayer {
rotationZ = (isExpanded)
}
)
}
}
) { current ->
Text(text = current.value)
}
}
カスタマイズ
アニメーションのカスタマイズ
RecursiveAccordion(
item = item,
expandedIds = expandedIds,
onToggle = { },
animationDurationMillis = 500,
) { }
レベルガイドのカスタマイズ
RecursiveAccordion(
item = item,
expandedIds = expandedIds,
onToggle = { },
showLevelGuide = true,
levelGuideWidth = 2.dp,
levelGuideColor = Color.Gray,
levelLeadingPadding = 16.dp,
) { }
LazyColumn での使用
API リファレンス
RecursiveItem
data class RecursiveItem<T>(
val id: String,
val value: T,
val children: List<RecursiveItem<T>> = emptyList()
)
RecursiveAccordion パラメータ
サンプルコード
完全なサンプルコードは composeApp/src/commonMain/kotlin/com/legstart/recursiveaccordion/sample
を参照してください。
ライセンス
Copyright 2025 Takuma Yoshimura
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.