Closed plnice closed 4 years ago
There is no direct necessity for that.
You can extend KRecyclerItem
, since basically it duplicates the functionality of KBaseView
, but replaces constructor to the parent matcher.
So what you need to do, is to provide additional constructors to your class, that will accept the DSL.
OK, what should I pass to the super constructor invocation in such case?
class KMyView : KRecyclerItem<KMyView> {
val child: KTextView
// RecylerItem version
constructor(parent: Matcher<View>) : super(parent) {
child = KTextView(parent) { withId(R.id.child) }
}
// Regular usage version
constructor(function: ViewBuilder.() -> Unit) : super(function) { // Does not compile, super constructor needs Matcher<View>
child = KTextView {
isDescendantOfA(function)
withId(R.id.child)
}
}
}
super(Matchers.any()) {
Closing this issue due to no activity
In my project I have a collection of reusable custom views and I want to prepare a library of Kakao views for them. Each of the custom views can be used within any ViewGroup, or within RecyclerView. For now for each of the views I prepare two separate classes for that two use cases:
Is there a way to have one class only, instead of two?