Epoxy, Kotlin: Using @ModelView generates nothing with no errors

448 Views Asked by At

I'm successfully able to have epoxy generate code from this EpoxyModelClass

@EpoxyModelClass(layout = R.layout.card_sample)
abstract class PhotoModel : EpoxyModelWithHolder<PhotoModel.Holder>() {
    @EpoxyAttribute
    var title: String? = null

    override fun bind(holder: PhotoModel.Holder) {
        holder.header.text = title
    }

    class Holder : EpoxyHolder() {
        override fun bindView(itemView: View) {
            header = itemView.findViewById(R.id.header_label)
        }

        lateinit var header: TextView
    }
}

but unfortunately not from a ModelView. It builds without errors, but no generated epoxy classes around this:

@ModelView
abstract class HeaderView : LinearLayout {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    )
    private var titleProp: CharSequence? = null
    @TextProp(defaultRes = R.string.app_name)
    fun setTitle(title: CharSequence) {
        titleProp = title
    }
}

Tried many variations on this to get it right but there are no helpful errors in build logs.

1

There are 1 best solutions below

0
On

Using open on both functions and class instead of abstract seems to work.

@ModelView(defaultLayout = R.layout.card_sample)
open class HeaderView : RelativeLayout {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    )

    private var titleProp: CharSequence? = null
    @TextProp(defaultRes = R.string.app_name)
    open fun setTitle(string: CharSequence?) {
        titleProp = string
    }
}