Hello - probably a beginner's question. I was look...
# compose
v
Hello - probably a beginner's question. I was looking at `VisualTransformation`to add some simple transformation to a `OutlineTextField`(like adding currency formatting, or percentage % display). But as soon as I add `
Copy code
class PercentageVisualTransformation : VisualTransformation {
    override fun filter(text: AnnotatedString): TransformedText {
        TODO("Not yet implemented")
    }
}
The code no longer compiles with an error message:
Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option
- I'm not comfortable changing compiler options for what, I thought, should be a simple thing to do. Any suggestions?
j
I’ve used VisualTransformation within my project without having to set that compiler option so definitely seems odd
Don’t see anything in yours that stands out as fundamentally different from mine. Maybe try restarting/invalidating caches in AS?
I’m on Compose 1.2.1, though. So if you’re on a new version it’s possible something changed in VisualTransformation
v
Pretty sure I'm on 1.2.1 as well - whatever the default for a new Android Studio project is! Though I have added Material3 rc1 to the project. I'll try the cache thing in the morning.
a
Material 3 1.0.0-rc01 transitively depends on Compose UI 1.3.0-rc01.
v
I tried changing my compose version 1.3.0-rc01 but I still get the same error message. Not important just now, I'll stay away from
VisualTransformation
. I'm still learning, just keen to learn from the most modern approaches.
j
Yeah, even looking at the head of the source code for VisualTransformation I don’t see a default impl for the filter method or any other interface defaults.
Maybe double check that you’re getting the
androidx.compose.ui.text.input.VisualTransformation
and not something from some other package?
v
Oh dear, I'm getting the same error (
Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option
) from a completely different Android library now - extending from
ViewModelProvider.Factory
. Must have something wrong with my project setup in gradle.
I have moved to the "bleeding edge" - Kotlin 1.7.20, Compose compiler 1.3.2, compose 1.3.0-rc01 etc, and the project now compiles and runs. Good thing this is just a training/hobby project for me!
j
Glad you sorted it out. Definitely an odd error, but the issue being related to the compose compiler and/or kotlin version kind of makes sense