Yaksa让你抛弃Adapter和ViewHolder写RecyclerView

《Yaksa让你抛弃Adapter和ViewHolder写RecyclerView》

Yaksa

一个轻量级的RecyclerView工具,让你像Javascript一样渲染Item.

众所周知,熟练使用RecyclerView展示列表数据已经是每个Android开发者必备的能力,然而,RecyclerView仍然有它的不足,
那就是过于繁琐,相信每个开发者都有过这样的经历,我们为了展示一个只有单一类型的简单的列表,需要创建一个Adapter,
需要创建一个ViewHolder,而对于具有多个类型的稍微复杂的列表,我们不但需要创建Adapter,同时还要创建多个ViewHolder..

我们一次又一次不断的重复着这样无聊的工作,显得那么的麻木不仁

然而,生活不止眼前的苟且,还有诗和远方!

让我们一起和噩梦一样的Adapter和ViewHolder说声再见,一起来拥抱Yaksa吧!

Yaksa(夜叉), 提高16点敏捷 15%攻击速度 10%移动速度

Talk is cheap, show me the code

渲染一个Linear列表:

example_rv.linear {
    renderHeaders(mutableListOf("Header1", "Header2")) {
        HeaderItem(it)
    }

    renderFootersByDsl(mutableListOf("Footer1", "Footer2")) { text ->
        xml(R.layout.header_item)
        render { view ->
            view.header_item_tv.text = text
            view.setOnClickListener { }
        }
    }

    renderItemsByDsl(dataSource.list) { item ->
        xml(R.layout.list_item)
        render { view ->
            view.list_item_tv.text = item.title
            view.setOnClickListener { toast("Item Clicked") }
        }
    }
}

就是这样,没有Adapter,也没有ViewHolder,你只需要专心的渲染Item就好了!

效果图:

《Yaksa让你抛弃Adapter和ViewHolder写RecyclerView》

渲染一个Grid列表:

example_rv.grid {
    spanCount(SPAN_COUNT)

    renderHeaders(mutableListOf("Header1", "Header2")) {
        HeaderItem(it)
    }

    renderFootersByDsl(mutableListOf("Footer1", "Footer2")) { text ->
        xml(R.layout.header_item)
        render { view ->
            view.header_item_tv.text = text
            view.setOnClickListener { }
        }
    }

    renderItemsByDsl(dataSource.list) { item ->
        xml(R.layout.list_item)
        render { view ->
            view.list_item_tv.text = item.title
            view.setOnClickListener { toast("Item Clicked") }
        }
    }
}

效果图:

《Yaksa让你抛弃Adapter和ViewHolder写RecyclerView》

瀑布流? 没问题:

example_rv.stagger {
    spanCount(3)

    renderHeaders(mutableListOf("Header1", "Header2")) {
        HeaderItem(it)
    }

    renderFootersByDsl(mutableListOf("Footer1", "Footer2")) { text ->
        xml(R.layout.header_item)
        render { view ->
            view.header_item_tv.text = text
            view.setOnClickListener { }
        }
    }

    renderItems(dataSource.list) { item ->
        ListItem(item.title, HEIGHTS[Random().nextInt(HEIGHTS.size)].px)
    }
}

效果图:

《Yaksa让你抛弃Adapter和ViewHolder写RecyclerView》

其余的Header,Footer,多种type类型更是不在话下,而且重要的是,这些都不需要你写任何的ViewHolder和Adapter

现在就开始装备夜叉吧,开启你的超神之路!

动图:

《Yaksa让你抛弃Adapter和ViewHolder写RecyclerView》

Github地址:https://github.com/ssseasonnn/Yaksa

License

Copyright 2018 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.
```![yaksa.png](https://upload-images.jianshu.io/upload_images/1008453-bcdfe27bf44ebd16.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

最后

在现在这个金三银四的面试季,我自己在网上也搜集了很多资料做成了文档和架构视频资料免费分享给大家【包括高级UI、性能优化、架构师课程、NDK、Kotlin、混合式开发(ReactNative+Weex)、Flutter等架构技术资料】,希望能帮助到您面试前的复习且找到一个好的工作,也节省大家在网上搜索资料的时间来学习。

资料获取方式:加入Android架构交流QQ群聊:513088520 ,进群即领取资料!!!

点击链接加入群聊【Android移动架构总群】:加入群聊

《Yaksa让你抛弃Adapter和ViewHolder写RecyclerView》 资料大全

    原文作者:Android架构
    原文地址: https://www.jianshu.com/p/de65f19a1ba0
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞