-
Notifications
You must be signed in to change notification settings - Fork 570
4、kotlin如何配置
mqzhangw edited this page Jan 4, 2018
·
1 revision
kotlin组件的配置与Java组件基本是一致的,主要区别在apt的命令上有点区别
在组件的build.gradle中添加依赖
apply plugin: 'com.dd.comgradle'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
kapt 'com.luojilab.ddcomponent:router-anno-compiler:1.0.0'
同时添加
kapt {
arguments {
arg("moduleName", project.getName())
}
}
在组件的声明周期类ApplicationLike中,添加注册和反注册代码
class KotlinApplike : IApplicationLike {
val uiRouter = UIRouter.getInstance()
override fun onCreate() {
uiRouter.registerUI("kotlin")
}
override fun onStop() {
uiRouter.unregisterUI("kotlin")
}
}
首先在跳转的目的Activity上添加RouteNode注解
@RouteNode(path = "/shareMagazine", desc = "分享杂志页面")
class ShareMessageActivity : Activity() {
如果需要传入参数,在具体的参数定义上增加Autowired注解:
@Autowired(name = "bookName")
@JvmField
var magazineName: String? = null
@Autowired
@JvmField
var author: Author? = null
注意此处的参数需要设置为非private,否则编译会直接报错
其他配置与Java组件一致,参见UI跳转