Skip to content

Commit

Permalink
docs: 更新开发文档
Browse files Browse the repository at this point in the history
  • Loading branch information
liangjingkanji committed Aug 13, 2023
1 parent dcfc0b1 commit 9183eae
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 395 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- [x] 快速配置点击重试
- [x] 监听缺省页回调
- [x] 自定义动画/布局
- [x] [骨骼动画](https://liangjingkanji.github.io/StateLayout/skeleton/)
- [x] [骨骼动画](https://liangjingkanji.github.io/StateLayout/skeleton.html)
- [x] 传递标签
- [x] 异步线程使用
- [x] 自定义缺省页切换处理
Expand Down
85 changes: 24 additions & 61 deletions docs/callback.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,55 @@
我们可以通过监听缺省页显示的生命周期来获取其对应的视图对象(View), 在其回调中可以拿到缺省页的任何控件(类似于Activity的`onCreate`)
生命周期回调中可以获取状态参数/视图对象

| 函数 | 描述 |
|-|-|
| onEmpty | showEmpty 时回调 |
| onError | showError 时回调 |
| onContent | showContent 时回调 |
| onLoading | showLoading 时回调 |
| onRefresh | showLoading 时回调, 一般在其中执行加载网络或异步任务的逻辑, 而不是加载视图|
| onRefresh | showLoading 时回调, 一般在其中执行加载网络异步任务|
| stateChangedHandler | 完全接管缺省页状态变更时处理 |

每个StateLayout实例都可以设置单独的回调监听, 同时StateConfig可以设置全局的回调监听

> 你对缺省页有任何自定义的需求, 点击事件? 开始播放动画? 通过参数展示不同的错误页或者空页面? 都可以在这里判断! <br>
> `show*()`函数可以通过其参数Any传递任何对象到`on*()`生命周期回调中
可以在此对缺省页自定义的需求, 点击事件或播放动画, 或根据标签展示不同的错误页

## 监听缺省页显示

=== "示例"
```kotlin
state.onRefresh {
// 每次showLoading都会执行该回调
}
state.showLoading()
```

=== "链式调用"
```kotlin

state.onRefresh {
// 每次showLoading都会执行该回调
}.showLoading()
```
```kotlin
state.onRefresh {
// 每次showLoading都会执行该回调
}.showLoading()
```

监听缺省页显示

=== "示例"
```kotlin
state.onEmpty {
findViewById<TextView>(R.id.msg).text = "空布局信息"
}

state.onError {

}

state.onLoading {

}

state.onRefresh {

}

state.onContent {

}
```

=== "链式调用"
```kotlin
state.onEmpty {

}.onError {
```kotlin
state.onEmpty {

}.onLoading {
}.onError {

}.onRefresh {
}.onLoading {

}
```
}.onRefresh {

`onRefresh``onLoading`触发的条件一样, 但是他们的函数参数接收者不一样, 他们所代表的的作用也不同
}
```

- onRefresh 中常见处理异步任务(例如网络请求)
- onLoading 中常见处理的是加载视图/动画
`onRefresh``onLoading`触发条件相同, 但是参数不同, 他们所代表的的作用也不同

## 自定义缺省页切换处理
1. `onRefresh` 中常见处理网络请求异步任务
2. `onLoading` 中常见处理的是加载视图/动画

创建`StateChangedHandler`来取代默认的缺省页切换逻辑, 可以自定义缺省页显示/隐藏动画, 并且可以自定义布局参数(宽高)
## 完全自定义

StateChangedHandler默认是removeView/addView, 如果你想改成visibility就可以实现接口自定义处理
实现`StateChangedHandler`可以实现最大程度自定义

可以全部配置或者单例配置
甚至来取代默认的缺省页切换逻辑, 可以自定义缺省页显示/隐藏动画, 并且可以自定义布局参数(宽高)

```kotlin
// 单例
state.stateChangedHandler = StateChangedHandler()

// 全局
StateConfig.stateChangedHandler = StateChangedHandler()
```
```

StateChangedHandler默认是removeView/addView, 如果你想改成visibility就请自定义
Loading

0 comments on commit 9183eae

Please sign in to comment.