Kotlin EpoxyModel with Paris Implementation
naj147 opened this issue · comments
I'm using Paris so I can Style my Epoxy Components programatically.
But I'm getting the following Kotlin error :
Methods annotated with @Style must be static and can't be private or protect
Dependencies
implementation 'com.airbnb.android:epoxy:3.4.0'
kapt 'com.airbnb.android:epoxy-processor:3.4.0'
implementation 'com.airbnb.android:paris:1.2.1'
kapt 'com.airbnb.android:paris-processor:1.2.1'
Code for View
@Styleable
@ModelView
class TypographyView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : TextView(context, attrs, defStyleAttr) {
@TextProp
fun setTitle(charSequence: CharSequence) {
text = charSequence
}
companion object {
@Style
fun defaultStyle(builder: TypographyViewStyleApplier.StyleBuilder) {
builder.textColorHint(Color.BLACK)
.textSize(16)
.fontFamilyRes(R.font.torsans_regular)
}
}
}
Code for Controller
class TypographyListingController() : TypedEpoxyController<List<TypographyDataModel>>() {
override fun buildModels(data: List<TypographyDataModel>?) {
data?.forEach {
TypographyViewModel_()
.id(it.text)
.styleBuilder { builder ->
builder.add(R.style.H1)
}
.title(it.text)
.addTo(this)
}
}
I tried using the generated Kotlin extension functions as someone advised me in Epoxy Repo
@Style
val defaultStyle = typographyViewStyle {
textColorHint(Color.BLACK)
textSize(16)
fontFamilyRes(R.font.torisans_regular)
}
but same error
Fields annotated with @Style must be static.
@naj147 you definitely need to use the Kotlin extension function for this, and are you still placing it inside the companion object
? For example: https://github.com/airbnb/paris/blob/master/paris/src/testDebug/java/com/airbnb/paris/views/kotlin/WithStylePropertyView.kt
@ngsilverman Yes its inside the Companion object exactly like the code provided in the first comment I've just replaced the function with the Kotlin extension one, still the same error as my previous comment.
@naj147 and you're sure that's where the error is coming from? Not some other class? Could I see the full stacktrace? And could you put up a small project that reproduces this error?
@ngsilverman I actually managed to fix it while I was creating a small project to demonstrate the problem 😄
The problem was I haven't mentioned all the default value for the style I was passing with Paris (I have font, Color,size and letterSpacing in the style file) And I think not cleaning & rebuilding, and changing things for the sake of debug might have also played a part in not conveying the right error.
Thank you so much 🙏
@naj147 glad you were able to fix it!