Skip to content

Commit

Permalink
docs: 多状态实现
Browse files Browse the repository at this point in the history
  • Loading branch information
liangjingkanji committed Jul 3, 2022
1 parent c249966 commit 997daf3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/multi-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
默认包含四种状态: 错误/空/加载中/内容


如果我们需要新增一种状态(例如错误分为网络/接口错误), 我们可以根据`tag`来在[视图回调](callback.md)中进行处理(比如替换图片)


### 示例

传递标签
```kotlin
val e = NetNetworkingException()
showError(e) // 这里直接传递异常对象过去, 实际你可以传递任何对象
```


配置全局视图回调

```kotlin
StateConfig.apply {
onError {
if (it is NetNetworkingException) {
// 这里是为无网络异常展示不同图片, 当然你可以做其他处理, 比如addView或者setText
findViewById<View>(R.id.iv_error).setImageResource(R.drawable.ic_networking_error)
}
}
}
```

或者你直接自定义StateChangedHandler也可以根据`tag`来addView, 但是我认为`onError`等方法足以, 也更简单


> 缺省页不同的状态就是添加不同的视图对象, 或显示不同图片/文字, 通过tag我们可以实现无限多种状态(类似网络拦截器)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ nav:
- 全局配置: global.md
- 传递标签: transfer.md
- 点击重试: retry.md
- 多状态: multi-state.md
- 动画/布局: animation.md
- 骨骼动画: skeleton.md
- 自动显示: extension.md
Expand Down

0 comments on commit 997daf3

Please sign in to comment.