Yasha - Kotlin时代的RecyclerView应该这么写

[复制链接]
来自: Season.zlc 分类: Android精品源码 上传时间: 2020-1-15 10:13:49
Tag:

项目介绍:

[i=s] 本帖最后由 Season.zlc 于 2020-1-15 10:22 编辑 [/i]

Yasha (夜叉)

Github地址

物品介绍:

夜叉是一个基于散华打造的快速渲染RecyclerView的DSL工具.

功能介绍:

  • 无需Adapter

  • 无需ViewHolder

  • 支持初始化数据加载

  • 支持数据分页加载

  • 支持MultiViewType

  • 支持Header和Footer

  • 支持DiffUtil

  • 支持Loading State

  • 支持CleanUp, 释放资源避免内存泄漏

Prepare

  1. 添加jitpack到build.gradle


allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. 添加依赖


dependencies {
    // 替换 xyz 为具体的版本号, 例如 1.0.0
    implementation 'com.github.ssseasonnn:Yasha:xyz'
}

First Blood

  • 渲染Linear列表:

    
      recycler_view.linear(dataSource) {
          renderItem<NormalItem> {
              res(R.layout.view_holder_normal)
              onBind {
                  tv_normal_content.text = data.toString()
              }
          }
          renderItem<HeaderItem> {
              res(R.layout.view_holder_header)
              onBind {
                  tv_header_content.text = data.toString()
              }
          }
          renderItem<FooterItem> {
              res(R.layout.view_holder_footer)
              onBind {
                  tv_footer_content.text = data.toString()
              }
          }
      }

Double Kill

  • 渲染Grid列表:

    
      recycler_view.grid(dataSource) {
          //设置SpanCount
          spanCount(3)
      
          renderItem<HeaderItem> {
              res(R.layout.view_holder_header)
              onBind {
                  tv_header_content.text = data.toString()
              }
              
              //设置Item的SpanSize
              gridSpanSize(3)
          }
        
          renderItem<NormalItem> {
              res(R.layout.view_holder_normal)
              onBind {
                  tv_normal_content.text = data.toString()
              }
          }
    
          renderItem<FooterItem> {
              res(R.layout.view_holder_footer)
              onBind {
                  tv_footer_content.text = data.toString()
              }
          }
      }

Triple Kill

  • 渲染Grid列表:

    
      recycler_view.stagger(dataSource) {
          //设置SpanCount
          spanCount(3)
        
          renderItem<HeaderItem> {
              res(R.layout.view_holder_header)
              onBind {
                  tv_header_content.text = data.toString()
              }
              
              //设置Item是否为full span
              staggerFullSpan(true)
          }
          renderItem<NormalItem> {
              res(R.layout.view_holder_normal)
              onBind {
                  tv_normal_content.text = data.toString()
              }
          }
          renderItem<FooterItem> {
              res(R.layout.view_holder_footer)
              onBind {
      }

License

Copyright 2019 Season.Zlc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

相关源码推荐:

我来说两句
所有评论(3)
幻影旅團 2020-4-17 02:39:16
正需要啊,感谢楼主无私分享!
回复
笃信,笃行 2020-5-21 16:57:21
强烈支持楼主ing……
回复
笃信,笃行 2020-5-25 10:08:04
强烈支持楼主ing……
回复
919 0 0
代码贡献英雄榜
用户名 下载数
联系我们
首页/微信公众账号投稿
帖子代码编辑/版权问题
QQ:435399051,1294855032
如何获得代码达人称号?
如何成为签约作者?
领先的中文移动开发者社区
18620764416
7*24全天服务
意见反馈:1294855032@qq.com

扫一扫关注我们

Powered by Discuz! X3.2© 2001-2019 Comsenz Inc.( 粤ICP备15117877号 )