Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

简单易用的SideBar 快速定位侧边栏A~Z 仿微信国家或地区代码选择 (jetpack compose)

License

Notifications You must be signed in to change notification settings

D10NGYANG/DLSideBar_Compose

Repository files navigation

DLSideBar


⚠️ 本项目已停止维护,相关组件已迁移至 D10NGYANG/DLJetpackComposeUtil,以IndexBar组件的形式呈现。


简单易用的SideBar 快速定位侧边栏A~Z 仿微信国家或地区代码选择 jetpack compose版本

普通Android XML布局版本在这里

截图


使用说明

1 添加仓库

allprojects {
    repositories {
        maven { url 'https://raw.githubusercontent.com/D10NGYANG/maven-repo/main/repository'}
    }
}

2 添加仓库

dependencies {
    implementation 'com.github.D10NGYANG:DLSideBar_Compose:1.2.5'

    // Compose
    def composeBom = platform('androidx.compose:compose-bom:2023.08.00')
    implementation composeBom
    androidTestImplementation composeBom
    // Material Design 2
    implementation 'androidx.compose.material:material'
    // Android Studio Preview support
    implementation 'androidx.compose.ui:ui-tooling-preview'
    debugImplementation 'androidx.compose.ui:ui-tooling'
}

3 在你的UI页面中使用

val scope = rememberCoroutineScope()
SideBar(
    onSelect = { value ->
        // 选中字符,如"A"
        val index = dataList.indexOfFirst { it.py[0].uppercase() == value }
        if (index >= 0) {
            scope.launch { listState.scrollToItem(index) }
        }
    }
) {
    // 列表
    LazyColumn(
        modifier = Modifier.fillMaxSize(),
        state = listState
    ) {
        itemsIndexed(dataList) { index, item ->
            // todo 单项UI
        }
    }
}

4 更多参数说明

@ExperimentalComposeUiApi
@Composable
fun SideBar(
    // 列表中显示的字符列表
    chars: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ#",
    // 选中字符后返回该字符
    onSelect: (String) -> Unit,
    // 触摸列表时,列表的颜色,不触摸列表时,颜色透明
    touchColor: Color = Color(0xFFEBEEF0),
    // 列表中字符的样式
    charText: @Composable (String) -> Unit = {
        DefaultSideBarCharText(text = it)
    },
    // 选中字符弹出的样式
    selectText: @Composable BoxScope.(String) -> Unit ={
        DefaultSideBarSelectText(text = it)
    },
    // 列表内容
    content: @Composable BoxScope.() -> Unit
)

5 混淆

-keep class com.d10ng.sidebar.** {*;}
-dontwarn com.d10ng.sidebar.**

About

简单易用的SideBar 快速定位侧边栏A~Z 仿微信国家或地区代码选择 (jetpack compose)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages