Skip to content

Commit 196574b

Browse files
committed
update sample
1 parent 14124b4 commit 196574b

File tree

6 files changed

+390
-197
lines changed

6 files changed

+390
-197
lines changed

README.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,91 @@
1-
# ComposeWaveLoading
1+
# ComposeWaveLoading
2+
3+
4+
5+
# 1. 使用方式
6+
7+
在 root 的 `build.gradle` 中引入 `jitpack`
8+
```groovy
9+
allprojects {
10+
repositories {
11+
...
12+
maven { url 'https://jitpack.io' }
13+
}
14+
}
15+
```
16+
在 module 的 `build.gradle` 中引入 `ComposeWaveLoading` 的最新版本
17+
```groovy
18+
dependencies {
19+
implementation 'com.github.vitaviva:ComposeWaveLoading:$latest_version'
20+
}
21+
```
22+
23+
# 2. API 设计思想
24+
25+
26+
```kotlin
27+
28+
Box {
29+
WaveLoading (
30+
progress = 0.5f // 0f ~ 1f
31+
) {
32+
Image(
33+
painter = painterResource(id = R.drawable.logo_tiktok),
34+
contentDescription = ""
35+
)
36+
}
37+
}
38+
39+
```
40+
传统的 UI 开发方式中,设计这样一个波浪控件,一般会使用自定义 View 并将 Image 等作为属性传入。 而在 Compose 中,我们让 `WaveLoading``Image` 以组合的方式使用,这样的 API 更加灵活,`WaveLoding` 的内部可以是 `Image`,也可以是 `Text` 亦或是其他 `Composable`。波浪动画不拘泥于某一特定 Composable, 任何 Composable 都可以以波浪动画的形式展现, **通过 Composable 的组合使用,我们扩大了 “能力” 的覆盖范围。**
41+
42+
43+
# 3. API 参数介绍
44+
45+
```kotlin
46+
@Composable
47+
fun WaveLoading(
48+
modifier: Modifier = Modifier,
49+
foreDrawType: DrawType = DrawType.DrawImage,
50+
backDrawType: DrawType = rememberDrawColor(color = Color.LightGray),
51+
@FloatRange(from = 0.0, to = 1.0) progress: Float = 0f,
52+
@FloatRange(from = 0.0, to = 1.0) amplitude: Float = defaultAmlitude,
53+
@FloatRange(from = 0.0, to = 1.0) velocity: Float = defaultVelocity,
54+
content: @Composable BoxScope.() -> Unit
55+
) { ... }
56+
```
57+
58+
|参数| 说明|
59+
|--|--|
60+
|progress| 加载进度 |
61+
|foreDrawType| 波浪图的绘制类型: `DrawColor` 或者 `DrawImage` |
62+
|backDrawType| 波浪图的背景绘制|
63+
|amplitude| 波浪的振幅, 0f ~ 1f 表示振幅在整个绘制区域的占比|
64+
|velocity|波浪移动的速度|
65+
|content| 子Composalble|
66+
67+
```kotlin
68+
sealed interface DrawType {
69+
object None : DrawType
70+
object DrawImage : DrawType
71+
data class DrawColor(val color: Color) : DrawType
72+
}
73+
```
74+
如上,DrawType 有三种类型:
75+
76+
- None: 不进行绘制
77+
- DrawColor:使用单一颜色绘制
78+
- DrawImage:按照原样绘制
79+
80+
以下面这个 `Image` 为例, 体会一下不同 DrawType 的组合效果
81+
82+
|index|backDrawType|foreDrawType | 说明 |
83+
|--|--|--| --|
84+
|1|DrawImage| DrawImage| 背景灰度,前景原图|
85+
|2|DrawColor(Color.LightGray)|DrawImage|背景单色,前景原图 |
86+
|3|DrawColor(Color.LightGray)|DrawColor(Color.Cyan)| 背景单色,前景单色|
87+
|4|None|DrawColor(Color.Cyan)| 无背景,前景单色|
88+
89+
<img src="/screenshot/screenshot_1.gif" width="480">
90+
91+
<img src="/screenshot/screenshot_2.gif" width="480">

0 commit comments

Comments
 (0)