-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcfc0b1
commit 4d00aed
Showing
11 changed files
with
167 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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就请自定义 |
Oops, something went wrong.