回复
     weiV DSL 已经设计完成,Widget、Element、View 架构已经搭建好
xbkong
 发布于 2022-7-7 17:10
 浏览
 0收藏
昨天早上突发奇想就开干,现在展示一下最新的开发成果。
DSL 样式如下:
class MainActivity : WeiVActivity() {
    private var switch = false
    private var text = "weiV"
    override fun build(): Widget {
        return WeiV {
            Flex(orientation = LinearLayout.HORIZONTAL) {
                Text(text = text, textSize = 14f)
                Text(text = text)
                Flex(
                    key = Key(),
                    orientation = LinearLayout.VERTICAL
                ) {
                    if (switch) {
                        Text(text = text)
                    } else {
                        Text(text = text)
                    }
                    repeat(10) {
                        Button(text = text + it)
                    }
                    for (i in 1..5) {
                        Text(text = text + i)
                    }
                }
            }
        }
    }
}
可以生成并打印出 Widget 树了,是不是跟 Compose 很像呢?
weiV 是可扩展的。它会内置所有常用的 Widget,这些 Widget 都是对系统 View 的包装。但对于第三方库,就需要写扩展,写起来也极其简单,比如给 Button 的扩展如下:
class weiVButton(
    override var key: Key? = null,
    var text: String? = null,
    var textSize: Float? = null,
    var textColor: Int? = null
) :
    LeafRenderWidget<Button>(key) {
    override fun createView(context: Context): Button = Button(context)
    override fun doParameter(view: Button, first: Boolean): Button {
        if (view.text != text) {
            view.text = text
        }
        if (view.currentTextColor != textColor) {
            view.setTextColor(textColor!!)
        }
        if (view.textSize != textSize) {
            view.textSize = textSize!!
        }
        return view
    }
}
fun WeiV.Button(
    key: Key? = null,
    text: String? = null,
    textSize: Float? = null,
    textColor: Int? = null
) {
    addLeafRenderWidget(
        weiVButton(
            key = key,
            text = text,
            textSize = textSize,
            textColor = textColor
        )
    )
}
预计很快 weiV 就可以真正跑起来了。但还任重而道远。首先需要移植 Flutter ConstraintLayout,其次大概率会重写一个 weiV 版本的 RecyclerView,以支持像 Flutter 那样简单的列表用法,不需要写 Adapter。
从长远看,weiV 可能成为继 React Native 和 Flutter 之后的第三个(类)高性能跨平台开发框架。它的前端采用 kotlin DSL,后端使用平台原生 View 渲染。并达到或超越原生 View 系统的性能。
点击查看原文进入 GitHub。
全部写完可能得一个月,欢迎订阅我的公众号关注后续进展。
文章转自公众号:FlutterFirst
标签 
  已于2022-7-7 17:10:59修改
 
        赞
        
 
        收藏 
      
 回复
  相关推荐
 



















